@tellescope/sdk 1.256.6 → 1.256.7
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/lib/cjs/enduser.d.ts +1 -1
- package/lib/cjs/enduser.d.ts.map +1 -1
- package/lib/cjs/enduser.js +1 -0
- package/lib/cjs/enduser.js.map +1 -1
- package/lib/cjs/tests/api_tests/calendar_event_create_and_bulk_triggers.test.d.ts +6 -0
- package/lib/cjs/tests/api_tests/calendar_event_create_and_bulk_triggers.test.d.ts.map +1 -0
- package/lib/cjs/tests/api_tests/calendar_event_create_and_bulk_triggers.test.js +505 -0
- package/lib/cjs/tests/api_tests/calendar_event_create_and_bulk_triggers.test.js.map +1 -0
- package/lib/cjs/tests/api_tests/configurations_public_read.test.d.ts +6 -0
- package/lib/cjs/tests/api_tests/configurations_public_read.test.d.ts.map +1 -0
- package/lib/cjs/tests/api_tests/configurations_public_read.test.js +173 -0
- package/lib/cjs/tests/api_tests/configurations_public_read.test.js.map +1 -0
- package/lib/cjs/tests/api_tests/form_started_trigger.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/form_started_trigger.test.js +87 -24
- package/lib/cjs/tests/api_tests/form_started_trigger.test.js.map +1 -1
- package/lib/cjs/tests/api_tests/form_translations.test.d.ts +6 -0
- package/lib/cjs/tests/api_tests/form_translations.test.d.ts.map +1 -0
- package/lib/cjs/tests/api_tests/form_translations.test.js +259 -0
- package/lib/cjs/tests/api_tests/form_translations.test.js.map +1 -0
- package/lib/cjs/tests/api_tests/group_event_attendee_status_triggers.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/group_event_attendee_status_triggers.test.js +340 -124
- package/lib/cjs/tests/api_tests/group_event_attendee_status_triggers.test.js.map +1 -1
- package/lib/cjs/tests/api_tests/mdi_trigger_refill.test.d.ts +6 -0
- package/lib/cjs/tests/api_tests/mdi_trigger_refill.test.d.ts.map +1 -0
- package/lib/cjs/tests/api_tests/mdi_trigger_refill.test.js +277 -0
- package/lib/cjs/tests/api_tests/mdi_trigger_refill.test.js.map +1 -0
- package/lib/cjs/tests/api_tests/purchase_made_trigger.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/purchase_made_trigger.test.js +262 -78
- package/lib/cjs/tests/api_tests/purchase_made_trigger.test.js.map +1 -1
- package/lib/cjs/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.d.ts +31 -0
- package/lib/cjs/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.d.ts.map +1 -0
- package/lib/cjs/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.js +230 -0
- package/lib/cjs/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.js.map +1 -0
- package/lib/cjs/tests/api_tests/security/public_endpoint_auth_field_lock.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/security/public_endpoint_auth_field_lock.test.js +206 -198
- package/lib/cjs/tests/api_tests/security/public_endpoint_auth_field_lock.test.js.map +1 -1
- package/lib/cjs/tests/api_tests/stripe_webhook_triggers.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/stripe_webhook_triggers.test.js +343 -80
- package/lib/cjs/tests/api_tests/stripe_webhook_triggers.test.js.map +1 -1
- package/lib/cjs/tests/api_tests/welle_partner_token.test.d.ts.map +1 -1
- package/lib/cjs/tests/api_tests/welle_partner_token.test.js +74 -35
- package/lib/cjs/tests/api_tests/welle_partner_token.test.js.map +1 -1
- package/lib/cjs/tests/stripe_webhook_helpers.d.ts +134 -0
- package/lib/cjs/tests/stripe_webhook_helpers.d.ts.map +1 -1
- package/lib/cjs/tests/stripe_webhook_helpers.js +126 -1
- package/lib/cjs/tests/stripe_webhook_helpers.js.map +1 -1
- package/lib/cjs/tests/tests.d.ts.map +1 -1
- package/lib/cjs/tests/tests.js +238 -212
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/enduser.d.ts +1 -1
- package/lib/esm/enduser.d.ts.map +1 -1
- package/lib/esm/enduser.js +1 -0
- package/lib/esm/enduser.js.map +1 -1
- package/lib/esm/tests/api_tests/calendar_event_create_and_bulk_triggers.test.d.ts +6 -0
- package/lib/esm/tests/api_tests/calendar_event_create_and_bulk_triggers.test.d.ts.map +1 -0
- package/lib/esm/tests/api_tests/calendar_event_create_and_bulk_triggers.test.js +501 -0
- package/lib/esm/tests/api_tests/calendar_event_create_and_bulk_triggers.test.js.map +1 -0
- package/lib/esm/tests/api_tests/configurations_public_read.test.d.ts +6 -0
- package/lib/esm/tests/api_tests/configurations_public_read.test.d.ts.map +1 -0
- package/lib/esm/tests/api_tests/configurations_public_read.test.js +169 -0
- package/lib/esm/tests/api_tests/configurations_public_read.test.js.map +1 -0
- package/lib/esm/tests/api_tests/form_started_trigger.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/form_started_trigger.test.js +87 -24
- package/lib/esm/tests/api_tests/form_started_trigger.test.js.map +1 -1
- package/lib/esm/tests/api_tests/form_translations.test.d.ts +6 -0
- package/lib/esm/tests/api_tests/form_translations.test.d.ts.map +1 -0
- package/lib/esm/tests/api_tests/form_translations.test.js +255 -0
- package/lib/esm/tests/api_tests/form_translations.test.js.map +1 -0
- package/lib/esm/tests/api_tests/group_event_attendee_status_triggers.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/group_event_attendee_status_triggers.test.js +340 -124
- package/lib/esm/tests/api_tests/group_event_attendee_status_triggers.test.js.map +1 -1
- package/lib/esm/tests/api_tests/mdi_trigger_refill.test.d.ts +6 -0
- package/lib/esm/tests/api_tests/mdi_trigger_refill.test.d.ts.map +1 -0
- package/lib/esm/tests/api_tests/mdi_trigger_refill.test.js +273 -0
- package/lib/esm/tests/api_tests/mdi_trigger_refill.test.js.map +1 -0
- package/lib/esm/tests/api_tests/purchase_made_trigger.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/purchase_made_trigger.test.js +262 -78
- package/lib/esm/tests/api_tests/purchase_made_trigger.test.js.map +1 -1
- package/lib/esm/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.d.ts +31 -0
- package/lib/esm/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.d.ts.map +1 -0
- package/lib/esm/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.js +226 -0
- package/lib/esm/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.js.map +1 -0
- package/lib/esm/tests/api_tests/security/public_endpoint_auth_field_lock.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/security/public_endpoint_auth_field_lock.test.js +206 -198
- package/lib/esm/tests/api_tests/security/public_endpoint_auth_field_lock.test.js.map +1 -1
- package/lib/esm/tests/api_tests/stripe_webhook_triggers.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/stripe_webhook_triggers.test.js +344 -81
- package/lib/esm/tests/api_tests/stripe_webhook_triggers.test.js.map +1 -1
- package/lib/esm/tests/api_tests/welle_partner_token.test.d.ts.map +1 -1
- package/lib/esm/tests/api_tests/welle_partner_token.test.js +74 -35
- package/lib/esm/tests/api_tests/welle_partner_token.test.js.map +1 -1
- package/lib/esm/tests/stripe_webhook_helpers.d.ts +134 -0
- package/lib/esm/tests/stripe_webhook_helpers.d.ts.map +1 -1
- package/lib/esm/tests/stripe_webhook_helpers.js +119 -0
- package/lib/esm/tests/stripe_webhook_helpers.js.map +1 -1
- package/lib/esm/tests/tests.d.ts.map +1 -1
- package/lib/esm/tests/tests.js +238 -212
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/enduser.ts +4 -2
- package/src/tests/api_tests/calendar_event_create_and_bulk_triggers.test.ts +293 -0
- package/src/tests/api_tests/configurations_public_read.test.ts +116 -0
- package/src/tests/api_tests/form_started_trigger.test.ts +49 -1
- package/src/tests/api_tests/form_translations.test.ts +205 -0
- package/src/tests/api_tests/group_event_attendee_status_triggers.test.ts +135 -0
- package/src/tests/api_tests/mdi_trigger_refill.test.ts +184 -0
- package/src/tests/api_tests/purchase_made_trigger.test.ts +137 -0
- package/src/tests/api_tests/security/F-0006-develop-health-benefit-verification-rbac.test.ts +144 -0
- package/src/tests/api_tests/security/public_endpoint_auth_field_lock.test.ts +16 -6
- package/src/tests/api_tests/stripe_webhook_triggers.test.ts +221 -0
- package/src/tests/api_tests/welle_partner_token.test.ts +49 -6
- package/src/tests/stripe_webhook_helpers.ts +116 -0
- package/src/tests/tests.ts +27 -12
- package/test_generated.pdf +0 -0
|
@@ -58,7 +58,7 @@ require('source-map-support').install();
|
|
|
58
58
|
import { Session } from "../../sdk";
|
|
59
59
|
import { assert, log_header, wait } from "@tellescope/testing";
|
|
60
60
|
import { setup_tests } from "../setup";
|
|
61
|
-
import { invoice_payment_failed_event, item_with_expanded_price_product, item_with_plan_product, item_with_price_product, line_with_expanded_price_product, line_with_plan_product, line_with_price_product, PAUSE_COLLECTION, post_stripe_webhook, setup_stripe_test_integration, sign_stripe_payload, subscription_deleted_event, subscription_paused_event, subscription_resumed_event, subscription_updated_event, } from "../stripe_webhook_helpers";
|
|
61
|
+
import { charge_succeeded_event, discount_with_coupon, discount_with_promo_code, discount_with_promo_code_ref, invoice_paid_event, invoice_paid_line, invoice_payment_failed_event, item_with_expanded_price_product, item_with_plan_product, item_with_price_product, line_with_expanded_price_product, line_with_plan_product, line_with_price_product, PAUSE_COLLECTION, post_stripe_webhook, setup_stripe_test_integration, sign_stripe_payload, subscription_deleted_event, subscription_paused_event, subscription_resumed_event, subscription_updated_event, } from "../stripe_webhook_helpers";
|
|
62
62
|
var host = process.env.API_URL || "http://localhost:8080";
|
|
63
63
|
/**
|
|
64
64
|
* End-to-end coverage of the custom Stripe webhook -> automation trigger path, driven by synthetic
|
|
@@ -75,10 +75,10 @@ var host = process.env.API_URL || "http://localhost:8080";
|
|
|
75
75
|
export var stripe_webhook_triggers_tests = function (_a) {
|
|
76
76
|
var sdk = _a.sdk, sdkNonAdmin = _a.sdkNonAdmin;
|
|
77
77
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var RUN, tag, createdEnduserIds, createdTriggerIds, createdProductIds, _b, stripePublicKey, webhooksSecret, cleanup, new_enduser, new_trigger, new_product, poll_for_tag, expect_fired, expect_not_fired, B1_TAG, b1Enduser, b1Event, b1Res, b2Res, B3_TAG, b3Enduser, b3Res, B4_TAG, b4Enduser, b4Res, stripeProductA_1, stripeProductB, productA, productB, B5_TAG, b5Enduser, b5Res, B6_TAG, b6Enduser, B7_TAG, b7Enduser, B8_TAG, b8Enduser, run_scoped_payment_failed_case, f7Scoped, f7Fetched, rejectedInvalidProductId, e_1, run_pause_case, p14Scoped, p14Fetched, rejectedInvalidPausedProductId, e_2;
|
|
79
|
-
var _c, _d;
|
|
80
|
-
return __generator(this, function (
|
|
81
|
-
switch (
|
|
78
|
+
var RUN, tag, createdEnduserIds, createdTriggerIds, createdProductIds, _b, stripePublicKey, webhooksSecret, cleanup, new_enduser, new_trigger, new_product, poll_for_tag, expect_fired, expect_not_fired, B1_TAG, b1Enduser, b1Event, b1Res, b2Res, B3_TAG, b3Enduser, b3Res, B4_TAG, b4Enduser, b4Res, stripeProductA_1, stripeProductB, productA, productB, B5_TAG, b5Enduser, b5Res, B6_TAG, b6Enduser, B7_TAG, b7Enduser, B8_TAG, b8Enduser, run_scoped_payment_failed_case, f7Scoped, f7Fetched, rejectedInvalidProductId, e_1, run_pause_case, p14Scoped, p14Fetched, rejectedInvalidPausedProductId, e_2, poll_for_purchase, run_coupon_invoice_case, c1Enduser, c1Purchases, c1bDiscount, c1bEnduser, c1bPurchases, c5Discount, C7_TAG, C7_SCOPED_TAG, c7Enduser, c7Res, c7Purchases, C8_TAG, c8Enduser, c8Res, c9Trigger, c9Fetched;
|
|
79
|
+
var _c, _d, _e;
|
|
80
|
+
return __generator(this, function (_f) {
|
|
81
|
+
switch (_f.label) {
|
|
82
82
|
case 0:
|
|
83
83
|
log_header("Stripe Webhook Triggers");
|
|
84
84
|
RUN = "".concat(Date.now());
|
|
@@ -90,7 +90,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
90
90
|
// Each enduser is matched by the handler on stripeCustomerId, so it must be unique per case.
|
|
91
91
|
];
|
|
92
92
|
case 1:
|
|
93
|
-
_b =
|
|
93
|
+
_b = _f.sent(), stripePublicKey = _b.stripePublicKey, webhooksSecret = _b.webhooksSecret, cleanup = _b.cleanup;
|
|
94
94
|
new_enduser = function (label) { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
95
|
var stripeCustomerId, enduser;
|
|
96
96
|
return __generator(this, function (_a) {
|
|
@@ -206,20 +206,20 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}); };
|
|
209
|
-
|
|
209
|
+
_f.label = 2;
|
|
210
210
|
case 2:
|
|
211
|
-
|
|
211
|
+
_f.trys.push([2, , 92, 95]);
|
|
212
212
|
B1_TAG = tag('b1-bad-signature');
|
|
213
213
|
return [4 /*yield*/, new_enduser('b1')];
|
|
214
214
|
case 3:
|
|
215
|
-
b1Enduser =
|
|
215
|
+
b1Enduser = _f.sent();
|
|
216
216
|
return [4 /*yield*/, new_trigger({
|
|
217
217
|
title: "Stripe payment failed (bad signature) ".concat(RUN),
|
|
218
218
|
event: { type: 'Subscription Payment Failed', info: {} },
|
|
219
219
|
tags: [B1_TAG],
|
|
220
220
|
})];
|
|
221
221
|
case 4:
|
|
222
|
-
|
|
222
|
+
_f.sent();
|
|
223
223
|
b1Event = invoice_payment_failed_event({ stripeCustomerId: b1Enduser.stripeCustomerId });
|
|
224
224
|
return [4 /*yield*/, post_stripe_webhook({
|
|
225
225
|
stripePublicKey: stripePublicKey,
|
|
@@ -228,57 +228,57 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
228
228
|
signature: sign_stripe_payload('{"tampered":true}', webhooksSecret),
|
|
229
229
|
})];
|
|
230
230
|
case 5:
|
|
231
|
-
b1Res =
|
|
231
|
+
b1Res = _f.sent();
|
|
232
232
|
assert(b1Res.status === 400, "expected 400 for a mismatched signature, got ".concat(b1Res.status), 'invalid signature rejected');
|
|
233
233
|
return [4 /*yield*/, expect_not_fired(b1Enduser.id, B1_TAG, 'invalid signature does not fire triggers')
|
|
234
234
|
// B2: unknown public key in the URL -> no integration -> 404
|
|
235
235
|
];
|
|
236
236
|
case 6:
|
|
237
|
-
|
|
237
|
+
_f.sent();
|
|
238
238
|
return [4 /*yield*/, post_stripe_webhook({
|
|
239
239
|
stripePublicKey: "pk_test_missing_".concat(RUN),
|
|
240
240
|
secret: webhooksSecret,
|
|
241
241
|
event: invoice_payment_failed_event({ stripeCustomerId: "cus_test_missing_".concat(RUN) }),
|
|
242
242
|
})];
|
|
243
243
|
case 7:
|
|
244
|
-
b2Res =
|
|
244
|
+
b2Res = _f.sent();
|
|
245
245
|
assert(b2Res.status === 404, "expected 404 for an unknown public key, got ".concat(b2Res.status), 'unknown integration rejected');
|
|
246
246
|
B3_TAG = tag('b3-unknown-customer');
|
|
247
247
|
return [4 /*yield*/, new_enduser('b3')];
|
|
248
248
|
case 8:
|
|
249
|
-
b3Enduser =
|
|
249
|
+
b3Enduser = _f.sent();
|
|
250
250
|
return [4 /*yield*/, new_trigger({
|
|
251
251
|
title: "Stripe payment failed (unknown customer) ".concat(RUN),
|
|
252
252
|
event: { type: 'Subscription Payment Failed', info: {} },
|
|
253
253
|
tags: [B3_TAG],
|
|
254
254
|
})];
|
|
255
255
|
case 9:
|
|
256
|
-
|
|
256
|
+
_f.sent();
|
|
257
257
|
return [4 /*yield*/, post_stripe_webhook({
|
|
258
258
|
stripePublicKey: stripePublicKey,
|
|
259
259
|
secret: webhooksSecret,
|
|
260
260
|
event: invoice_payment_failed_event({ stripeCustomerId: "cus_test_nobody_".concat(RUN) }),
|
|
261
261
|
})];
|
|
262
262
|
case 10:
|
|
263
|
-
b3Res =
|
|
263
|
+
b3Res = _f.sent();
|
|
264
264
|
assert(b3Res.status === 200, "expected 200 for an unmatched customer, got ".concat(b3Res.status), 'unmatched customer accepted');
|
|
265
265
|
return [4 /*yield*/, expect_not_fired(b3Enduser.id, B3_TAG, 'unmatched customer does not fire triggers')
|
|
266
266
|
// B4: the baseline behavior the productIds feature must preserve — a Subscription Payment Failed
|
|
267
267
|
// trigger with no product scoping fires for any failed invoice.
|
|
268
268
|
];
|
|
269
269
|
case 11:
|
|
270
|
-
|
|
270
|
+
_f.sent();
|
|
271
271
|
B4_TAG = tag('b4-unscoped');
|
|
272
272
|
return [4 /*yield*/, new_enduser('b4')];
|
|
273
273
|
case 12:
|
|
274
|
-
b4Enduser =
|
|
274
|
+
b4Enduser = _f.sent();
|
|
275
275
|
return [4 /*yield*/, new_trigger({
|
|
276
276
|
title: "Stripe payment failed (unscoped) ".concat(RUN),
|
|
277
277
|
event: { type: 'Subscription Payment Failed', info: {} },
|
|
278
278
|
tags: [B4_TAG],
|
|
279
279
|
})];
|
|
280
280
|
case 13:
|
|
281
|
-
|
|
281
|
+
_f.sent();
|
|
282
282
|
return [4 /*yield*/, post_stripe_webhook({
|
|
283
283
|
stripePublicKey: stripePublicKey,
|
|
284
284
|
secret: webhooksSecret,
|
|
@@ -288,35 +288,35 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
288
288
|
}),
|
|
289
289
|
})];
|
|
290
290
|
case 14:
|
|
291
|
-
b4Res =
|
|
291
|
+
b4Res = _f.sent();
|
|
292
292
|
assert(b4Res.status === 200, "expected 200, got ".concat(b4Res.status, " (").concat(b4Res.data, ")"), 'payment failed webhook accepted');
|
|
293
293
|
return [4 /*yield*/, expect_fired(b4Enduser.id, B4_TAG, 'unscoped Subscription Payment Failed trigger fires')
|
|
294
294
|
/* ===================== customer.subscription.deleted ===================== */
|
|
295
295
|
// Products A and B exist to distinguish "the subscription's product" from "some other product".
|
|
296
296
|
];
|
|
297
297
|
case 15:
|
|
298
|
-
|
|
298
|
+
_f.sent();
|
|
299
299
|
stripeProductA_1 = "prod_test_a_".concat(RUN);
|
|
300
300
|
stripeProductB = "prod_test_b_".concat(RUN);
|
|
301
301
|
return [4 /*yield*/, new_product('A', stripeProductA_1)];
|
|
302
302
|
case 16:
|
|
303
|
-
productA =
|
|
303
|
+
productA = _f.sent();
|
|
304
304
|
return [4 /*yield*/, new_product('B', stripeProductB)
|
|
305
305
|
// B5: unscoped Subscription Ended fires
|
|
306
306
|
];
|
|
307
307
|
case 17:
|
|
308
|
-
productB =
|
|
308
|
+
productB = _f.sent();
|
|
309
309
|
B5_TAG = tag('b5-ended-unscoped');
|
|
310
310
|
return [4 /*yield*/, new_enduser('b5')];
|
|
311
311
|
case 18:
|
|
312
|
-
b5Enduser =
|
|
312
|
+
b5Enduser = _f.sent();
|
|
313
313
|
return [4 /*yield*/, new_trigger({
|
|
314
314
|
title: "Stripe subscription ended (unscoped) ".concat(RUN),
|
|
315
315
|
event: { type: 'Subscription Ended', info: {} },
|
|
316
316
|
tags: [B5_TAG],
|
|
317
317
|
})];
|
|
318
318
|
case 19:
|
|
319
|
-
|
|
319
|
+
_f.sent();
|
|
320
320
|
return [4 /*yield*/, post_stripe_webhook({
|
|
321
321
|
stripePublicKey: stripePublicKey,
|
|
322
322
|
secret: webhooksSecret,
|
|
@@ -326,24 +326,24 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
326
326
|
}),
|
|
327
327
|
})];
|
|
328
328
|
case 20:
|
|
329
|
-
b5Res =
|
|
329
|
+
b5Res = _f.sent();
|
|
330
330
|
assert(b5Res.status === 200, "expected 200, got ".concat(b5Res.status, " (").concat(b5Res.data, ")"), 'subscription deleted webhook accepted');
|
|
331
331
|
return [4 /*yield*/, expect_fired(b5Enduser.id, B5_TAG, 'unscoped Subscription Ended trigger fires')
|
|
332
332
|
// B6: an explicitly empty productIds list means "all products"
|
|
333
333
|
];
|
|
334
334
|
case 21:
|
|
335
|
-
|
|
335
|
+
_f.sent();
|
|
336
336
|
B6_TAG = tag('b6-ended-empty-list');
|
|
337
337
|
return [4 /*yield*/, new_enduser('b6')];
|
|
338
338
|
case 22:
|
|
339
|
-
b6Enduser =
|
|
339
|
+
b6Enduser = _f.sent();
|
|
340
340
|
return [4 /*yield*/, new_trigger({
|
|
341
341
|
title: "Stripe subscription ended (empty productIds) ".concat(RUN),
|
|
342
342
|
event: { type: 'Subscription Ended', info: { productIds: [] } },
|
|
343
343
|
tags: [B6_TAG],
|
|
344
344
|
})];
|
|
345
345
|
case 23:
|
|
346
|
-
|
|
346
|
+
_f.sent();
|
|
347
347
|
return [4 /*yield*/, post_stripe_webhook({
|
|
348
348
|
stripePublicKey: stripePublicKey,
|
|
349
349
|
secret: webhooksSecret,
|
|
@@ -353,25 +353,25 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
353
353
|
}),
|
|
354
354
|
})];
|
|
355
355
|
case 24:
|
|
356
|
-
|
|
356
|
+
_f.sent();
|
|
357
357
|
return [4 /*yield*/, expect_fired(b6Enduser.id, B6_TAG, 'Subscription Ended trigger with empty productIds fires')
|
|
358
358
|
// B7/B8 pin the existing product-matching semantics end-to-end, so any refactor of the
|
|
359
359
|
// productIds query clause is provably behavior-preserving.
|
|
360
360
|
// B7: productIds matching the subscription's product fires
|
|
361
361
|
];
|
|
362
362
|
case 25:
|
|
363
|
-
|
|
363
|
+
_f.sent();
|
|
364
364
|
B7_TAG = tag('b7-ended-matching');
|
|
365
365
|
return [4 /*yield*/, new_enduser('b7')];
|
|
366
366
|
case 26:
|
|
367
|
-
b7Enduser =
|
|
367
|
+
b7Enduser = _f.sent();
|
|
368
368
|
return [4 /*yield*/, new_trigger({
|
|
369
369
|
title: "Stripe subscription ended (matching product) ".concat(RUN),
|
|
370
370
|
event: { type: 'Subscription Ended', info: { productIds: [productA.id] } },
|
|
371
371
|
tags: [B7_TAG],
|
|
372
372
|
})];
|
|
373
373
|
case 27:
|
|
374
|
-
|
|
374
|
+
_f.sent();
|
|
375
375
|
return [4 /*yield*/, post_stripe_webhook({
|
|
376
376
|
stripePublicKey: stripePublicKey,
|
|
377
377
|
secret: webhooksSecret,
|
|
@@ -381,23 +381,23 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
381
381
|
}),
|
|
382
382
|
})];
|
|
383
383
|
case 28:
|
|
384
|
-
|
|
384
|
+
_f.sent();
|
|
385
385
|
return [4 /*yield*/, expect_fired(b7Enduser.id, B7_TAG, 'Subscription Ended trigger scoped to the matching product fires')
|
|
386
386
|
// B8: productIds naming a different product does not fire
|
|
387
387
|
];
|
|
388
388
|
case 29:
|
|
389
|
-
|
|
389
|
+
_f.sent();
|
|
390
390
|
B8_TAG = tag('b8-ended-nonmatching');
|
|
391
391
|
return [4 /*yield*/, new_enduser('b8')];
|
|
392
392
|
case 30:
|
|
393
|
-
b8Enduser =
|
|
393
|
+
b8Enduser = _f.sent();
|
|
394
394
|
return [4 /*yield*/, new_trigger({
|
|
395
395
|
title: "Stripe subscription ended (other product) ".concat(RUN),
|
|
396
396
|
event: { type: 'Subscription Ended', info: { productIds: [productB.id] } },
|
|
397
397
|
tags: [B8_TAG],
|
|
398
398
|
})];
|
|
399
399
|
case 31:
|
|
400
|
-
|
|
400
|
+
_f.sent();
|
|
401
401
|
return [4 /*yield*/, post_stripe_webhook({
|
|
402
402
|
stripePublicKey: stripePublicKey,
|
|
403
403
|
secret: webhooksSecret,
|
|
@@ -407,14 +407,14 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
407
407
|
}),
|
|
408
408
|
})];
|
|
409
409
|
case 32:
|
|
410
|
-
|
|
410
|
+
_f.sent();
|
|
411
411
|
return [4 /*yield*/, expect_not_fired(b8Enduser.id, B8_TAG, 'Subscription Ended trigger scoped to another product does not fire')
|
|
412
412
|
/* ============ invoice.payment_failed, scoped to products ============ */
|
|
413
413
|
// Shared shape for the cases below: a trigger scoped to productA, and an invoice whose line
|
|
414
414
|
// items are varied per case to cover how Stripe can reference a product.
|
|
415
415
|
];
|
|
416
416
|
case 33:
|
|
417
|
-
|
|
417
|
+
_f.sent();
|
|
418
418
|
run_scoped_payment_failed_case = function (_a) {
|
|
419
419
|
var label = _a.label, productIds = _a.productIds, lines = _a.lines, shouldFire = _a.shouldFire, title = _a.title;
|
|
420
420
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -467,7 +467,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
467
467
|
];
|
|
468
468
|
case 34:
|
|
469
469
|
// F1: the feature — a trigger scoped to the product that actually failed fires
|
|
470
|
-
|
|
470
|
+
_f.sent();
|
|
471
471
|
// F2: the point of the feature — a trigger scoped to a different product stays quiet
|
|
472
472
|
return [4 /*yield*/, run_scoped_payment_failed_case({
|
|
473
473
|
label: 'f2-nonmatching',
|
|
@@ -480,7 +480,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
480
480
|
];
|
|
481
481
|
case 35:
|
|
482
482
|
// F2: the point of the feature — a trigger scoped to a different product stays quiet
|
|
483
|
-
|
|
483
|
+
_f.sent();
|
|
484
484
|
// F3: "leave blank for all" — an empty list is not a filter
|
|
485
485
|
return [4 /*yield*/, run_scoped_payment_failed_case({
|
|
486
486
|
label: 'f3-empty-list',
|
|
@@ -493,7 +493,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
493
493
|
];
|
|
494
494
|
case 36:
|
|
495
495
|
// F3: "leave blank for all" — an empty list is not a filter
|
|
496
|
-
|
|
496
|
+
_f.sent();
|
|
497
497
|
// F4: price.product may arrive expanded as an object rather than a bare id
|
|
498
498
|
return [4 /*yield*/, run_scoped_payment_failed_case({
|
|
499
499
|
label: 'f4-expanded-product',
|
|
@@ -506,7 +506,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
506
506
|
];
|
|
507
507
|
case 37:
|
|
508
508
|
// F4: price.product may arrive expanded as an object rather than a bare id
|
|
509
|
-
|
|
509
|
+
_f.sent();
|
|
510
510
|
// F5: subscription/proration lines can carry plan.product with no price
|
|
511
511
|
return [4 /*yield*/, run_scoped_payment_failed_case({
|
|
512
512
|
label: 'f5-plan-product',
|
|
@@ -519,7 +519,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
519
519
|
];
|
|
520
520
|
case 38:
|
|
521
521
|
// F5: subscription/proration lines can carry plan.product with no price
|
|
522
|
-
|
|
522
|
+
_f.sent();
|
|
523
523
|
// F6: one matching line among several is enough
|
|
524
524
|
return [4 /*yield*/, run_scoped_payment_failed_case({
|
|
525
525
|
label: 'f6-multi-line',
|
|
@@ -534,17 +534,17 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
534
534
|
];
|
|
535
535
|
case 39:
|
|
536
536
|
// F6: one matching line among several is enough
|
|
537
|
-
|
|
537
|
+
_f.sent();
|
|
538
538
|
return [4 /*yield*/, new_trigger({
|
|
539
539
|
title: "Stripe payment failed (validator round-trip) ".concat(RUN),
|
|
540
540
|
event: { type: 'Subscription Payment Failed', info: { productIds: [productA.id] } },
|
|
541
541
|
tags: [tag('f7')],
|
|
542
542
|
})];
|
|
543
543
|
case 40:
|
|
544
|
-
f7Scoped =
|
|
544
|
+
f7Scoped = _f.sent();
|
|
545
545
|
return [4 /*yield*/, sdk.api.automation_triggers.getOne(f7Scoped.id)];
|
|
546
546
|
case 41:
|
|
547
|
-
f7Fetched =
|
|
547
|
+
f7Fetched = _f.sent();
|
|
548
548
|
assert(JSON.stringify((_c = f7Fetched.event.info) === null || _c === void 0 ? void 0 : _c.productIds) === JSON.stringify([productA.id]), "expected productIds to round-trip, got ".concat(JSON.stringify(f7Fetched.event)), 'productIds round-trips through the validator');
|
|
549
549
|
return [4 /*yield*/, new_trigger({
|
|
550
550
|
title: "Stripe payment failed (empty info) ".concat(RUN),
|
|
@@ -552,7 +552,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
552
552
|
tags: [tag('f7-empty-info')],
|
|
553
553
|
})];
|
|
554
554
|
case 42:
|
|
555
|
-
|
|
555
|
+
_f.sent();
|
|
556
556
|
assert(true, '', 'empty info accepted');
|
|
557
557
|
return [4 /*yield*/, new_trigger({
|
|
558
558
|
title: "Stripe payment failed (no info) ".concat(RUN),
|
|
@@ -560,22 +560,22 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
560
560
|
tags: [tag('f7-no-info')],
|
|
561
561
|
})];
|
|
562
562
|
case 43:
|
|
563
|
-
|
|
563
|
+
_f.sent();
|
|
564
564
|
assert(true, '', 'omitted info still accepted');
|
|
565
565
|
rejectedInvalidProductId = false;
|
|
566
|
-
|
|
566
|
+
_f.label = 44;
|
|
567
567
|
case 44:
|
|
568
|
-
|
|
568
|
+
_f.trys.push([44, 46, , 47]);
|
|
569
569
|
return [4 /*yield*/, new_trigger({
|
|
570
570
|
title: "Stripe payment failed (invalid productId) ".concat(RUN),
|
|
571
571
|
event: { type: 'Subscription Payment Failed', info: { productIds: ['not-a-mongo-id'] } },
|
|
572
572
|
tags: [tag('f7-invalid')],
|
|
573
573
|
})];
|
|
574
574
|
case 45:
|
|
575
|
-
|
|
575
|
+
_f.sent();
|
|
576
576
|
return [3 /*break*/, 47];
|
|
577
577
|
case 46:
|
|
578
|
-
e_1 =
|
|
578
|
+
e_1 = _f.sent();
|
|
579
579
|
rejectedInvalidProductId = true;
|
|
580
580
|
return [3 /*break*/, 47];
|
|
581
581
|
case 47:
|
|
@@ -640,7 +640,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
640
640
|
// P1: the core pause path — pause_collection goes null -> set on customer.subscription.updated.
|
|
641
641
|
// This is how a pause from the billing portal or dashboard actually arrives; there is no
|
|
642
642
|
// dedicated event for it.
|
|
643
|
-
|
|
643
|
+
_f.sent();
|
|
644
644
|
// P2: the mirror — pause_collection cleared is a resume
|
|
645
645
|
return [4 /*yield*/, run_pause_case({
|
|
646
646
|
label: 'p2-pause-collection-cleared',
|
|
@@ -658,7 +658,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
658
658
|
];
|
|
659
659
|
case 49:
|
|
660
660
|
// P2: the mirror — pause_collection cleared is a resume
|
|
661
|
-
|
|
661
|
+
_f.sent();
|
|
662
662
|
// P3: a pause that is only *modified* (behavior or resumes_at changed) is neither a pause nor a
|
|
663
663
|
// resume — firing here would re-trigger every time a customer adjusts an existing pause
|
|
664
664
|
return [4 /*yield*/, run_pause_case({
|
|
@@ -679,7 +679,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
679
679
|
case 50:
|
|
680
680
|
// P3: a pause that is only *modified* (behavior or resumes_at changed) is neither a pause nor a
|
|
681
681
|
// resume — firing here would re-trigger every time a customer adjusts an existing pause
|
|
682
|
-
|
|
682
|
+
_f.sent();
|
|
683
683
|
// P4: the volume guard. customer.subscription.updated fires on every renewal, price change and
|
|
684
684
|
// cancel_at_period_end toggle; with no pause_collection key in previous_attributes the handler
|
|
685
685
|
// must do nothing (and, in the API, must not even reach the enduser lookup).
|
|
@@ -703,7 +703,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
703
703
|
// P4: the volume guard. customer.subscription.updated fires on every renewal, price change and
|
|
704
704
|
// cancel_at_period_end toggle; with no pause_collection key in previous_attributes the handler
|
|
705
705
|
// must do nothing (and, in the API, must not even reach the enduser lookup).
|
|
706
|
-
|
|
706
|
+
_f.sent();
|
|
707
707
|
// P4b: the idempotency case. previous_attributes carries only what changed, so an unrelated
|
|
708
708
|
// update to an already-paused subscription has no pause_collection key even though
|
|
709
709
|
// pause_collection is currently set. Firing here would re-trigger on every renewal, quantity
|
|
@@ -728,7 +728,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
728
728
|
// pause_collection is currently set. Firing here would re-trigger on every renewal, quantity
|
|
729
729
|
// change and coupon edit for the whole duration of a pause — which is what would happen if the
|
|
730
730
|
// gate were ever "simplified" to read current state instead of the transition.
|
|
731
|
-
|
|
731
|
+
_f.sent();
|
|
732
732
|
// P5/P6: the dedicated events, which Stripe emits for status='paused' transitions only
|
|
733
733
|
return [4 /*yield*/, run_pause_case({
|
|
734
734
|
label: 'p5-dedicated-paused',
|
|
@@ -739,7 +739,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
739
739
|
})];
|
|
740
740
|
case 53:
|
|
741
741
|
// P5/P6: the dedicated events, which Stripe emits for status='paused' transitions only
|
|
742
|
-
|
|
742
|
+
_f.sent();
|
|
743
743
|
return [4 /*yield*/, run_pause_case({
|
|
744
744
|
label: 'p6-dedicated-resumed',
|
|
745
745
|
type: 'Subscription Resumed',
|
|
@@ -750,7 +750,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
750
750
|
// P7: a Paused trigger must not fire on a resume, and vice versa — the two are separate types
|
|
751
751
|
];
|
|
752
752
|
case 54:
|
|
753
|
-
|
|
753
|
+
_f.sent();
|
|
754
754
|
// P7: a Paused trigger must not fire on a resume, and vice versa — the two are separate types
|
|
755
755
|
return [4 /*yield*/, run_pause_case({
|
|
756
756
|
label: 'p7-wrong-direction',
|
|
@@ -765,7 +765,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
765
765
|
];
|
|
766
766
|
case 55:
|
|
767
767
|
// P7: a Paused trigger must not fire on a resume, and vice versa — the two are separate types
|
|
768
|
-
|
|
768
|
+
_f.sent();
|
|
769
769
|
// P8: the dedupe guard — the .updated that accompanies a status='paused' transition must not
|
|
770
770
|
// fire on top of the dedicated event. Stripe isn't expected to send this combination at all;
|
|
771
771
|
// the case pins the guard so a future refactor can't quietly drop it.
|
|
@@ -788,7 +788,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
788
788
|
// P8: the dedupe guard — the .updated that accompanies a status='paused' transition must not
|
|
789
789
|
// fire on top of the dedicated event. Stripe isn't expected to send this combination at all;
|
|
790
790
|
// the case pins the guard so a future refactor can't quietly drop it.
|
|
791
|
-
|
|
791
|
+
_f.sent();
|
|
792
792
|
/* ---- product scoping, over the pause_collection path ---- */
|
|
793
793
|
// P9-P12: the same matrix the payment-failed cases cover, applied to the new triggers
|
|
794
794
|
return [4 /*yield*/, run_pause_case({
|
|
@@ -807,7 +807,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
807
807
|
case 57:
|
|
808
808
|
/* ---- product scoping, over the pause_collection path ---- */
|
|
809
809
|
// P9-P12: the same matrix the payment-failed cases cover, applied to the new triggers
|
|
810
|
-
|
|
810
|
+
_f.sent();
|
|
811
811
|
return [4 /*yield*/, run_pause_case({
|
|
812
812
|
label: 'p10-scoped-nonmatching',
|
|
813
813
|
type: 'Subscription Paused',
|
|
@@ -822,7 +822,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
822
822
|
title: 'Subscription Paused scoped to another product does not fire',
|
|
823
823
|
})];
|
|
824
824
|
case 58:
|
|
825
|
-
|
|
825
|
+
_f.sent();
|
|
826
826
|
return [4 /*yield*/, run_pause_case({
|
|
827
827
|
label: 'p11-empty-list',
|
|
828
828
|
type: 'Subscription Paused',
|
|
@@ -839,7 +839,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
839
839
|
// plan.product and expanded price.product objects both have to resolve, same as the invoice path
|
|
840
840
|
];
|
|
841
841
|
case 59:
|
|
842
|
-
|
|
842
|
+
_f.sent();
|
|
843
843
|
// plan.product and expanded price.product objects both have to resolve, same as the invoice path
|
|
844
844
|
return [4 /*yield*/, run_pause_case({
|
|
845
845
|
label: 'p12-plan-product',
|
|
@@ -856,7 +856,7 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
856
856
|
})];
|
|
857
857
|
case 60:
|
|
858
858
|
// plan.product and expanded price.product objects both have to resolve, same as the invoice path
|
|
859
|
-
|
|
859
|
+
_f.sent();
|
|
860
860
|
return [4 /*yield*/, run_pause_case({
|
|
861
861
|
label: 'p13-expanded-product',
|
|
862
862
|
type: 'Subscription Resumed',
|
|
@@ -872,17 +872,17 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
872
872
|
// P14: same round-trip guarantees as F7, for both new types
|
|
873
873
|
];
|
|
874
874
|
case 61:
|
|
875
|
-
|
|
875
|
+
_f.sent();
|
|
876
876
|
return [4 /*yield*/, new_trigger({
|
|
877
877
|
title: "Stripe subscription paused (validator round-trip) ".concat(RUN),
|
|
878
878
|
event: { type: 'Subscription Paused', info: { productIds: [productA.id] } },
|
|
879
879
|
tags: [tag('p14')],
|
|
880
880
|
})];
|
|
881
881
|
case 62:
|
|
882
|
-
p14Scoped =
|
|
882
|
+
p14Scoped = _f.sent();
|
|
883
883
|
return [4 /*yield*/, sdk.api.automation_triggers.getOne(p14Scoped.id)];
|
|
884
884
|
case 63:
|
|
885
|
-
p14Fetched =
|
|
885
|
+
p14Fetched = _f.sent();
|
|
886
886
|
assert(JSON.stringify((_d = p14Fetched.event.info) === null || _d === void 0 ? void 0 : _d.productIds) === JSON.stringify([productA.id]), "expected productIds to round-trip, got ".concat(JSON.stringify(p14Fetched.event)), 'Subscription Paused productIds round-trips through the validator');
|
|
887
887
|
return [4 /*yield*/, new_trigger({
|
|
888
888
|
title: "Stripe subscription resumed (no info) ".concat(RUN),
|
|
@@ -890,41 +890,304 @@ export var stripe_webhook_triggers_tests = function (_a) {
|
|
|
890
890
|
tags: [tag('p14-no-info')],
|
|
891
891
|
})];
|
|
892
892
|
case 64:
|
|
893
|
-
|
|
893
|
+
_f.sent();
|
|
894
894
|
assert(true, '', 'Subscription Resumed with omitted info accepted');
|
|
895
895
|
rejectedInvalidPausedProductId = false;
|
|
896
|
-
|
|
896
|
+
_f.label = 65;
|
|
897
897
|
case 65:
|
|
898
|
-
|
|
898
|
+
_f.trys.push([65, 67, , 68]);
|
|
899
899
|
return [4 /*yield*/, new_trigger({
|
|
900
900
|
title: "Stripe subscription paused (invalid productId) ".concat(RUN),
|
|
901
901
|
event: { type: 'Subscription Paused', info: { productIds: ['not-a-mongo-id'] } },
|
|
902
902
|
tags: [tag('p14-invalid')],
|
|
903
903
|
})];
|
|
904
904
|
case 66:
|
|
905
|
-
|
|
905
|
+
_f.sent();
|
|
906
906
|
return [3 /*break*/, 68];
|
|
907
907
|
case 67:
|
|
908
|
-
e_2 =
|
|
908
|
+
e_2 = _f.sent();
|
|
909
909
|
rejectedInvalidPausedProductId = true;
|
|
910
910
|
return [3 /*break*/, 68];
|
|
911
911
|
case 68:
|
|
912
912
|
assert(rejectedInvalidPausedProductId, 'expected a non-ObjectId productId to be rejected', 'invalid Subscription Paused productId rejected');
|
|
913
|
+
poll_for_purchase = function (enduserId, iterations) {
|
|
914
|
+
if (iterations === void 0) { iterations = 20; }
|
|
915
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
916
|
+
var i, purchases;
|
|
917
|
+
return __generator(this, function (_a) {
|
|
918
|
+
switch (_a.label) {
|
|
919
|
+
case 0:
|
|
920
|
+
i = 0;
|
|
921
|
+
_a.label = 1;
|
|
922
|
+
case 1:
|
|
923
|
+
if (!(i < iterations)) return [3 /*break*/, 5];
|
|
924
|
+
return [4 /*yield*/, wait(undefined, 500)];
|
|
925
|
+
case 2:
|
|
926
|
+
_a.sent();
|
|
927
|
+
return [4 /*yield*/, sdk.api.purchases.getSome({ filter: { enduserId: enduserId } })];
|
|
928
|
+
case 3:
|
|
929
|
+
purchases = _a.sent();
|
|
930
|
+
if (purchases.length)
|
|
931
|
+
return [2 /*return*/, purchases];
|
|
932
|
+
_a.label = 4;
|
|
933
|
+
case 4:
|
|
934
|
+
i++;
|
|
935
|
+
return [3 /*break*/, 1];
|
|
936
|
+
case 5: return [2 /*return*/, []];
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
run_coupon_invoice_case = function (_a) {
|
|
942
|
+
var label = _a.label, couponCodes = _a.couponCodes, discounts = _a.discounts, discount = _a.discount, shouldFire = _a.shouldFire, title = _a.title;
|
|
943
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
944
|
+
var caseTag, enduser, res;
|
|
945
|
+
return __generator(this, function (_b) {
|
|
946
|
+
switch (_b.label) {
|
|
947
|
+
case 0:
|
|
948
|
+
caseTag = tag(label);
|
|
949
|
+
return [4 /*yield*/, new_enduser(label)];
|
|
950
|
+
case 1:
|
|
951
|
+
enduser = _b.sent();
|
|
952
|
+
return [4 /*yield*/, new_trigger({
|
|
953
|
+
title: "Stripe purchase made (".concat(label, ") ").concat(RUN),
|
|
954
|
+
event: { type: 'Purchase Made', info: couponCodes !== undefined ? { couponCodes: couponCodes } : {} },
|
|
955
|
+
tags: [caseTag],
|
|
956
|
+
})];
|
|
957
|
+
case 2:
|
|
958
|
+
_b.sent();
|
|
959
|
+
return [4 /*yield*/, post_stripe_webhook({
|
|
960
|
+
stripePublicKey: stripePublicKey,
|
|
961
|
+
secret: webhooksSecret,
|
|
962
|
+
event: invoice_paid_event({
|
|
963
|
+
stripeCustomerId: enduser.stripeCustomerId,
|
|
964
|
+
lines: [invoice_paid_line({ description: "Coupon Test ".concat(label, " ").concat(RUN) })],
|
|
965
|
+
discounts: discounts,
|
|
966
|
+
discount: discount,
|
|
967
|
+
}),
|
|
968
|
+
})];
|
|
969
|
+
case 3:
|
|
970
|
+
res = _b.sent();
|
|
971
|
+
assert(res.status === 200, "expected 200, got ".concat(res.status, " (").concat(res.data, ")"), "".concat(label, " webhook accepted"));
|
|
972
|
+
if (!shouldFire) return [3 /*break*/, 5];
|
|
973
|
+
return [4 /*yield*/, expect_fired(enduser.id, caseTag, title)];
|
|
974
|
+
case 4:
|
|
975
|
+
_b.sent();
|
|
976
|
+
return [3 /*break*/, 7];
|
|
977
|
+
case 5: return [4 /*yield*/, expect_not_fired(enduser.id, caseTag, title)];
|
|
978
|
+
case 6:
|
|
979
|
+
_b.sent();
|
|
980
|
+
_b.label = 7;
|
|
981
|
+
case 7: return [2 /*return*/, enduser];
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
});
|
|
985
|
+
};
|
|
986
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
987
|
+
label: 'c1-matching-promo',
|
|
988
|
+
couponCodes: ['SUMMER20'],
|
|
989
|
+
discounts: [discount_with_promo_code('SUMMER20')],
|
|
990
|
+
shouldFire: true,
|
|
991
|
+
title: 'coupon-scoped Purchase Made trigger fires for a matching promo code',
|
|
992
|
+
})];
|
|
993
|
+
case 69:
|
|
994
|
+
c1Enduser = _f.sent();
|
|
995
|
+
return [4 /*yield*/, poll_for_purchase(c1Enduser.id)];
|
|
996
|
+
case 70:
|
|
997
|
+
c1Purchases = _f.sent();
|
|
998
|
+
assert(c1Purchases.some(function (p) { var _a; return (_a = p.couponCodes) === null || _a === void 0 ? void 0 : _a.includes('SUMMER20'); }), "expected a purchase with couponCodes containing SUMMER20, got ".concat(JSON.stringify(c1Purchases.map(function (p) { return p.couponCodes; }))), 'couponCodes persisted on the webhook-created purchase');
|
|
999
|
+
c1bDiscount = discount_with_promo_code_ref({ couponId: "coupon_test_c1b_".concat(RUN), couponName: 'Test coupon' });
|
|
1000
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1001
|
+
label: 'c1b-real-shape',
|
|
1002
|
+
couponCodes: ['Test coupon'],
|
|
1003
|
+
discount: c1bDiscount,
|
|
1004
|
+
discounts: [c1bDiscount.id],
|
|
1005
|
+
shouldFire: true,
|
|
1006
|
+
title: 'real-shaped invoice.paid payload matches via coupon name',
|
|
1007
|
+
})];
|
|
1008
|
+
case 71:
|
|
1009
|
+
c1bEnduser = _f.sent();
|
|
1010
|
+
return [4 /*yield*/, poll_for_purchase(c1bEnduser.id)];
|
|
1011
|
+
case 72:
|
|
1012
|
+
c1bPurchases = _f.sent();
|
|
1013
|
+
assert(c1bPurchases.some(function (p) { var _a, _b; return ((_a = p.couponCodes) === null || _a === void 0 ? void 0 : _a.includes('Test coupon')) && ((_b = p.couponCodes) === null || _b === void 0 ? void 0 : _b.includes("coupon_test_c1b_".concat(RUN))); }), "expected couponCodes with the coupon name and id, got ".concat(JSON.stringify(c1bPurchases.map(function (p) { return p.couponCodes; }))), 'coupon name and id persisted from a real-shaped payload');
|
|
1014
|
+
// C2: matching is case-sensitive — Stripe sends the canonical merchant-defined code, so a
|
|
1015
|
+
// differently-cased trigger value must stay quiet (staff can list multiple variants if needed)
|
|
1016
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1017
|
+
label: 'c2-case-mismatch',
|
|
1018
|
+
couponCodes: ['summer20'],
|
|
1019
|
+
discounts: [discount_with_promo_code('SUMMER20')],
|
|
1020
|
+
shouldFire: false,
|
|
1021
|
+
title: 'coupon match is case-sensitive: a differently-cased code does not fire',
|
|
1022
|
+
})
|
|
1023
|
+
// C3: a different code stays quiet
|
|
1024
|
+
];
|
|
1025
|
+
case 73:
|
|
1026
|
+
// C2: matching is case-sensitive — Stripe sends the canonical merchant-defined code, so a
|
|
1027
|
+
// differently-cased trigger value must stay quiet (staff can list multiple variants if needed)
|
|
1028
|
+
_f.sent();
|
|
1029
|
+
// C3: a different code stays quiet
|
|
1030
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1031
|
+
label: 'c3-nonmatching',
|
|
1032
|
+
couponCodes: ['SUMMER20'],
|
|
1033
|
+
discounts: [discount_with_promo_code('WINTER10')],
|
|
1034
|
+
shouldFire: false,
|
|
1035
|
+
title: 'coupon-scoped trigger does not fire for a different code',
|
|
1036
|
+
})
|
|
1037
|
+
// C4: an undiscounted invoice never matches a coupon-scoped trigger
|
|
1038
|
+
];
|
|
1039
|
+
case 74:
|
|
1040
|
+
// C3: a different code stays quiet
|
|
1041
|
+
_f.sent();
|
|
1042
|
+
// C4: an undiscounted invoice never matches a coupon-scoped trigger
|
|
1043
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1044
|
+
label: 'c4-no-discounts',
|
|
1045
|
+
couponCodes: ['SUMMER20'],
|
|
1046
|
+
shouldFire: false,
|
|
1047
|
+
title: 'an invoice with no discounts does not fire a coupon-scoped trigger',
|
|
1048
|
+
})
|
|
1049
|
+
// C5: admin-applied coupons carry a name but no promotion code, and must still match. Built
|
|
1050
|
+
// once and referenced by id from `discounts`, mirroring the real single-discount payload shape.
|
|
1051
|
+
];
|
|
1052
|
+
case 75:
|
|
1053
|
+
// C4: an undiscounted invoice never matches a coupon-scoped trigger
|
|
1054
|
+
_f.sent();
|
|
1055
|
+
c5Discount = discount_with_coupon('Spring Promo');
|
|
1056
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1057
|
+
label: 'c5-coupon-name',
|
|
1058
|
+
couponCodes: ['Spring Promo'],
|
|
1059
|
+
discount: c5Discount,
|
|
1060
|
+
discounts: [c5Discount.id],
|
|
1061
|
+
shouldFire: true,
|
|
1062
|
+
title: 'coupon-scoped trigger matches via coupon name (no promotion code)',
|
|
1063
|
+
})
|
|
1064
|
+
// C6: backward compat — an unscoped Purchase Made trigger fires for discounted and
|
|
1065
|
+
// undiscounted invoices alike
|
|
1066
|
+
];
|
|
1067
|
+
case 76:
|
|
1068
|
+
_f.sent();
|
|
1069
|
+
// C6: backward compat — an unscoped Purchase Made trigger fires for discounted and
|
|
1070
|
+
// undiscounted invoices alike
|
|
1071
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1072
|
+
label: 'c6-unscoped-discounted',
|
|
1073
|
+
discounts: [discount_with_promo_code('SUMMER20')],
|
|
1074
|
+
shouldFire: true,
|
|
1075
|
+
title: 'unscoped Purchase Made trigger fires for a discounted invoice',
|
|
1076
|
+
})];
|
|
1077
|
+
case 77:
|
|
1078
|
+
// C6: backward compat — an unscoped Purchase Made trigger fires for discounted and
|
|
1079
|
+
// undiscounted invoices alike
|
|
1080
|
+
_f.sent();
|
|
1081
|
+
return [4 /*yield*/, run_coupon_invoice_case({
|
|
1082
|
+
label: 'c6b-unscoped-undiscounted',
|
|
1083
|
+
shouldFire: true,
|
|
1084
|
+
title: 'unscoped Purchase Made trigger fires for an undiscounted invoice',
|
|
1085
|
+
})
|
|
1086
|
+
// C7: charge.succeeded with payment_intent null — the coupon lookup is skipped entirely, so
|
|
1087
|
+
// the purchase is created, the unscoped trigger fires, and the coupon-scoped one does not
|
|
1088
|
+
];
|
|
1089
|
+
case 78:
|
|
1090
|
+
_f.sent();
|
|
1091
|
+
C7_TAG = tag('c7-charge-unscoped');
|
|
1092
|
+
C7_SCOPED_TAG = tag('c7-charge-coupon-scoped');
|
|
1093
|
+
return [4 /*yield*/, new_enduser('c7')];
|
|
1094
|
+
case 79:
|
|
1095
|
+
c7Enduser = _f.sent();
|
|
1096
|
+
return [4 /*yield*/, new_trigger({
|
|
1097
|
+
title: "Stripe purchase made (c7 unscoped) ".concat(RUN),
|
|
1098
|
+
event: { type: 'Purchase Made', info: {} },
|
|
1099
|
+
tags: [C7_TAG],
|
|
1100
|
+
})];
|
|
1101
|
+
case 80:
|
|
1102
|
+
_f.sent();
|
|
1103
|
+
return [4 /*yield*/, new_trigger({
|
|
1104
|
+
title: "Stripe purchase made (c7 coupon-scoped) ".concat(RUN),
|
|
1105
|
+
event: { type: 'Purchase Made', info: { couponCodes: ['SUMMER20'] } },
|
|
1106
|
+
tags: [C7_SCOPED_TAG],
|
|
1107
|
+
})];
|
|
1108
|
+
case 81:
|
|
1109
|
+
_f.sent();
|
|
1110
|
+
return [4 /*yield*/, post_stripe_webhook({
|
|
1111
|
+
stripePublicKey: stripePublicKey,
|
|
1112
|
+
secret: webhooksSecret,
|
|
1113
|
+
event: charge_succeeded_event({
|
|
1114
|
+
customer: {
|
|
1115
|
+
id: c7Enduser.stripeCustomerId,
|
|
1116
|
+
email: "stripe-webhook-c7-".concat(RUN, "@tellescope.com"),
|
|
1117
|
+
name: 'Stripe Webhook c7',
|
|
1118
|
+
},
|
|
1119
|
+
}),
|
|
1120
|
+
})];
|
|
1121
|
+
case 82:
|
|
1122
|
+
c7Res = _f.sent();
|
|
1123
|
+
assert(c7Res.status === 200, "expected 200, got ".concat(c7Res.status, " (").concat(c7Res.data, ")"), 'charge.succeeded webhook accepted');
|
|
1124
|
+
return [4 /*yield*/, expect_fired(c7Enduser.id, C7_TAG, 'unscoped Purchase Made trigger fires for charge.succeeded')];
|
|
1125
|
+
case 83:
|
|
1126
|
+
_f.sent();
|
|
1127
|
+
return [4 /*yield*/, expect_not_fired(c7Enduser.id, C7_SCOPED_TAG, 'coupon-scoped trigger does not fire for a charge with no coupon data')];
|
|
1128
|
+
case 84:
|
|
1129
|
+
_f.sent();
|
|
1130
|
+
return [4 /*yield*/, poll_for_purchase(c7Enduser.id)];
|
|
1131
|
+
case 85:
|
|
1132
|
+
c7Purchases = _f.sent();
|
|
1133
|
+
assert(c7Purchases.length > 0, 'expected charge.succeeded to create a purchase', 'charge.succeeded purchase created');
|
|
1134
|
+
C8_TAG = tag('c8-charge-failed-lookup');
|
|
1135
|
+
return [4 /*yield*/, new_enduser('c8')];
|
|
1136
|
+
case 86:
|
|
1137
|
+
c8Enduser = _f.sent();
|
|
1138
|
+
return [4 /*yield*/, new_trigger({
|
|
1139
|
+
title: "Stripe purchase made (c8 failed session lookup) ".concat(RUN),
|
|
1140
|
+
event: { type: 'Purchase Made', info: {} },
|
|
1141
|
+
tags: [C8_TAG],
|
|
1142
|
+
})];
|
|
1143
|
+
case 87:
|
|
1144
|
+
_f.sent();
|
|
1145
|
+
return [4 /*yield*/, post_stripe_webhook({
|
|
1146
|
+
stripePublicKey: stripePublicKey,
|
|
1147
|
+
secret: webhooksSecret,
|
|
1148
|
+
event: charge_succeeded_event({
|
|
1149
|
+
customer: {
|
|
1150
|
+
id: c8Enduser.stripeCustomerId,
|
|
1151
|
+
email: "stripe-webhook-c8-".concat(RUN, "@tellescope.com"),
|
|
1152
|
+
name: 'Stripe Webhook c8',
|
|
1153
|
+
},
|
|
1154
|
+
payment_intent: "pi_test_".concat(RUN),
|
|
1155
|
+
}),
|
|
1156
|
+
})];
|
|
1157
|
+
case 88:
|
|
1158
|
+
c8Res = _f.sent();
|
|
1159
|
+
assert(c8Res.status === 200, "expected 200, got ".concat(c8Res.status, " (").concat(c8Res.data, ")"), 'charge.succeeded with failing session lookup still accepted');
|
|
1160
|
+
return [4 /*yield*/, expect_fired(c8Enduser.id, C8_TAG, 'a failing checkout-session lookup does not block the purchase or its triggers')
|
|
1161
|
+
// C9: couponCodes must round-trip on the trigger's event.info
|
|
1162
|
+
];
|
|
1163
|
+
case 89:
|
|
1164
|
+
_f.sent();
|
|
1165
|
+
return [4 /*yield*/, new_trigger({
|
|
1166
|
+
title: "Stripe purchase made (validator round-trip) ".concat(RUN),
|
|
1167
|
+
event: { type: 'Purchase Made', info: { couponCodes: ['SUMMER20'] } },
|
|
1168
|
+
tags: [tag('c9')],
|
|
1169
|
+
})];
|
|
1170
|
+
case 90:
|
|
1171
|
+
c9Trigger = _f.sent();
|
|
1172
|
+
return [4 /*yield*/, sdk.api.automation_triggers.getOne(c9Trigger.id)];
|
|
1173
|
+
case 91:
|
|
1174
|
+
c9Fetched = _f.sent();
|
|
1175
|
+
assert(JSON.stringify((_e = c9Fetched.event.info) === null || _e === void 0 ? void 0 : _e.couponCodes) === JSON.stringify(['SUMMER20']), "expected couponCodes to round-trip, got ".concat(JSON.stringify(c9Fetched.event)), 'couponCodes round-trips through the validator');
|
|
913
1176
|
console.log("All Stripe webhook trigger tests passed!");
|
|
914
|
-
return [3 /*break*/,
|
|
915
|
-
case
|
|
1177
|
+
return [3 /*break*/, 95];
|
|
1178
|
+
case 92:
|
|
916
1179
|
// Best-effort only: the harness exits the process on the first failed assertion, which skips
|
|
917
1180
|
// this block. setup_stripe_test_integration clears integration residue on the next run.
|
|
918
1181
|
return [4 /*yield*/, cleanup().catch(console.error)];
|
|
919
|
-
case
|
|
1182
|
+
case 93:
|
|
920
1183
|
// Best-effort only: the harness exits the process on the first failed assertion, which skips
|
|
921
1184
|
// this block. setup_stripe_test_integration clears integration residue on the next run.
|
|
922
|
-
|
|
1185
|
+
_f.sent();
|
|
923
1186
|
return [4 /*yield*/, Promise.all(__spreadArray(__spreadArray(__spreadArray([], createdTriggerIds.map(function (id) { return sdk.api.automation_triggers.deleteOne(id).catch(console.error); }), true), createdProductIds.map(function (id) { return sdk.api.products.deleteOne(id).catch(console.error); }), true), createdEnduserIds.map(function (id) { return sdk.api.endusers.deleteOne(id).catch(console.error); }), true))];
|
|
924
|
-
case
|
|
925
|
-
|
|
1187
|
+
case 94:
|
|
1188
|
+
_f.sent();
|
|
926
1189
|
return [7 /*endfinally*/];
|
|
927
|
-
case
|
|
1190
|
+
case 95: return [2 /*return*/];
|
|
928
1191
|
}
|
|
929
1192
|
});
|
|
930
1193
|
});
|