Closer/functions/dist/notifications/idempotency.test.js

19 lines
1.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const idempotency_1 = require("./idempotency");
function markRef(create) {
return { path: 'couples/c1/notif_marks/m1', create };
}
describe('claimOnce', () => {
it('claims (true) when the marker did not exist', async () => {
expect(await (0, idempotency_1.claimOnce)(markRef(async () => undefined))).toBe(true);
});
it('does not claim (false) when the marker already exists (ALREADY_EXISTS = 6)', async () => {
expect(await (0, idempotency_1.claimOnce)(markRef(async () => Promise.reject({ code: 6 })))).toBe(false);
});
it('fails open (true) on any other create error so a ping is not silently dropped', async () => {
expect(await (0, idempotency_1.claimOnce)(markRef(async () => Promise.reject({ code: 14 })))).toBe(true);
expect(await (0, idempotency_1.claimOnce)(markRef(async () => Promise.reject(new Error('boom'))))).toBe(true);
});
});
//# sourceMappingURL=idempotency.test.js.map