@fantastic.dev/better-stripe 0.95.0 → 0.96.0
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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +2 -5
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +15 -4
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -1
- package/dist/client/billing/renewalObservation/evidence-invoice-lines.d.ts +27 -0
- package/dist/client/billing/renewalObservation/evidence-invoice-lines.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-invoice-lines.js +164 -0
- package/dist/client/billing/renewalObservation/evidence-invoice-lines.js.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-invoice.d.ts +4 -0
- package/dist/client/billing/renewalObservation/evidence-invoice.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-invoice.js +190 -0
- package/dist/client/billing/renewalObservation/evidence-invoice.js.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-material.d.ts +26 -0
- package/dist/client/billing/renewalObservation/evidence-material.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-material.js +253 -0
- package/dist/client/billing/renewalObservation/evidence-material.js.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-v1-types.d.ts +156 -0
- package/dist/client/billing/renewalObservation/evidence-v1-types.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-v1-types.js +2 -0
- package/dist/client/billing/renewalObservation/evidence-v1-types.js.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-v1.d.ts +4 -0
- package/dist/client/billing/renewalObservation/evidence-v1.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/evidence-v1.js +263 -0
- package/dist/client/billing/renewalObservation/evidence-v1.js.map +1 -0
- package/dist/client/billing/renewalObservation/terminal-evidence.d.ts +17 -0
- package/dist/client/billing/renewalObservation/terminal-evidence.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/terminal-evidence.js +289 -0
- package/dist/client/billing/renewalObservation/terminal-evidence.js.map +1 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +9 -5
- package/docs/renewal-material-observation.md +50 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +2 -5
- package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +17 -5
- package/src/client/billing/renewalAttach/internal/producer/producerClock.integration.test.ts +175 -0
- package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +15 -23
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +62 -0
- package/src/client/billing/renewalObservation/evidence-admission.test.ts +219 -0
- package/src/client/billing/renewalObservation/evidence-history.test.ts +187 -0
- package/src/client/billing/renewalObservation/evidence-invoice-controls.test.ts +293 -0
- package/src/client/billing/renewalObservation/evidence-invoice-lines.ts +238 -0
- package/src/client/billing/renewalObservation/evidence-invoice.test.ts +177 -0
- package/src/client/billing/renewalObservation/evidence-invoice.ts +271 -0
- package/src/client/billing/renewalObservation/evidence-material.test.ts +289 -0
- package/src/client/billing/renewalObservation/evidence-material.ts +313 -0
- package/src/client/billing/renewalObservation/evidence-v1-types.ts +186 -0
- package/src/client/billing/renewalObservation/evidence-v1.test.ts +371 -0
- package/src/client/billing/renewalObservation/evidence-v1.ts +286 -0
- package/src/client/billing/renewalObservation/terminal-evidence.ts +379 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import { inspectRenewalEvidenceV1 } from "./evidence-v1.js";
|
|
3
|
+
import { inspectRenewalScheduleMaterialV2 } from "../renewalV2/observation.js";
|
|
4
|
+
import { object, array, get } from "./common.js";
|
|
5
|
+
import type { HistoricalMaterialV1, LifecycleV1 } from "./evidence-v1-types.js";
|
|
6
|
+
import {
|
|
7
|
+
recipe,
|
|
8
|
+
evidence,
|
|
9
|
+
facts,
|
|
10
|
+
complete,
|
|
11
|
+
completionLifecycle,
|
|
12
|
+
currentTarget,
|
|
13
|
+
prerequisites,
|
|
14
|
+
bounded,
|
|
15
|
+
set,
|
|
16
|
+
} from "../../../../tests/renewalObservation/evidenceFixtures.js";
|
|
17
|
+
|
|
18
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
19
|
+
const controls = [
|
|
20
|
+
"full-snapshot",
|
|
21
|
+
"live-default-drift",
|
|
22
|
+
"foreign-snapshot",
|
|
23
|
+
"snapshot-settings",
|
|
24
|
+
"snapshot-native",
|
|
25
|
+
"duplicate-items",
|
|
26
|
+
"terminal-snapshot",
|
|
27
|
+
"absent",
|
|
28
|
+
] as const;
|
|
29
|
+
it.each(controls)("unsigned historical full snapshot %s", async (control) => {
|
|
30
|
+
const h = recipe("active");
|
|
31
|
+
const snapshot = structuredClone(h.baseline.reads);
|
|
32
|
+
const item = object(
|
|
33
|
+
array(get(object(snapshot.subscription), "items").data)[0],
|
|
34
|
+
);
|
|
35
|
+
complete(h.input);
|
|
36
|
+
if (control === "live-default-drift")
|
|
37
|
+
set(
|
|
38
|
+
get(object(h.input.reads.schedule), "default_settings"),
|
|
39
|
+
"description",
|
|
40
|
+
"TEST_LIVE_DRIFT_ONLY",
|
|
41
|
+
);
|
|
42
|
+
if (control === "foreign-snapshot")
|
|
43
|
+
set(snapshot.subscription, "id", "sub_foreign");
|
|
44
|
+
if (control === "snapshot-settings")
|
|
45
|
+
set(snapshot.subscription, "description", "TEST_SNAPSHOT_DRIFT");
|
|
46
|
+
if (control === "snapshot-native")
|
|
47
|
+
set(item, "current_period_end", Number(item.current_period_end) + 1);
|
|
48
|
+
if (control === "duplicate-items") {
|
|
49
|
+
const duplicate = structuredClone(item);
|
|
50
|
+
set(duplicate, "id", "si_second");
|
|
51
|
+
set(get(object(snapshot.subscription), "items"), "data", [item, duplicate]);
|
|
52
|
+
}
|
|
53
|
+
if (control === "terminal-snapshot")
|
|
54
|
+
complete({ ...h.input, reads: snapshot });
|
|
55
|
+
if (control !== "absent")
|
|
56
|
+
set(h.input, "historicalSnapshot", {
|
|
57
|
+
reads: snapshot,
|
|
58
|
+
invoiceContext: null,
|
|
59
|
+
});
|
|
60
|
+
const lifecycle: LifecycleV1 =
|
|
61
|
+
control === "live-default-drift"
|
|
62
|
+
? {
|
|
63
|
+
predicate: "conflict",
|
|
64
|
+
providerStatus: "completed",
|
|
65
|
+
facts: facts(h.input),
|
|
66
|
+
completion: null,
|
|
67
|
+
reason: "material_mismatch",
|
|
68
|
+
}
|
|
69
|
+
: completionLifecycle(h.input);
|
|
70
|
+
let historical: HistoricalMaterialV1;
|
|
71
|
+
if (control === "full-snapshot" || control === "live-default-drift") {
|
|
72
|
+
const match = currentTarget({ ...h.input, reads: snapshot });
|
|
73
|
+
historical = {
|
|
74
|
+
predicate: "snapshot_target_material_match",
|
|
75
|
+
observedItemId: match.observedItemId,
|
|
76
|
+
nativePeriod: match.nativePeriod,
|
|
77
|
+
reason: null,
|
|
78
|
+
};
|
|
79
|
+
} else if (control === "foreign-snapshot")
|
|
80
|
+
historical = {
|
|
81
|
+
predicate: "conflict",
|
|
82
|
+
observedItemId: null,
|
|
83
|
+
nativePeriod: null,
|
|
84
|
+
reason: "snapshot_relation_mismatch",
|
|
85
|
+
};
|
|
86
|
+
else if (control === "snapshot-settings")
|
|
87
|
+
historical = {
|
|
88
|
+
predicate: "conflict",
|
|
89
|
+
observedItemId: null,
|
|
90
|
+
nativePeriod: null,
|
|
91
|
+
reason: "material_mismatch",
|
|
92
|
+
};
|
|
93
|
+
else
|
|
94
|
+
historical = {
|
|
95
|
+
predicate: "unknown",
|
|
96
|
+
observedItemId: null,
|
|
97
|
+
nativePeriod: null,
|
|
98
|
+
reason:
|
|
99
|
+
control === "absent"
|
|
100
|
+
? "not_supplied"
|
|
101
|
+
: control === "duplicate-items"
|
|
102
|
+
? "ambiguous_items"
|
|
103
|
+
: "incomplete_material",
|
|
104
|
+
};
|
|
105
|
+
const expected = {
|
|
106
|
+
...evidence(h.input, lifecycle, {
|
|
107
|
+
predicate: "unknown",
|
|
108
|
+
observedItemId: null,
|
|
109
|
+
nativePeriod: null,
|
|
110
|
+
reason: "terminal_completion_unproven",
|
|
111
|
+
}),
|
|
112
|
+
historicalMaterial: historical,
|
|
113
|
+
};
|
|
114
|
+
let fetchCalls = 0;
|
|
115
|
+
vi.stubGlobal("fetch", () => {
|
|
116
|
+
fetchCalls++;
|
|
117
|
+
throw Error("UNEXPECTED_FETCH");
|
|
118
|
+
});
|
|
119
|
+
await prerequisites(h);
|
|
120
|
+
const old = await inspectRenewalScheduleMaterialV2({
|
|
121
|
+
configuration: h.input.configuration,
|
|
122
|
+
reads: snapshot,
|
|
123
|
+
});
|
|
124
|
+
const base = {
|
|
125
|
+
acknowledgementEstablished: false,
|
|
126
|
+
authenticationEstablished: false,
|
|
127
|
+
providerQualificationRequired: true,
|
|
128
|
+
} as const;
|
|
129
|
+
if (["full-snapshot", "live-default-drift", "absent"].includes(control)) {
|
|
130
|
+
expect(old).toEqual({
|
|
131
|
+
...base,
|
|
132
|
+
predicate: "current_target_material_match",
|
|
133
|
+
observedItemId: "si_successor",
|
|
134
|
+
nativePeriod: currentTarget({ ...h.input, reads: snapshot }).nativePeriod,
|
|
135
|
+
});
|
|
136
|
+
} else if (control === "terminal-snapshot") {
|
|
137
|
+
expect(old).toEqual({
|
|
138
|
+
...base,
|
|
139
|
+
predicate: "terminal_facts_only",
|
|
140
|
+
providerStatus: "completed",
|
|
141
|
+
effectiveness: "unknown",
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
expect(old).toEqual({
|
|
145
|
+
...base,
|
|
146
|
+
predicate:
|
|
147
|
+
control === "foreign-snapshot" || control === "snapshot-settings"
|
|
148
|
+
? "conflict"
|
|
149
|
+
: "unknown",
|
|
150
|
+
reason:
|
|
151
|
+
control === "foreign-snapshot"
|
|
152
|
+
? "original_subscription_identity_mismatch"
|
|
153
|
+
: control === "snapshot-settings"
|
|
154
|
+
? "effective_full_material_drift"
|
|
155
|
+
: control === "snapshot-native"
|
|
156
|
+
? "native_target_period_not_exact"
|
|
157
|
+
: "incomplete_or_ambiguous_current_items",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const before = bounded(h.input);
|
|
161
|
+
let targetFailed = false;
|
|
162
|
+
try {
|
|
163
|
+
const actual = await inspectRenewalEvidenceV1(h.input);
|
|
164
|
+
expect(actual).toEqual(expected);
|
|
165
|
+
expect(Reflect.ownKeys(actual)).toHaveLength(12);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
targetFailed = true;
|
|
168
|
+
throw error;
|
|
169
|
+
} finally {
|
|
170
|
+
try {
|
|
171
|
+
expect(h.input).toEqual(before);
|
|
172
|
+
expect(fetchCalls).toBe(0);
|
|
173
|
+
console.info(
|
|
174
|
+
"EVIDENCE_HISTORY_SETTLEMENT",
|
|
175
|
+
JSON.stringify({
|
|
176
|
+
control,
|
|
177
|
+
targetReached: true,
|
|
178
|
+
inputUnchanged: true,
|
|
179
|
+
fetchCalls,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (!targetFailed) throw error;
|
|
184
|
+
console.info("EVIDENCE_HISTORY_INSPECTION_FAILED");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import { inspectRenewalEvidenceV1 } from "./evidence-v1.js";
|
|
3
|
+
import { object } from "./common.js";
|
|
4
|
+
import type { InvoiceEvidenceV1, Reason } from "./evidence-v1-types.js";
|
|
5
|
+
import {
|
|
6
|
+
invoiceRecipe,
|
|
7
|
+
invoiceMatch,
|
|
8
|
+
currentTarget,
|
|
9
|
+
evidence,
|
|
10
|
+
activeLifecycle,
|
|
11
|
+
prerequisites,
|
|
12
|
+
bounded,
|
|
13
|
+
set,
|
|
14
|
+
} from "../../../../tests/renewalObservation/evidenceFixtures.js";
|
|
15
|
+
|
|
16
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
17
|
+
const controls = [
|
|
18
|
+
"I0-manual",
|
|
19
|
+
"I1-create",
|
|
20
|
+
"invoice-parent",
|
|
21
|
+
"line-sub",
|
|
22
|
+
"line-item",
|
|
23
|
+
"invoice-id",
|
|
24
|
+
"customer",
|
|
25
|
+
"account",
|
|
26
|
+
"mode",
|
|
27
|
+
"price",
|
|
28
|
+
"product",
|
|
29
|
+
"currency",
|
|
30
|
+
"native-end",
|
|
31
|
+
"fractional-quantity",
|
|
32
|
+
"decimal-price-drift",
|
|
33
|
+
"large-decimal-one-unit",
|
|
34
|
+
"quantity-only",
|
|
35
|
+
"legacy-line-only",
|
|
36
|
+
"null-parent",
|
|
37
|
+
"numeric-decimal",
|
|
38
|
+
"too-precise-decimal",
|
|
39
|
+
"duplicate-eligible",
|
|
40
|
+
"duplicate-page",
|
|
41
|
+
"nonprogress",
|
|
42
|
+
"incomplete-page-two",
|
|
43
|
+
"wrong-page-url",
|
|
44
|
+
"too-many-pages",
|
|
45
|
+
"too-many-lines",
|
|
46
|
+
"full-settings-drift",
|
|
47
|
+
"unrelated-supplied-invoice",
|
|
48
|
+
] as const;
|
|
49
|
+
it.each(controls)("unsigned invoice refusal %s", async (control) => {
|
|
50
|
+
const f = invoiceRecipe(
|
|
51
|
+
"subscription_create",
|
|
52
|
+
"open",
|
|
53
|
+
control === "large-decimal-one-unit" ? "large-decimal" : "standard",
|
|
54
|
+
);
|
|
55
|
+
const addon = (id: string) => {
|
|
56
|
+
const row = structuredClone(f.currentLine);
|
|
57
|
+
set(row, "id", id);
|
|
58
|
+
set(row, "subscription", null);
|
|
59
|
+
set(row, "parent", {
|
|
60
|
+
type: "invoice_item_details",
|
|
61
|
+
subscription_item_details: null,
|
|
62
|
+
invoice_item_details: {
|
|
63
|
+
invoice_item: "ii_declared_extra",
|
|
64
|
+
proration: false,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return row;
|
|
68
|
+
};
|
|
69
|
+
let reason: Reason = "invoice_relation_mismatch";
|
|
70
|
+
let predicate: "unknown" | "conflict" = "conflict";
|
|
71
|
+
if (control === "I0-manual" || control === "I1-create") {
|
|
72
|
+
set(
|
|
73
|
+
control === "I0-manual" ? f.originalInvoice : f.currentInvoice,
|
|
74
|
+
"billing_reason",
|
|
75
|
+
control === "I0-manual" ? "manual" : "subscription_create",
|
|
76
|
+
);
|
|
77
|
+
reason = "unsupported_invoice_reason";
|
|
78
|
+
predicate = "unknown";
|
|
79
|
+
}
|
|
80
|
+
if (control === "invoice-parent")
|
|
81
|
+
set(
|
|
82
|
+
f.currentInvoice.parent.subscription_details,
|
|
83
|
+
"subscription",
|
|
84
|
+
"sub_foreign",
|
|
85
|
+
);
|
|
86
|
+
if (control === "line-sub")
|
|
87
|
+
set(
|
|
88
|
+
f.currentLine.parent.subscription_item_details,
|
|
89
|
+
"subscription",
|
|
90
|
+
"sub_foreign",
|
|
91
|
+
);
|
|
92
|
+
if (control === "line-item")
|
|
93
|
+
set(
|
|
94
|
+
f.currentLine.parent.subscription_item_details,
|
|
95
|
+
"subscription_item",
|
|
96
|
+
"si_foreign",
|
|
97
|
+
);
|
|
98
|
+
if (control === "invoice-id") set(f.currentInvoice, "id", "in_foreign");
|
|
99
|
+
if (control === "customer") set(f.currentInvoice, "customer", "cus_foreign");
|
|
100
|
+
if (control === "account")
|
|
101
|
+
set(f.currentInvoice, "customer_account", "acct_foreign");
|
|
102
|
+
if (control === "mode") set(f.currentInvoice, "livemode", true);
|
|
103
|
+
if (control === "price" || control === "product") {
|
|
104
|
+
set(
|
|
105
|
+
f.currentLine.pricing.price_details,
|
|
106
|
+
control,
|
|
107
|
+
control === "price" ? "price_foreign" : "prod_foreign",
|
|
108
|
+
);
|
|
109
|
+
reason = "invoice_material_mismatch";
|
|
110
|
+
}
|
|
111
|
+
if (control === "currency") {
|
|
112
|
+
set(f.currentLine, "currency", "eur");
|
|
113
|
+
reason = "invoice_material_mismatch";
|
|
114
|
+
}
|
|
115
|
+
if (control === "native-end") {
|
|
116
|
+
set(f.currentLine.period, "end", f.currentLine.period.end - 1);
|
|
117
|
+
reason = "invoice_material_mismatch";
|
|
118
|
+
}
|
|
119
|
+
if (control === "fractional-quantity") {
|
|
120
|
+
set(f.currentLine, "quantity_decimal", "3.5");
|
|
121
|
+
reason = "invoice_material_mismatch";
|
|
122
|
+
}
|
|
123
|
+
if (control === "decimal-price-drift") {
|
|
124
|
+
set(f.currentLine.pricing, "unit_amount_decimal", "2000.000000000001");
|
|
125
|
+
reason = "invoice_material_mismatch";
|
|
126
|
+
}
|
|
127
|
+
if (control === "large-decimal-one-unit") {
|
|
128
|
+
const original = f.currentLine.pricing.unit_amount_decimal;
|
|
129
|
+
const changed = "9007199254740991.000000000002";
|
|
130
|
+
expect(
|
|
131
|
+
BigInt(changed.replace(".", "")) - BigInt(original.replace(".", "")),
|
|
132
|
+
).toBe(1n);
|
|
133
|
+
// This offline illusion is why the production comparison may not use Number.
|
|
134
|
+
expect(Number(changed)).toBe(Number(original));
|
|
135
|
+
set(f.currentLine.pricing, "unit_amount_decimal", changed);
|
|
136
|
+
reason = "invoice_material_mismatch";
|
|
137
|
+
}
|
|
138
|
+
if (control === "quantity-only") {
|
|
139
|
+
set(f.currentLine, "quantity_decimal", null);
|
|
140
|
+
reason = "incomplete_invoice_lines";
|
|
141
|
+
predicate = "unknown";
|
|
142
|
+
}
|
|
143
|
+
if (control === "legacy-line-only") {
|
|
144
|
+
set(f.currentLine, "parent", null);
|
|
145
|
+
set(f.currentLine, "pricing", null);
|
|
146
|
+
set(f.currentLine, "price", {
|
|
147
|
+
id: "price_target",
|
|
148
|
+
product: "custom-target",
|
|
149
|
+
});
|
|
150
|
+
set(f.currentLine, "subscription_item", "si_successor");
|
|
151
|
+
reason = "incomplete_invoice_lines";
|
|
152
|
+
predicate = "unknown";
|
|
153
|
+
}
|
|
154
|
+
if (control === "null-parent") {
|
|
155
|
+
set(f.currentInvoice, "parent", null);
|
|
156
|
+
reason = "incomplete_invoice_lines";
|
|
157
|
+
predicate = "unknown";
|
|
158
|
+
}
|
|
159
|
+
if (control === "numeric-decimal" || control === "too-precise-decimal") {
|
|
160
|
+
set(
|
|
161
|
+
f.currentLine.pricing,
|
|
162
|
+
"unit_amount_decimal",
|
|
163
|
+
control === "numeric-decimal" ? 2000 : "2000.0000000000001",
|
|
164
|
+
);
|
|
165
|
+
reason = "unsupported_profile";
|
|
166
|
+
predicate = "unknown";
|
|
167
|
+
}
|
|
168
|
+
if (control === "duplicate-eligible") {
|
|
169
|
+
const duplicate = structuredClone(f.currentLine);
|
|
170
|
+
set(duplicate, "id", "il_duplicate_eligible");
|
|
171
|
+
set(f.currentPages[0], "data", [f.currentLine, duplicate]);
|
|
172
|
+
reason = "incomplete_invoice_lines";
|
|
173
|
+
predicate = "unknown";
|
|
174
|
+
}
|
|
175
|
+
if (control === "duplicate-page") {
|
|
176
|
+
set(f.currentPages[0], "has_more", true);
|
|
177
|
+
f.currentPages.push({
|
|
178
|
+
...structuredClone(f.currentPages[0]),
|
|
179
|
+
has_more: false,
|
|
180
|
+
});
|
|
181
|
+
reason = "incomplete_invoice_lines";
|
|
182
|
+
predicate = "unknown";
|
|
183
|
+
}
|
|
184
|
+
if (control === "incomplete-page-two" || control === "too-many-pages") {
|
|
185
|
+
set(f.currentPages[0], "data", [addon("il_page_one_extra")]);
|
|
186
|
+
set(f.currentPages[0], "has_more", true);
|
|
187
|
+
f.currentPages.push({
|
|
188
|
+
object: "list",
|
|
189
|
+
url: f.currentPages[0].url,
|
|
190
|
+
has_more: true,
|
|
191
|
+
data:
|
|
192
|
+
control === "too-many-pages"
|
|
193
|
+
? [addon("il_page_two_extra")]
|
|
194
|
+
: [f.currentLine],
|
|
195
|
+
});
|
|
196
|
+
if (control === "too-many-pages")
|
|
197
|
+
f.currentPages.push({
|
|
198
|
+
object: "list",
|
|
199
|
+
url: f.currentPages[0].url,
|
|
200
|
+
has_more: false,
|
|
201
|
+
data: [f.currentLine],
|
|
202
|
+
});
|
|
203
|
+
reason = "incomplete_invoice_lines";
|
|
204
|
+
predicate = "unknown";
|
|
205
|
+
}
|
|
206
|
+
if (control === "nonprogress") {
|
|
207
|
+
set(f.currentPages[0], "data", []);
|
|
208
|
+
set(f.currentPages[0], "has_more", true);
|
|
209
|
+
f.currentPages.push({
|
|
210
|
+
object: "list",
|
|
211
|
+
url: f.currentPages[0].url,
|
|
212
|
+
has_more: false,
|
|
213
|
+
data: [f.currentLine],
|
|
214
|
+
});
|
|
215
|
+
reason = "incomplete_invoice_lines";
|
|
216
|
+
predicate = "unknown";
|
|
217
|
+
}
|
|
218
|
+
if (control === "wrong-page-url")
|
|
219
|
+
set(f.currentPages[0], "url", "/v1/invoices/in_foreign/lines");
|
|
220
|
+
if (control === "too-many-lines") {
|
|
221
|
+
set(f.currentPages[0], "data", [
|
|
222
|
+
f.currentLine,
|
|
223
|
+
...Array.from({ length: 100 }, (_, index) => addon(`il_bound_${index}`)),
|
|
224
|
+
]);
|
|
225
|
+
reason = "incomplete_invoice_lines";
|
|
226
|
+
predicate = "unknown";
|
|
227
|
+
}
|
|
228
|
+
if (control === "full-settings-drift")
|
|
229
|
+
set(
|
|
230
|
+
object(f.h.input.reads.subscription),
|
|
231
|
+
"description",
|
|
232
|
+
"TEST_FULL_SUBSCRIPTION_DRIFT",
|
|
233
|
+
);
|
|
234
|
+
if (control === "unrelated-supplied-invoice")
|
|
235
|
+
set(object(f.h.input.reads.subscription), "latest_invoice", "in_original");
|
|
236
|
+
const invoiceEvidence: InvoiceEvidenceV1 =
|
|
237
|
+
control === "full-settings-drift"
|
|
238
|
+
? invoiceMatch(f)
|
|
239
|
+
: { predicate, original: null, current: null, reason };
|
|
240
|
+
const currentMaterial =
|
|
241
|
+
control === "unrelated-supplied-invoice"
|
|
242
|
+
? currentTarget(f.h.input)
|
|
243
|
+
: control === "full-settings-drift"
|
|
244
|
+
? {
|
|
245
|
+
predicate: "conflict" as const,
|
|
246
|
+
observedItemId: null,
|
|
247
|
+
nativePeriod: null,
|
|
248
|
+
reason: "material_mismatch" as const,
|
|
249
|
+
}
|
|
250
|
+
: {
|
|
251
|
+
predicate: "unknown" as const,
|
|
252
|
+
observedItemId: null,
|
|
253
|
+
nativePeriod: null,
|
|
254
|
+
reason: "incomplete_material" as const,
|
|
255
|
+
};
|
|
256
|
+
const expected = {
|
|
257
|
+
...evidence(f.h.input, activeLifecycle, currentMaterial),
|
|
258
|
+
invoiceEvidence,
|
|
259
|
+
};
|
|
260
|
+
let fetchCalls = 0;
|
|
261
|
+
vi.stubGlobal("fetch", () => {
|
|
262
|
+
fetchCalls++;
|
|
263
|
+
throw Error("UNEXPECTED_FETCH");
|
|
264
|
+
});
|
|
265
|
+
await prerequisites(f.h);
|
|
266
|
+
const before = bounded(f.h.input);
|
|
267
|
+
let targetFailed = false;
|
|
268
|
+
try {
|
|
269
|
+
const actual = await inspectRenewalEvidenceV1(f.h.input);
|
|
270
|
+
expect(actual).toEqual(expected);
|
|
271
|
+
expect(Reflect.ownKeys(actual)).toHaveLength(12);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
targetFailed = true;
|
|
274
|
+
throw error;
|
|
275
|
+
} finally {
|
|
276
|
+
try {
|
|
277
|
+
expect(f.h.input).toEqual(before);
|
|
278
|
+
expect(fetchCalls).toBe(0);
|
|
279
|
+
console.info(
|
|
280
|
+
"EVIDENCE_INVOICE_CONTROL_SETTLEMENT",
|
|
281
|
+
JSON.stringify({
|
|
282
|
+
control,
|
|
283
|
+
targetReached: true,
|
|
284
|
+
inputUnchanged: true,
|
|
285
|
+
fetchCalls,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (!targetFailed) throw error;
|
|
290
|
+
console.info("EVIDENCE_INVOICE_CONTROL_INSPECTION_FAILED");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|