21 lines
1.5 KiB
TypeScript
21 lines
1.5 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { trackIpsecMutation } from "./ipsec-operation.js"
|
|
import { MikrotikError, type MikrotikClient } from "./mikrotik.js"
|
|
const rejected = new MikrotikError(403, "/ip/ipsec/peer", "forbidden")
|
|
for (const steps of [0, 1]) for (const failure of [rejected, new Error("socket closed"), new MikrotikError(500, "/ip/ipsec/peer", "server error")]) {
|
|
let attempts = 0
|
|
const client = { patch: async () => { attempts++; if (attempts > steps) throw failure }, put: async () => {}, delete: async () => {}, post: async () => {} } as unknown as MikrotikClient
|
|
const tracked = trackIpsecMutation(client)
|
|
if (steps) await tracked.client.patch("/own", {})
|
|
await assert.rejects(tracked.client.patch("/own", {}))
|
|
assert.equal(tracked.receipt()?.state, failure === rejected ? steps ? "partial" : undefined : "unknown")
|
|
assert.equal(tracked.receipt()?.confirmedWrites ?? 0, steps)
|
|
}
|
|
const client = { patch: async () => {}, put: async () => {}, delete: async () => {}, post: async () => {}, removeCertificate: async function () { await this.delete("/certificate/own") } } as unknown as MikrotikClient
|
|
const tracked = trackIpsecMutation(client)
|
|
await tracked.client.removeCertificate("own")
|
|
assert.equal(tracked.receipt()?.confirmedWrites, 1)
|
|
tracked.complete(); assert.deepEqual(tracked.receipt(), { state: "applied", confirmedWrites: 1, needsReview: true })
|
|
console.log("IPsec progress: native 4xx, partial writes, transport/5xx uncertainty, nested methods and completed operation")
|
|
|