22 lines
1.1 KiB
TypeScript
22 lines
1.1 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { isAlreadyCaptured } from "../../utils/captureResponse.ts";
|
|
|
|
test("recognises the CMS's answer to a repeated capture", () => {
|
|
assert.equal(isAlreadyCaptured({ success: true, alreadyCaptured: true }), true);
|
|
});
|
|
|
|
test("takes the paid order of a first capture for no repeated capture", () => {
|
|
const order = { uuid: "11111111-2222-4333-8444-555555555555", total: 22.85, paymentAuthorised: true, email: "erika@example.org" };
|
|
|
|
assert.equal(isAlreadyCaptured(order), false);
|
|
assert.equal(isAlreadyCaptured({ ...order, alreadyCaptured: false }), false);
|
|
});
|
|
|
|
test("takes nothing but true for both fields as a repeated capture", () => {
|
|
assert.equal(isAlreadyCaptured({ alreadyCaptured: true }), false);
|
|
assert.equal(isAlreadyCaptured({ success: true, alreadyCaptured: "true" }), false);
|
|
assert.equal(isAlreadyCaptured({ success: false, alreadyCaptured: true }), false);
|
|
for (const response of [undefined, null, "alreadyCaptured", 1, [true]]) assert.equal(isAlreadyCaptured(response), false);
|
|
});
|