@saasicat/persistence-testing 1.0.0-rc.15 → 1.0.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17,9 +17,84 @@ var OFFER = {
17
17
  effectiveGross: 58.31
18
18
  }
19
19
  };
20
- function contractFromOffer(offerId) {
20
+ function partiesWith(subscriberId, legalName) {
21
+ return {
22
+ subscriberId,
23
+ subscriber: {
24
+ customerNumber: "K-10001",
25
+ legalName,
26
+ vatId: "DE123456789",
27
+ taxNumber: null,
28
+ addressLine1: "Hauptstra\xDFe 1",
29
+ addressLine2: null,
30
+ postalCode: "10115",
31
+ city: "Berlin",
32
+ country: "DE"
33
+ },
34
+ issuer: {
35
+ legalName: "Example Software GmbH",
36
+ vatId: "DE987654321",
37
+ taxNumber: "12/345/67890",
38
+ addressLine1: "Werkstra\xDFe 5",
39
+ addressLine2: null,
40
+ postalCode: "80331",
41
+ city: "M\xFCnchen",
42
+ country: "DE"
43
+ }
44
+ };
45
+ }
46
+ function eventAt(gatewayAccount, eventId, about = {}) {
47
+ return {
48
+ gatewayAccount,
49
+ eventId,
50
+ provider: "stripe",
51
+ sessionId: `cs_${eventId}`,
52
+ kind: "payment-method-confirmed",
53
+ summary: { type: "card", last4: "4242" },
54
+ ...about
55
+ };
56
+ }
57
+ var CARD = {
58
+ type: "card",
59
+ brand: "visa",
60
+ last4: "4242",
61
+ expiryMonth: 12,
62
+ expiryYear: 2030,
63
+ country: null,
64
+ bankCode: null,
65
+ mandateReference: null,
66
+ customerRef: "cus_1",
67
+ paymentMethodRef: "pm_card"
68
+ };
69
+ function paymentMethodFor(subscriberId, paymentMethodRef, confirmedAt, gatewayAccount = "stripe-main") {
70
+ return {
71
+ ...CARD,
72
+ paymentMethodRef,
73
+ subscriberId,
74
+ gatewayAccount,
75
+ provider: "stripe",
76
+ confirmedAt: new Date(confirmedAt)
77
+ };
78
+ }
79
+ function subscriberFor(tenantId, legalName) {
80
+ return {
81
+ tenantId,
82
+ legalName,
83
+ vatId: null,
84
+ taxNumber: null,
85
+ addressLine1: null,
86
+ addressLine2: null,
87
+ postalCode: null,
88
+ city: null,
89
+ country: null,
90
+ invoiceEmail: null,
91
+ customerNumberPrefix: ""
92
+ };
93
+ }
94
+ function contractFromOffer(offerId, parties) {
21
95
  return {
22
96
  tenantId: `tenant-${offerId}`,
97
+ parties,
23
98
  effectiveFrom: /* @__PURE__ */ new Date("2026-01-01T00:00:00.000Z"),
24
99
  originalOfferId: offerId,
25
100
  priceSnapshot: {
@@ -151,8 +226,20 @@ var CONTRACT_GAPS = {
151
226
  present: ({ adapter }) => Boolean(adapter.mfa)
152
227
  },
153
228
  subscriptionContracts: {
154
- reason: "adapter provides no SubscriptionContractRepository",
155
- present: ({ adapter }) => Boolean(adapter.subscriptionContractRepository)
229
+ reason: "adapter provides no SubscriptionContractRepository, or no subscriber seed for it",
230
+ present: ({ adapter, seed }) => Boolean(adapter.subscriptionContractRepository && seed.createSubscriber)
231
+ },
232
+ subscribers: {
233
+ reason: "adapter provides no SubscriberRepository",
234
+ present: ({ adapter }) => Boolean(adapter.subscriberRepository)
235
+ },
236
+ paymentEventLog: {
237
+ reason: "adapter provides no PaymentEventLog",
238
+ present: ({ adapter }) => Boolean(adapter.paymentEventLog)
239
+ },
240
+ subscriberPaymentMethods: {
241
+ reason: "adapter provides no SubscriberPaymentMethodRepository, or no subscriber seed for it",
242
+ present: ({ adapter, seed }) => Boolean(adapter.subscriberPaymentMethodRepository && seed.createSubscriber)
156
243
  },
157
244
  checkoutOffers: {
158
245
  reason: "adapter provides no CheckoutOfferRepository",
@@ -1347,14 +1434,18 @@ function persistenceAdapterContract(options) {
1347
1434
  });
1348
1435
  test("a contract keeps what was agreed, and ending it does not rewrite it", async (t) => {
1349
1436
  const contracts = harness.adapter.subscriptionContractRepository;
1350
- if (!contracts) {
1437
+ const createSubscriber = harness.seed.createSubscriber;
1438
+ if (!contracts || !createSubscriber) {
1351
1439
  missing(t, "subscriptionContracts");
1352
1440
  return;
1353
1441
  }
1354
1442
  const tenantId = "tenant-contract-lifecycle";
1355
1443
  const signedAt = /* @__PURE__ */ new Date("2026-01-01T00:00:00.000Z");
1444
+ const { subscriberId } = await createSubscriber({ legalName: "Meier GmbH" });
1445
+ const parties = partiesWith(subscriberId, "Meier GmbH");
1356
1446
  const created = await contracts.create({
1357
1447
  tenantId,
1448
+ parties,
1358
1449
  effectiveFrom: signedAt,
1359
1450
  priceSnapshot: {
1360
1451
  currency: "EUR",
@@ -1415,6 +1506,10 @@ function persistenceAdapterContract(options) {
1415
1506
  });
1416
1507
  assert.equal(created.status, "active");
1417
1508
  assert.equal(created.tenantId, tenantId);
1509
+ assert.equal(created.subscriberId, subscriberId);
1510
+ assert.deepEqual(created.subscriber, parties.subscriber);
1511
+ assert.deepEqual(created.issuer, parties.issuer);
1512
+ assert.equal(created.partiesMigrated, false);
1418
1513
  assert.equal(created.lineItems.length, 2);
1419
1514
  assert.deepEqual(created.originalBundleVersionIds, ["bundle-version-1"]);
1420
1515
  assert.deepEqual(created.termsSnapshot, { noticePeriodDays: 30 });
@@ -1447,6 +1542,8 @@ function persistenceAdapterContract(options) {
1447
1542
  assert.equal(bundleLine.metadata, null);
1448
1543
  const readBack = await contracts.findById(created.id);
1449
1544
  assert.ok(readBack, "contract expected by id");
1545
+ assert.deepEqual(readBack.subscriber, parties.subscriber, "the copy is stored");
1546
+ assert.deepEqual(readBack.issuer, parties.issuer);
1450
1547
  assert.equal(
1451
1548
  readBack.lineItems.length,
1452
1549
  2,
@@ -1503,11 +1600,14 @@ function persistenceAdapterContract(options) {
1503
1600
  });
1504
1601
  test("a successor takes over without erasing the contract it replaces", async (t) => {
1505
1602
  const contracts = harness.adapter.subscriptionContractRepository;
1506
- if (!contracts) {
1603
+ const createSubscriber = harness.seed.createSubscriber;
1604
+ if (!contracts || !createSubscriber) {
1507
1605
  missing(t, "subscriptionContracts");
1508
1606
  return;
1509
1607
  }
1510
1608
  const tenantId = "tenant-contract-succession";
1609
+ const { subscriberId } = await createSubscriber({ legalName: "Nachfolger KG" });
1610
+ const parties = partiesWith(subscriberId, "Nachfolger KG");
1511
1611
  const handover = /* @__PURE__ */ new Date("2026-04-01T00:00:00.000Z");
1512
1612
  const lineAt = (priceNet, priceGross) => ({
1513
1613
  kind: "plan",
@@ -1539,6 +1639,7 @@ function persistenceAdapterContract(options) {
1539
1639
  });
1540
1640
  const first = await contracts.create({
1541
1641
  tenantId,
1642
+ parties,
1542
1643
  effectiveFrom: /* @__PURE__ */ new Date("2026-01-01T00:00:00.000Z"),
1543
1644
  priceSnapshot: priceAt(19.9, 23.68),
1544
1645
  lineItems: [lineAt(19.9, 23.68)]
@@ -1556,6 +1657,7 @@ function persistenceAdapterContract(options) {
1556
1657
  });
1557
1658
  const second = await contracts.create({
1558
1659
  tenantId,
1660
+ parties,
1559
1661
  effectiveFrom: handover,
1560
1662
  priceSnapshot: priceAt(24.9, 29.63),
1561
1663
  lineItems: [lineAt(24.9, 29.63)]
@@ -1605,13 +1707,17 @@ function persistenceAdapterContract(options) {
1605
1707
  });
1606
1708
  test("a line keeps the currency and the tax it was booked with", async (t) => {
1607
1709
  const contracts = harness.adapter.subscriptionContractRepository;
1608
- if (!contracts) {
1710
+ const createSubscriber = harness.seed.createSubscriber;
1711
+ if (!contracts || !createSubscriber) {
1609
1712
  missing(t, "subscriptionContracts");
1610
1713
  return;
1611
1714
  }
1612
1715
  const tenantId = "tenant-contract-money-facts";
1716
+ const { subscriberId } = await createSubscriber({ legalName: "Z\xFCrich AG" });
1717
+ const parties = { ...partiesWith(subscriberId, "Z\xFCrich AG"), issuer: null };
1613
1718
  const created = await contracts.create({
1614
1719
  tenantId,
1720
+ parties,
1615
1721
  effectiveFrom: /* @__PURE__ */ new Date("2026-01-01T00:00:00.000Z"),
1616
1722
  priceSnapshot: {
1617
1723
  currency: "CHF",
@@ -1686,9 +1792,9 @@ function persistenceAdapterContract(options) {
1686
1792
  }
1687
1793
  });
1688
1794
  test("a contract written on a transaction is undone with it, and found by its offer", async (t) => {
1689
- const { adapter } = harness;
1795
+ const { adapter, seed } = harness;
1690
1796
  const contracts = adapter.subscriptionContractRepository;
1691
- if (!contracts) {
1797
+ if (!contracts || !seed.createSubscriber) {
1692
1798
  missing(t, "subscriptionContracts");
1693
1799
  return;
1694
1800
  }
@@ -1696,9 +1802,11 @@ function persistenceAdapterContract(options) {
1696
1802
  t.skip("adapter declares no transaction capability");
1697
1803
  return;
1698
1804
  }
1805
+ const { subscriberId } = await seed.createSubscriber({ legalName: "Angebot GmbH" });
1806
+ const parties = partiesWith(subscriberId, "Angebot GmbH");
1699
1807
  await assert.rejects(
1700
1808
  adapter.transactionRunner.run(async (tx) => {
1701
- await contracts.create(contractFromOffer("offer-rolled-back"), tx);
1809
+ await contracts.create(contractFromOffer("offer-rolled-back", parties), tx);
1702
1810
  throw new Error("the conclusion fails after the contract is written");
1703
1811
  })
1704
1812
  );
@@ -1708,13 +1816,817 @@ function persistenceAdapterContract(options) {
1708
1816
  "the contract outlived its transaction"
1709
1817
  );
1710
1818
  const kept = await adapter.transactionRunner.run(
1711
- (tx) => contracts.create(contractFromOffer("offer-kept"), tx)
1819
+ (tx) => contracts.create(contractFromOffer("offer-kept", parties), tx)
1712
1820
  );
1713
1821
  const found = await contracts.findByOriginalOfferId("offer-kept");
1714
1822
  assert.equal(found?.id, kept.id);
1715
1823
  assert.equal(found?.lineItems.length, 1, "with its lines");
1716
1824
  assert.equal(await contracts.findByOriginalOfferId("offer-nobody-concluded"), null);
1717
1825
  });
1826
+ test("a subscriber is created live for its tenant, and numbered by the database", async (t) => {
1827
+ const subscribers = harness.adapter.subscriberRepository;
1828
+ if (!subscribers) {
1829
+ missing(t, "subscribers");
1830
+ return;
1831
+ }
1832
+ const first = await subscribers.createForTenant({
1833
+ ...subscriberFor("tenant-subscriber-first", "Erste Autohaus GmbH"),
1834
+ vatId: "DE123456789",
1835
+ addressLine1: "Hauptstra\xDFe 1",
1836
+ postalCode: "10115",
1837
+ city: "Berlin",
1838
+ country: "DE",
1839
+ invoiceEmail: "rechnung@erste.example",
1840
+ customerNumberPrefix: "K-"
1841
+ });
1842
+ const second = await subscribers.createForTenant(
1843
+ subscriberFor("tenant-subscriber-second", "Zweiter Verein e.V.")
1844
+ );
1845
+ assert.ok(first && second, "both tenants had no subscriber");
1846
+ const numberOf = (customerNumber) => Number(customerNumber.replace("K-", ""));
1847
+ assert.ok(first.customerNumber.startsWith("K-"), first.customerNumber);
1848
+ assert.equal(numberOf(second.customerNumber), numberOf(first.customerNumber) + 1);
1849
+ assert.ok(numberOf(first.customerNumber) >= 10001, first.customerNumber);
1850
+ const found = await subscribers.findByTenantId("tenant-subscriber-first");
1851
+ assert.deepEqual(
1852
+ found && {
1853
+ id: found.id,
1854
+ customerNumber: found.customerNumber,
1855
+ tenantId: found.tenantId,
1856
+ legalName: found.legalName,
1857
+ vatId: found.vatId,
1858
+ taxNumber: found.taxNumber,
1859
+ addressLine1: found.addressLine1,
1860
+ addressLine2: found.addressLine2,
1861
+ postalCode: found.postalCode,
1862
+ city: found.city,
1863
+ country: found.country,
1864
+ invoiceEmail: found.invoiceEmail,
1865
+ migrated: found.migrated
1866
+ },
1867
+ {
1868
+ id: first.id,
1869
+ customerNumber: first.customerNumber,
1870
+ tenantId: "tenant-subscriber-first",
1871
+ legalName: "Erste Autohaus GmbH",
1872
+ vatId: "DE123456789",
1873
+ // The nullable half, so an adapter writing '' is caught too.
1874
+ taxNumber: null,
1875
+ addressLine1: "Hauptstra\xDFe 1",
1876
+ addressLine2: null,
1877
+ postalCode: "10115",
1878
+ city: "Berlin",
1879
+ country: "DE",
1880
+ invoiceEmail: "rechnung@erste.example",
1881
+ migrated: false
1882
+ }
1883
+ );
1884
+ assert.equal(
1885
+ (await subscribers.findById(second.id))?.tenantId,
1886
+ "tenant-subscriber-second"
1887
+ );
1888
+ assert.equal(await subscribers.findByTenantId("tenant-without-subscriber"), null);
1889
+ assert.equal(await subscribers.findById("subscriber-nobody-created"), null);
1890
+ });
1891
+ test("a tenant has one live subscriber: a second is refused, and the transaction survives it", async (t) => {
1892
+ const { adapter } = harness;
1893
+ const subscribers = adapter.subscriberRepository;
1894
+ if (!subscribers) {
1895
+ missing(t, "subscribers");
1896
+ return;
1897
+ }
1898
+ if (!adapter.capabilities.transactions) {
1899
+ t.skip("adapter declares no transaction capability");
1900
+ return;
1901
+ }
1902
+ const first = await subscribers.createForTenant(
1903
+ subscriberFor("tenant-one-subscriber", "Einzig GmbH")
1904
+ );
1905
+ const afterRefusal = await adapter.transactionRunner.run(async (tx) => {
1906
+ const refused = await subscribers.createForTenant(
1907
+ subscriberFor("tenant-one-subscriber", "Doppelt GmbH"),
1908
+ tx
1909
+ );
1910
+ assert.equal(refused, null, "a second live subscriber was created");
1911
+ return subscribers.createForTenant(
1912
+ subscriberFor("tenant-after-refusal", "Danach GmbH"),
1913
+ tx
1914
+ );
1915
+ });
1916
+ assert.equal(
1917
+ (await subscribers.findByTenantId("tenant-one-subscriber"))?.id,
1918
+ first?.id
1919
+ );
1920
+ assert.equal(
1921
+ (await subscribers.findByTenantId("tenant-after-refusal"))?.id,
1922
+ afterRefusal?.id,
1923
+ "the transaction did not survive the refusal"
1924
+ );
1925
+ });
1926
+ test("creating a subscriber for one tenant twice at once ends with one", async (t) => {
1927
+ const subscribers = harness.adapter.subscriberRepository;
1928
+ if (!subscribers) {
1929
+ missing(t, "subscribers");
1930
+ return;
1931
+ }
1932
+ const results = await Promise.all([
1933
+ subscribers.createForTenant(subscriberFor("tenant-at-once", "Gleichzeitig A")),
1934
+ subscribers.createForTenant(subscriberFor("tenant-at-once", "Gleichzeitig B"))
1935
+ ]);
1936
+ const created = results.filter((result) => result !== null);
1937
+ assert.equal(created.length, 1, `${created.length} subscribers were created`);
1938
+ assert.equal((await subscribers.findByTenantId("tenant-at-once"))?.id, created[0].id);
1939
+ });
1940
+ test("a subscriber written on a transaction is undone with it", async (t) => {
1941
+ const { adapter } = harness;
1942
+ const subscribers = adapter.subscriberRepository;
1943
+ if (!subscribers) {
1944
+ missing(t, "subscribers");
1945
+ return;
1946
+ }
1947
+ if (!adapter.capabilities.transactions) {
1948
+ t.skip("adapter declares no transaction capability");
1949
+ return;
1950
+ }
1951
+ await assert.rejects(
1952
+ adapter.transactionRunner.run(async (tx) => {
1953
+ await subscribers.createForTenant(
1954
+ subscriberFor("tenant-rolled-back", "Zur\xFCckgerollt GmbH"),
1955
+ tx
1956
+ );
1957
+ throw new Error("the tenant is not created after all");
1958
+ })
1959
+ );
1960
+ assert.equal(await subscribers.findByTenantId("tenant-rolled-back"), null);
1961
+ assert.ok(
1962
+ await subscribers.createForTenant(
1963
+ subscriberFor("tenant-rolled-back", "Zur\xFCckgerollt GmbH")
1964
+ )
1965
+ );
1966
+ });
1967
+ test("a contact change writes what it names and keeps the rest", async (t) => {
1968
+ const subscribers = harness.adapter.subscriberRepository;
1969
+ if (!subscribers) {
1970
+ missing(t, "subscribers");
1971
+ return;
1972
+ }
1973
+ const created = await subscribers.createForTenant({
1974
+ ...subscriberFor("tenant-contact", "Kontakt GmbH"),
1975
+ addressLine2: "Hinterhaus",
1976
+ city: "Hamburg"
1977
+ });
1978
+ assert.ok(created);
1979
+ const changed = await subscribers.updateContact(created.id, {
1980
+ city: "Bremen",
1981
+ addressLine2: null,
1982
+ invoiceEmail: "buchhaltung@kontakt.example"
1983
+ });
1984
+ assert.deepEqual(
1985
+ changed && [
1986
+ changed.city,
1987
+ changed.addressLine2,
1988
+ changed.invoiceEmail,
1989
+ changed.legalName,
1990
+ changed.tenantId
1991
+ ],
1992
+ ["Bremen", null, "buchhaltung@kontakt.example", "Kontakt GmbH", "tenant-contact"]
1993
+ );
1994
+ assert.equal((await subscribers.findById(created.id))?.city, "Bremen");
1995
+ assert.equal(
1996
+ await subscribers.updateContact("subscriber-nobody-created", { city: "Kiel" }),
1997
+ null
1998
+ );
1999
+ });
2000
+ test("a correction records the values it replaced, and nothing when nothing moves", async (t) => {
2001
+ const subscribers = harness.adapter.subscriberRepository;
2002
+ if (!subscribers) {
2003
+ missing(t, "subscribers");
2004
+ return;
2005
+ }
2006
+ const created = await subscribers.createForTenant(
2007
+ subscriberFor("tenant-correction", "Mueller GmbH")
2008
+ );
2009
+ assert.ok(created);
2010
+ const at = (day) => new Date(Date.UTC(2026, 8, day));
2011
+ const first = await subscribers.correctIdentity(created.id, {
2012
+ corrected: { legalName: "M\xFCller GmbH", vatId: "DE123456789", taxNumber: null },
2013
+ reason: "Umlaut lost when the registration was typed",
2014
+ correctedBy: "operator:anna",
2015
+ correctedAt: at(1)
2016
+ });
2017
+ assert.deepEqual(
2018
+ first?.correction && {
2019
+ previous: first.correction.previous,
2020
+ corrected: first.correction.corrected,
2021
+ reason: first.correction.reason,
2022
+ correctedBy: first.correction.correctedBy,
2023
+ correctedAt: first.correction.correctedAt.getTime()
2024
+ },
2025
+ {
2026
+ previous: { legalName: "Mueller GmbH", vatId: null },
2027
+ corrected: { legalName: "M\xFCller GmbH", vatId: "DE123456789" },
2028
+ reason: "Umlaut lost when the registration was typed",
2029
+ correctedBy: "operator:anna",
2030
+ correctedAt: at(1).getTime()
2031
+ }
2032
+ );
2033
+ assert.equal(first?.subscriber.legalName, "M\xFCller GmbH");
2034
+ assert.equal((await subscribers.findById(created.id))?.vatId, "DE123456789");
2035
+ const unchanged = await subscribers.correctIdentity(created.id, {
2036
+ corrected: { legalName: "M\xFCller GmbH" },
2037
+ reason: "Clicked twice",
2038
+ correctedBy: "operator:anna",
2039
+ correctedAt: at(2)
2040
+ });
2041
+ assert.equal(
2042
+ unchanged?.correction,
2043
+ null,
2044
+ "a correction that moved nothing was recorded"
2045
+ );
2046
+ await subscribers.correctIdentity(created.id, {
2047
+ corrected: { vatId: "DE999999999" },
2048
+ reason: "Wrong VAT id on the first correction",
2049
+ correctedBy: "operator:ben",
2050
+ correctedAt: at(3)
2051
+ });
2052
+ const listed = await subscribers.listCorrections(created.id);
2053
+ assert.deepEqual(
2054
+ listed.map((correction) => correction.reason),
2055
+ [
2056
+ "Wrong VAT id on the first correction",
2057
+ "Umlaut lost when the registration was typed"
2058
+ ],
2059
+ "corrections come back the latest first, and only the two that moved something"
2060
+ );
2061
+ assert.equal(
2062
+ await subscribers.correctIdentity("subscriber-nobody-created", {
2063
+ corrected: { legalName: "Niemand" },
2064
+ reason: "none",
2065
+ correctedBy: "operator:anna",
2066
+ correctedAt: at(4)
2067
+ }),
2068
+ null
2069
+ );
2070
+ });
2071
+ test("two corrections at once each record the value the other left behind", async (t) => {
2072
+ const { adapter } = harness;
2073
+ const subscribers = adapter.subscriberRepository;
2074
+ if (!subscribers) {
2075
+ missing(t, "subscribers");
2076
+ return;
2077
+ }
2078
+ if (!adapter.capabilities.transactions || !adapter.capabilities.pessimisticLocking) {
2079
+ t.skip("adapter declares no transactions or no row locks");
2080
+ return;
2081
+ }
2082
+ const created = await subscribers.createForTenant(
2083
+ subscriberFor("tenant-corrected-twice", "Original GmbH")
2084
+ );
2085
+ assert.ok(created);
2086
+ const correctTo = (legalName) => adapter.transactionRunner.run(async (tx) => {
2087
+ await subscribers.correctIdentity(
2088
+ created.id,
2089
+ {
2090
+ corrected: { legalName },
2091
+ reason: `to ${legalName}`,
2092
+ correctedBy: "operator:anna",
2093
+ correctedAt: /* @__PURE__ */ new Date()
2094
+ },
2095
+ tx
2096
+ );
2097
+ await sleep(LOCK_HOLD_MS);
2098
+ });
2099
+ await Promise.all([
2100
+ correctTo("Erste Korrektur GmbH"),
2101
+ correctTo("Zweite Korrektur GmbH")
2102
+ ]);
2103
+ const listed = await subscribers.listCorrections(created.id);
2104
+ assert.equal(listed.length, 2);
2105
+ const replaced = listed.map((correction) => correction.previous.legalName).sort();
2106
+ const written = listed.map((correction) => correction.corrected.legalName);
2107
+ const current = (await subscribers.findById(created.id))?.legalName;
2108
+ assert.ok(replaced.includes("Original GmbH"), JSON.stringify(listed));
2109
+ const secondReplaced = replaced.find((name) => name !== "Original GmbH");
2110
+ assert.ok(
2111
+ secondReplaced !== void 0 && written.includes(secondReplaced),
2112
+ `a correction recorded a value it did not replace: ${JSON.stringify(listed)}`
2113
+ );
2114
+ assert.ok(current !== void 0 && written.includes(current));
2115
+ assert.notEqual(secondReplaced, current);
2116
+ });
2117
+ test("a contract keeps its subscriber's copy after the subscriber is corrected", async (t) => {
2118
+ const { adapter } = harness;
2119
+ const subscribers = adapter.subscriberRepository;
2120
+ const contracts = adapter.subscriptionContractRepository;
2121
+ if (!subscribers) {
2122
+ missing(t, "subscribers");
2123
+ return;
2124
+ }
2125
+ if (!contracts || !harness.seed.createSubscriber) {
2126
+ missing(t, "subscriptionContracts");
2127
+ return;
2128
+ }
2129
+ const subscriber = await subscribers.createForTenant(
2130
+ subscriberFor("tenant-copy-kept", "Vorher GmbH")
2131
+ );
2132
+ assert.ok(subscriber);
2133
+ const parties = partiesWith(subscriber.id, "Vorher GmbH");
2134
+ const contract = await contracts.create({
2135
+ ...contractFromOffer("offer-copy-kept", parties),
2136
+ tenantId: "tenant-copy-kept"
2137
+ });
2138
+ await subscribers.correctIdentity(subscriber.id, {
2139
+ corrected: { legalName: "Nachher GmbH" },
2140
+ reason: "Change of name of the same company",
2141
+ correctedBy: "operator:anna",
2142
+ correctedAt: /* @__PURE__ */ new Date()
2143
+ });
2144
+ const readBack = await contracts.findById(contract.id);
2145
+ assert.equal(readBack?.subscriberId, subscriber.id);
2146
+ assert.equal(
2147
+ readBack?.subscriber.legalName,
2148
+ "Vorher GmbH",
2149
+ "the contract followed a correction of the live record"
2150
+ );
2151
+ });
2152
+ test("a gateway event is claimed once per account, and a duplicate leaves the transaction usable", async (t) => {
2153
+ const { adapter } = harness;
2154
+ const log = adapter.paymentEventLog;
2155
+ if (!log) {
2156
+ missing(t, "paymentEventLog");
2157
+ return;
2158
+ }
2159
+ const claims = await adapter.transactionRunner.run(async (tx) => [
2160
+ await log.claim(eventAt("stripe-main", "evt_1"), tx),
2161
+ await log.claim(eventAt("stripe-main", "evt_1"), tx),
2162
+ // The same identifier from another account is another event.
2163
+ await log.claim(eventAt("stripe-old", "evt_1"), tx),
2164
+ // A duplicate that raised would have aborted the transaction here.
2165
+ await log.claim(eventAt("stripe-main", "evt_2"), tx)
2166
+ ]);
2167
+ assert.deepEqual(claims, [true, false, true, true]);
2168
+ const later = await adapter.transactionRunner.run(
2169
+ (tx) => log.claim(eventAt("stripe-main", "evt_1"), tx)
2170
+ );
2171
+ assert.equal(later, false, "a committed claim was claimed again");
2172
+ });
2173
+ test("one gateway session is confirmed once, however many events report it", async (t) => {
2174
+ const { adapter } = harness;
2175
+ const log = adapter.paymentEventLog;
2176
+ if (!log) {
2177
+ missing(t, "paymentEventLog");
2178
+ return;
2179
+ }
2180
+ const session = "cs_reported_twice";
2181
+ const claims = await adapter.transactionRunner.run(async (tx) => [
2182
+ await log.claim(
2183
+ eventAt("stripe-main", "evt_form_done", { sessionId: session }),
2184
+ tx
2185
+ ),
2186
+ // The same session, reported again under another identifier:
2187
+ // recording it would set the session's payment method up twice.
2188
+ await log.claim(
2189
+ eventAt("stripe-main", "evt_method_on", { sessionId: session }),
2190
+ tx
2191
+ ),
2192
+ // Another account's session of that name is another session.
2193
+ await log.claim(eventAt("stripe-old", "evt_elsewhere", { sessionId: session }), tx),
2194
+ // A kind that says nothing about the session being confirmed.
2195
+ await log.claim(
2196
+ eventAt("stripe-main", "evt_gave_up", {
2197
+ sessionId: session,
2198
+ kind: "payment-method-setup-failed"
2199
+ }),
2200
+ tx
2201
+ ),
2202
+ // Events about no session at all do not collide with each other.
2203
+ await log.claim(
2204
+ eventAt("stripe-main", "evt_other_1", { sessionId: null, kind: "unhandled" }),
2205
+ tx
2206
+ ),
2207
+ await log.claim(
2208
+ eventAt("stripe-main", "evt_other_2", { sessionId: null, kind: "unhandled" }),
2209
+ tx
2210
+ )
2211
+ ]);
2212
+ assert.deepEqual(claims, [true, false, true, true, true, true]);
2213
+ const later = await adapter.transactionRunner.run(
2214
+ (tx) => log.claim(eventAt("stripe-main", "evt_late", { sessionId: session }), tx)
2215
+ );
2216
+ assert.equal(later, false, "a session already confirmed was confirmed again");
2217
+ });
2218
+ test("a claim rolled back with its transaction is free for the retry", async (t) => {
2219
+ const { adapter } = harness;
2220
+ const log = adapter.paymentEventLog;
2221
+ if (!log) {
2222
+ missing(t, "paymentEventLog");
2223
+ return;
2224
+ }
2225
+ await assert.rejects(
2226
+ adapter.transactionRunner.run(async (tx) => {
2227
+ assert.equal(await log.claim(eventAt("stripe-main", "evt_retry"), tx), true);
2228
+ throw new Error("recording what the event changes failed");
2229
+ }),
2230
+ /recording what the event changes failed/
2231
+ );
2232
+ const retry = await adapter.transactionRunner.run(
2233
+ (tx) => log.claim(eventAt("stripe-main", "evt_retry"), tx)
2234
+ );
2235
+ assert.equal(retry, true, "the retry was discarded as a duplicate");
2236
+ });
2237
+ test("a delivery that meets a claim still open waits for it, and answers by its outcome", async (t) => {
2238
+ const { adapter } = harness;
2239
+ const log = adapter.paymentEventLog;
2240
+ if (!log) {
2241
+ missing(t, "paymentEventLog");
2242
+ return;
2243
+ }
2244
+ if (!adapter.capabilities.pessimisticLocking) {
2245
+ t.skip(
2246
+ "adapter declares no pessimistic locking: an open claim cannot be waited on"
2247
+ );
2248
+ return;
2249
+ }
2250
+ const [committed, afterCommit] = await Promise.all([
2251
+ adapter.transactionRunner.run(async (tx) => {
2252
+ const claimed = await log.claim(eventAt("stripe-main", "evt_race"), tx);
2253
+ await sleep(LOCK_HOLD_MS);
2254
+ return claimed;
2255
+ }),
2256
+ sleep(LOCK_HOLD_MS / 3).then(
2257
+ () => adapter.transactionRunner.run(
2258
+ (tx) => log.claim(eventAt("stripe-main", "evt_race"), tx)
2259
+ )
2260
+ )
2261
+ ]);
2262
+ assert.deepEqual([committed, afterCommit], [true, false]);
2263
+ const [rolledBack, afterRollback] = await Promise.allSettled([
2264
+ adapter.transactionRunner.run(async (tx) => {
2265
+ await log.claim(eventAt("stripe-main", "evt_race_back"), tx);
2266
+ await sleep(LOCK_HOLD_MS);
2267
+ throw new Error("the first delivery failed");
2268
+ }),
2269
+ sleep(LOCK_HOLD_MS / 3).then(
2270
+ () => adapter.transactionRunner.run(
2271
+ (tx) => log.claim(eventAt("stripe-main", "evt_race_back"), tx)
2272
+ )
2273
+ )
2274
+ ]);
2275
+ assert.equal(rolledBack.status, "rejected");
2276
+ assert.deepEqual(afterRollback, { status: "fulfilled", value: true });
2277
+ });
2278
+ test("an event that changed nothing gives its session back, and stays claimed itself", async (t) => {
2279
+ const { adapter } = harness;
2280
+ const log = adapter.paymentEventLog;
2281
+ if (!log) {
2282
+ missing(t, "paymentEventLog");
2283
+ return;
2284
+ }
2285
+ const session = "cs_nothing_to_do";
2286
+ const released = await adapter.transactionRunner.run(async (tx) => {
2287
+ await log.claim(eventAt("stripe-main", "evt_missed", { sessionId: session }), tx);
2288
+ await log.releaseSession("stripe-main", "evt_missed", tx);
2289
+ return [
2290
+ // The next event about that session is handled …
2291
+ await log.claim(
2292
+ eventAt("stripe-main", "evt_correct", { sessionId: session }),
2293
+ tx
2294
+ ),
2295
+ // … while the event that released it stays claimed.
2296
+ await log.claim(eventAt("stripe-main", "evt_missed", { sessionId: null }), tx)
2297
+ ];
2298
+ });
2299
+ assert.deepEqual(released, [true, false]);
2300
+ const again = await adapter.transactionRunner.run(
2301
+ (tx) => log.claim(eventAt("stripe-main", "evt_after_correct", { sessionId: session }), tx)
2302
+ );
2303
+ assert.equal(again, false, "the session was confirmed and is not free again");
2304
+ });
2305
+ test("two events confirming one session at once end with one claim", async (t) => {
2306
+ const { adapter } = harness;
2307
+ const log = adapter.paymentEventLog;
2308
+ if (!log) {
2309
+ missing(t, "paymentEventLog");
2310
+ return;
2311
+ }
2312
+ if (!adapter.capabilities.pessimisticLocking) {
2313
+ t.skip(
2314
+ "adapter declares no pessimistic locking: an open claim cannot be waited on"
2315
+ );
2316
+ return;
2317
+ }
2318
+ const session = "cs_at_once";
2319
+ const [first, second] = await Promise.all([
2320
+ adapter.transactionRunner.run(async (tx) => {
2321
+ const claimed = await log.claim(
2322
+ eventAt("stripe-main", "evt_at_once_a", { sessionId: session }),
2323
+ tx
2324
+ );
2325
+ await sleep(LOCK_HOLD_MS);
2326
+ return claimed;
2327
+ }),
2328
+ sleep(LOCK_HOLD_MS / 3).then(
2329
+ () => adapter.transactionRunner.run(
2330
+ (tx) => log.claim(
2331
+ eventAt("stripe-main", "evt_at_once_b", { sessionId: session }),
2332
+ tx
2333
+ )
2334
+ )
2335
+ )
2336
+ ]);
2337
+ assert.deepEqual([first, second], [true, false]);
2338
+ });
2339
+ test("a confirmed payment method becomes the subscriber's, with its references and masked details", async (t) => {
2340
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2341
+ const createSubscriber = harness.seed.createSubscriber;
2342
+ if (!methods || !createSubscriber) {
2343
+ missing(t, "subscriberPaymentMethods");
2344
+ return;
2345
+ }
2346
+ const { subscriberId } = await createSubscriber({ legalName: "Karte GmbH" });
2347
+ const debit = {
2348
+ ...paymentMethodFor(subscriberId, "pm_sepa", "2026-09-01T10:00:00.000Z"),
2349
+ type: "sepa_debit",
2350
+ brand: null,
2351
+ last4: "3000",
2352
+ expiryMonth: null,
2353
+ expiryYear: null,
2354
+ country: "DE",
2355
+ bankCode: "37040044",
2356
+ mandateReference: "MANDATE-1"
2357
+ };
2358
+ const result = await methods.recordConfirmed(debit);
2359
+ assert.equal(result.outcome, "activated");
2360
+ const { id, createdAt, ...stored } = result.method;
2361
+ assert.ok(id);
2362
+ assert.ok(createdAt instanceof Date);
2363
+ assert.deepEqual(stored, { ...debit, status: "ACTIVE", replacedAt: null });
2364
+ assert.deepEqual(await methods.findActive(subscriberId), result.method);
2365
+ assert.deepEqual(
2366
+ await methods.findByReference("stripe-main", "pm_sepa"),
2367
+ result.method
2368
+ );
2369
+ assert.equal(await methods.findByReference("stripe-old", "pm_sepa"), null);
2370
+ const other = await createSubscriber({ legalName: "Second Customer GmbH" });
2371
+ assert.equal(await methods.findActive(other.subscriberId), null);
2372
+ });
2373
+ test("a newer payment method takes over, and the one it replaced stays as history", async (t) => {
2374
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2375
+ const createSubscriber = harness.seed.createSubscriber;
2376
+ if (!methods || !createSubscriber) {
2377
+ missing(t, "subscriberPaymentMethods");
2378
+ return;
2379
+ }
2380
+ const { subscriberId } = await createSubscriber({ legalName: "Wechsel GmbH" });
2381
+ await methods.recordConfirmed(
2382
+ paymentMethodFor(subscriberId, "pm_first", "2026-09-01T10:00:00.000Z")
2383
+ );
2384
+ const second = await methods.recordConfirmed(
2385
+ paymentMethodFor(subscriberId, "pm_second", "2026-09-02T10:00:00.000Z")
2386
+ );
2387
+ assert.equal(second.outcome, "activated");
2388
+ assert.equal((await methods.findActive(subscriberId))?.paymentMethodRef, "pm_second");
2389
+ const first = await methods.findByReference("stripe-main", "pm_first");
2390
+ assert.equal(first?.status, "REPLACED");
2391
+ assert.equal(first?.replacedAt?.toISOString(), "2026-09-02T10:00:00.000Z");
2392
+ });
2393
+ test("a confirmation recorded again is recognised, and changes nothing", async (t) => {
2394
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2395
+ const createSubscriber = harness.seed.createSubscriber;
2396
+ if (!methods || !createSubscriber) {
2397
+ missing(t, "subscriberPaymentMethods");
2398
+ return;
2399
+ }
2400
+ const { subscriberId } = await createSubscriber({ legalName: "Doppelt GmbH" });
2401
+ const confirmation = paymentMethodFor(
2402
+ subscriberId,
2403
+ "pm_twice",
2404
+ "2026-09-01T10:00:00.000Z"
2405
+ );
2406
+ const first = await methods.recordConfirmed(confirmation);
2407
+ const again = await methods.recordConfirmed({
2408
+ ...confirmation,
2409
+ confirmedAt: /* @__PURE__ */ new Date("2026-09-03T10:00:00.000Z")
2410
+ });
2411
+ assert.equal(again.outcome, "already-recorded");
2412
+ assert.deepEqual(again.method, first.method);
2413
+ assert.deepEqual(await methods.findActive(subscriberId), first.method);
2414
+ });
2415
+ test("a confirmation older than the payment method in use is recorded as already replaced", async (t) => {
2416
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2417
+ const createSubscriber = harness.seed.createSubscriber;
2418
+ if (!methods || !createSubscriber) {
2419
+ missing(t, "subscriberPaymentMethods");
2420
+ return;
2421
+ }
2422
+ const { subscriberId } = await createSubscriber({ legalName: "Reihenfolge GmbH" });
2423
+ await methods.recordConfirmed(
2424
+ paymentMethodFor(subscriberId, "pm_later", "2026-09-02T10:00:00.000Z")
2425
+ );
2426
+ const earlier = await methods.recordConfirmed(
2427
+ paymentMethodFor(subscriberId, "pm_earlier", "2026-09-01T10:00:00.000Z")
2428
+ );
2429
+ assert.equal(earlier.outcome, "superseded");
2430
+ assert.equal(earlier.method.status, "REPLACED");
2431
+ assert.equal(earlier.method.replacedAt?.toISOString(), "2026-09-02T10:00:00.000Z");
2432
+ assert.equal((await methods.findActive(subscriberId))?.paymentMethodRef, "pm_later");
2433
+ });
2434
+ test("two confirmations for one subscriber at once leave one payment method in use", async (t) => {
2435
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2436
+ const createSubscriber = harness.seed.createSubscriber;
2437
+ if (!methods || !createSubscriber) {
2438
+ missing(t, "subscriberPaymentMethods");
2439
+ return;
2440
+ }
2441
+ const { subscriberId } = await createSubscriber({ legalName: "Gleichzeitig GmbH" });
2442
+ const results = await Promise.all([
2443
+ methods.recordConfirmed(
2444
+ paymentMethodFor(subscriberId, "pm_at_once_a", "2026-09-01T10:00:00.000Z")
2445
+ ),
2446
+ methods.recordConfirmed(
2447
+ paymentMethodFor(subscriberId, "pm_at_once_b", "2026-09-01T10:00:01.000Z")
2448
+ )
2449
+ ]);
2450
+ for (const result of results) {
2451
+ assert.ok(
2452
+ result.outcome === "activated" || result.outcome === "superseded",
2453
+ result.outcome
2454
+ );
2455
+ }
2456
+ const statuses = await Promise.all(
2457
+ ["pm_at_once_a", "pm_at_once_b"].map(
2458
+ async (ref) => (await methods.findByReference("stripe-main", ref))?.status
2459
+ )
2460
+ );
2461
+ assert.deepEqual(statuses, ["REPLACED", "ACTIVE"]);
2462
+ assert.equal(
2463
+ (await methods.findActive(subscriberId))?.paymentMethodRef,
2464
+ "pm_at_once_b"
2465
+ );
2466
+ });
2467
+ test("a payment method written on a transaction is undone with it", async (t) => {
2468
+ const { adapter } = harness;
2469
+ const methods = adapter.subscriberPaymentMethodRepository;
2470
+ const createSubscriber = harness.seed.createSubscriber;
2471
+ if (!methods || !createSubscriber) {
2472
+ missing(t, "subscriberPaymentMethods");
2473
+ return;
2474
+ }
2475
+ const { subscriberId } = await createSubscriber({ legalName: "Rolled Back GmbH" });
2476
+ await assert.rejects(
2477
+ adapter.transactionRunner.run(async (tx) => {
2478
+ await methods.recordConfirmed(
2479
+ paymentMethodFor(
2480
+ subscriberId,
2481
+ "pm_rolled_back",
2482
+ "2026-09-01T10:00:00.000Z"
2483
+ ),
2484
+ tx
2485
+ );
2486
+ throw new Error("the activation failed after all");
2487
+ }),
2488
+ /the activation failed after all/
2489
+ );
2490
+ assert.equal(await methods.findActive(subscriberId), null);
2491
+ assert.equal(await methods.findByReference("stripe-main", "pm_rolled_back"), null);
2492
+ });
2493
+ test("a payment method for a subscriber that does not exist is refused", async (t) => {
2494
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2495
+ if (!methods || !harness.seed.createSubscriber) {
2496
+ missing(t, "subscriberPaymentMethods");
2497
+ return;
2498
+ }
2499
+ await assert.rejects(
2500
+ methods.recordConfirmed(
2501
+ paymentMethodFor(
2502
+ "subscriber-nobody-created",
2503
+ "pm_nobody",
2504
+ "2026-09-01T10:00:00.000Z"
2505
+ )
2506
+ )
2507
+ );
2508
+ assert.equal(await methods.findByReference("stripe-main", "pm_nobody"), null);
2509
+ });
2510
+ test("the accounts in use are those holding a payment method in use, each once", async (t) => {
2511
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2512
+ const createSubscriber = harness.seed.createSubscriber;
2513
+ if (!methods || !createSubscriber) {
2514
+ missing(t, "subscriberPaymentMethods");
2515
+ return;
2516
+ }
2517
+ assert.deepEqual(await methods.accountsInUse(), []);
2518
+ const moved = await createSubscriber({ legalName: "Umgezogen GmbH" });
2519
+ const stayed = await createSubscriber({ legalName: "Geblieben GmbH" });
2520
+ await methods.recordConfirmed(
2521
+ paymentMethodFor(
2522
+ moved.subscriberId,
2523
+ "pm_old_account",
2524
+ "2026-09-01T10:00:00.000Z",
2525
+ "stripe-old"
2526
+ )
2527
+ );
2528
+ await methods.recordConfirmed(
2529
+ paymentMethodFor(
2530
+ moved.subscriberId,
2531
+ "pm_new_account",
2532
+ "2026-09-02T10:00:00.000Z",
2533
+ "stripe-main"
2534
+ )
2535
+ );
2536
+ await methods.recordConfirmed(
2537
+ paymentMethodFor(
2538
+ stayed.subscriberId,
2539
+ "pm_main",
2540
+ "2026-09-02T10:00:00.000Z",
2541
+ "stripe-main"
2542
+ )
2543
+ );
2544
+ assert.deepEqual(await methods.accountsInUse(), ["stripe-main"]);
2545
+ });
2546
+ test("a setup is completed once, and only by the account, session and subscriber it was started with", async (t) => {
2547
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2548
+ const createSubscriber = harness.seed.createSubscriber;
2549
+ if (!methods || !createSubscriber) {
2550
+ missing(t, "subscriberPaymentMethods");
2551
+ return;
2552
+ }
2553
+ const { subscriberId } = await createSubscriber({ legalName: "Setup GmbH" });
2554
+ const other = await createSubscriber({ legalName: "Other Tenant GmbH" });
2555
+ await methods.recordSetup({
2556
+ subscriberId,
2557
+ gatewayAccount: "stripe-main",
2558
+ sessionRef: "cs_setup",
2559
+ customerRef: "cus_setup",
2560
+ startedAt: /* @__PURE__ */ new Date("2026-09-15T10:00:00.000Z")
2561
+ });
2562
+ const at = /* @__PURE__ */ new Date("2026-09-15T10:05:00.000Z");
2563
+ const match = { gatewayAccount: "stripe-main", sessionRef: "cs_setup", subscriberId };
2564
+ assert.equal(
2565
+ await methods.completeSetup({ ...match, subscriberId: other.subscriberId }, at),
2566
+ false
2567
+ );
2568
+ assert.equal(
2569
+ await methods.completeSetup({ ...match, gatewayAccount: "stripe-old" }, at),
2570
+ false
2571
+ );
2572
+ assert.equal(
2573
+ await methods.completeSetup({ ...match, sessionRef: "cs_nobody_opened" }, at),
2574
+ false
2575
+ );
2576
+ assert.equal(await methods.completeSetup(match, at), true);
2577
+ assert.equal(
2578
+ await methods.completeSetup(match, at),
2579
+ false,
2580
+ "a setup was completed twice"
2581
+ );
2582
+ });
2583
+ test("a setup completed on a transaction that rolls back is open again", async (t) => {
2584
+ const { adapter } = harness;
2585
+ const methods = adapter.subscriberPaymentMethodRepository;
2586
+ const createSubscriber = harness.seed.createSubscriber;
2587
+ if (!methods || !createSubscriber) {
2588
+ missing(t, "subscriberPaymentMethods");
2589
+ return;
2590
+ }
2591
+ const { subscriberId } = await createSubscriber({ legalName: "Retry GmbH" });
2592
+ const match = { gatewayAccount: "stripe-main", sessionRef: "cs_retry", subscriberId };
2593
+ await methods.recordSetup({
2594
+ ...match,
2595
+ customerRef: "cus_retry",
2596
+ startedAt: /* @__PURE__ */ new Date("2026-09-15T10:00:00.000Z")
2597
+ });
2598
+ const at = /* @__PURE__ */ new Date("2026-09-15T10:05:00.000Z");
2599
+ await assert.rejects(
2600
+ adapter.transactionRunner.run(async (tx) => {
2601
+ assert.equal(await methods.completeSetup(match, at, tx), true);
2602
+ throw new Error("recording the payment method failed");
2603
+ }),
2604
+ /recording the payment method failed/
2605
+ );
2606
+ assert.equal(
2607
+ await methods.completeSetup(match, at),
2608
+ true,
2609
+ "the rollback kept the completion"
2610
+ );
2611
+ });
2612
+ test("one session is one setup, however often it is recorded", async (t) => {
2613
+ const methods = harness.adapter.subscriberPaymentMethodRepository;
2614
+ const createSubscriber = harness.seed.createSubscriber;
2615
+ if (!methods || !createSubscriber) {
2616
+ missing(t, "subscriberPaymentMethods");
2617
+ return;
2618
+ }
2619
+ const { subscriberId } = await createSubscriber({ legalName: "Once GmbH" });
2620
+ const setup = {
2621
+ subscriberId,
2622
+ gatewayAccount: "stripe-main",
2623
+ sessionRef: "cs_once",
2624
+ customerRef: "cus_once",
2625
+ startedAt: /* @__PURE__ */ new Date("2026-09-15T10:00:00.000Z")
2626
+ };
2627
+ await methods.recordSetup(setup);
2628
+ await assert.rejects(methods.recordSetup(setup));
2629
+ });
1718
2630
  test("an offer is consumed once, whoever asks first", async (t) => {
1719
2631
  const offers = harness.adapter.checkoutOfferRepository;
1720
2632
  if (!offers) {