backend-manager 5.9.7 → 5.9.9

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.
Files changed (216) hide show
  1. package/package.json +5 -3
  2. package/src/cli/commands/setup-tests/bem-config.js +3 -2
  3. package/src/cli/commands/setup-tests/helpers.js +5 -0
  4. package/src/cli/commands/setup-tests/project-id-consistency.js +2 -1
  5. package/src/test/fixtures/firebase-project/.temp/test-mode.json +1 -1
  6. package/src/test/fixtures/firebase-project/database-debug.log +8 -8
  7. package/src/test/fixtures/firebase-project/firestore-debug.log +57 -55
  8. package/src/test/fixtures/firebase-project/pubsub-debug.log +3 -3
  9. package/templates/_.env +42 -0
  10. package/templates/_.gitignore +60 -0
  11. package/templates/backend-manager-config.json +249 -0
  12. package/templates/database.rules.json +83 -0
  13. package/templates/firebase.json +66 -0
  14. package/templates/firestore.indexes.json +4 -0
  15. package/templates/firestore.rules +112 -0
  16. package/templates/public/404.html +26 -0
  17. package/templates/public/index.html +24 -0
  18. package/templates/remoteconfig.template.json +1 -0
  19. package/templates/storage-lifecycle-config-1-day.json +9 -0
  20. package/templates/storage-lifecycle-config-30-days.json +9 -0
  21. package/templates/storage.rules +8 -0
  22. package/test/_init/accounts-validation.js +58 -0
  23. package/test/_legacy/ai/index.js +231 -0
  24. package/test/_legacy/ai/test.jpg +0 -0
  25. package/test/_legacy/ai/test.pdf +0 -0
  26. package/test/_legacy/index.js +31 -0
  27. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  28. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +98 -0
  29. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +578 -0
  30. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +38 -0
  31. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +135 -0
  32. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +42 -0
  33. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +44 -0
  34. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +39 -0
  35. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +143 -0
  36. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +48 -0
  37. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +204 -0
  38. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +204 -0
  39. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +125 -0
  40. package/test/_legacy/payment-resolver/index.js +1558 -0
  41. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  42. package/test/_legacy/payment-resolver/paypal/orders/regular.json +120 -0
  43. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +323 -0
  44. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +192 -0
  45. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +125 -0
  46. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +76 -0
  47. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +114 -0
  48. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +114 -0
  49. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +111 -0
  50. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +132 -0
  51. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +107 -0
  52. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +91 -0
  53. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +147 -0
  54. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +120 -0
  55. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  56. package/test/_legacy/payment-resolver/stripe/orders/regular.json +91 -0
  57. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +421 -0
  58. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +349 -0
  59. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +430 -0
  60. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +319 -0
  61. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +319 -0
  62. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +414 -0
  63. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +319 -0
  64. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +339 -0
  65. package/test/_legacy/test-new +1178 -0
  66. package/test/_legacy/test.md +89 -0
  67. package/test/_legacy/usage.js +175 -0
  68. package/test/_legacy/user.js +31 -0
  69. package/test/ai/tools-live.js +170 -0
  70. package/test/boot/emulator-boots.js +37 -0
  71. package/test/content/blog-generate.js +160 -0
  72. package/test/email/campaign-send.js +45 -0
  73. package/test/email/consent-lifecycle.js +257 -0
  74. package/test/email/feedback-and-plain-send.js +52 -0
  75. package/test/email/fixtures/clean.json +30 -0
  76. package/test/email/fixtures/editorial.json +30 -0
  77. package/test/email/fixtures/field-report.json +53 -0
  78. package/test/email/marketing-lifecycle.js +132 -0
  79. package/test/email/newsletter-generate.js +819 -0
  80. package/test/email/newsletter-templates.js +491 -0
  81. package/test/email/templates.js +207 -0
  82. package/test/email/transactional-send.js +34 -0
  83. package/test/email/transactional.js +560 -0
  84. package/test/email/validation.js +710 -0
  85. package/test/events/auth-delete-race.js +201 -0
  86. package/test/events/payments/journey-payments-cancel-endpoint.js +100 -0
  87. package/test/events/payments/journey-payments-cancel.js +182 -0
  88. package/test/events/payments/journey-payments-discount.js +89 -0
  89. package/test/events/payments/journey-payments-failure.js +146 -0
  90. package/test/events/payments/journey-payments-legacy-product.js +149 -0
  91. package/test/events/payments/journey-payments-one-time-failure.js +111 -0
  92. package/test/events/payments/journey-payments-one-time.js +136 -0
  93. package/test/events/payments/journey-payments-plan-change.js +144 -0
  94. package/test/events/payments/journey-payments-refund-webhook.js +180 -0
  95. package/test/events/payments/journey-payments-suspend.js +181 -0
  96. package/test/events/payments/journey-payments-trial-cancel.js +130 -0
  97. package/test/events/payments/journey-payments-trial.js +171 -0
  98. package/test/events/payments/journey-payments-uid-resolution.js +132 -0
  99. package/test/events/payments/journey-payments-upgrade.js +135 -0
  100. package/test/fixtures/chargebee/invoice-one-time.json +27 -0
  101. package/test/fixtures/chargebee/subscription-active.json +44 -0
  102. package/test/fixtures/chargebee/subscription-cancelled.json +42 -0
  103. package/test/fixtures/chargebee/subscription-in-trial.json +41 -0
  104. package/test/fixtures/chargebee/subscription-legacy-plan.json +41 -0
  105. package/test/fixtures/chargebee/subscription-non-renewing.json +41 -0
  106. package/test/fixtures/chargebee/subscription-paused.json +42 -0
  107. package/test/fixtures/chargebee/webhook-payment-failed.json +51 -0
  108. package/test/fixtures/chargebee/webhook-subscription-created.json +47 -0
  109. package/test/fixtures/paypal/order-approved.json +62 -0
  110. package/test/fixtures/paypal/order-completed.json +110 -0
  111. package/test/fixtures/paypal/subscription-active.json +76 -0
  112. package/test/fixtures/paypal/subscription-cancelled.json +50 -0
  113. package/test/fixtures/paypal/subscription-suspended.json +65 -0
  114. package/test/fixtures/stripe/checkout-session-completed.json +130 -0
  115. package/test/fixtures/stripe/invoice-payment-failed.json +148 -0
  116. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +28 -0
  117. package/test/fixtures/stripe/subscription-active.json +161 -0
  118. package/test/fixtures/stripe/subscription-canceled.json +161 -0
  119. package/test/fixtures/stripe/subscription-trialing.json +161 -0
  120. package/test/functions/admin/database-read.js +134 -0
  121. package/test/functions/admin/database-write.js +159 -0
  122. package/test/functions/admin/edit-post.js +366 -0
  123. package/test/functions/admin/firestore-query.js +207 -0
  124. package/test/functions/admin/firestore-read.js +129 -0
  125. package/test/functions/admin/firestore-write.js +105 -0
  126. package/test/functions/admin/get-stats.js +115 -0
  127. package/test/functions/admin/send-email.js +119 -0
  128. package/test/functions/admin/send-notification.js +208 -0
  129. package/test/functions/admin/write-repo-content.js +223 -0
  130. package/test/functions/general/add-marketing-contact.js +335 -0
  131. package/test/functions/general/fetch-post.js +54 -0
  132. package/test/functions/general/generate-uuid.js +114 -0
  133. package/test/functions/test/authenticate.js +64 -0
  134. package/test/functions/user/create-custom-token.js +73 -0
  135. package/test/functions/user/delete.js +135 -0
  136. package/test/functions/user/get-active-sessions.js +111 -0
  137. package/test/functions/user/get-subscription-info.js +99 -0
  138. package/test/functions/user/regenerate-api-keys.js +156 -0
  139. package/test/functions/user/resolve.js +52 -0
  140. package/test/functions/user/sign-out-all-sessions.js +94 -0
  141. package/test/functions/user/sign-up.js +252 -0
  142. package/test/functions/user/submit-feedback.js +104 -0
  143. package/test/functions/user/validate-settings.js +82 -0
  144. package/test/helpers/ai-request-payload.js +300 -0
  145. package/test/helpers/ai-test-provider.js +202 -0
  146. package/test/helpers/ai-tools-format.js +383 -0
  147. package/test/helpers/content/blog-auto-publisher.js +484 -0
  148. package/test/helpers/content/feed-parser.js +528 -0
  149. package/test/helpers/content/ghostii-blocks.js +134 -0
  150. package/test/helpers/content/ghostii-feed-integration.js +404 -0
  151. package/test/helpers/content/ghostii-write-article.js +243 -0
  152. package/test/helpers/environment.js +230 -0
  153. package/test/helpers/infer-contact.js +113 -0
  154. package/test/helpers/merge-line-files.js +271 -0
  155. package/test/helpers/payment/chargebee/parse-webhook.js +413 -0
  156. package/test/helpers/payment/chargebee/to-unified-one-time.js +147 -0
  157. package/test/helpers/payment/chargebee/to-unified-subscription.js +648 -0
  158. package/test/helpers/payment/paypal/parse-webhook.js +539 -0
  159. package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
  160. package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
  161. package/test/helpers/payment/stripe/parse-webhook.js +447 -0
  162. package/test/helpers/payment/stripe/to-unified-one-time.js +306 -0
  163. package/test/helpers/payment/stripe/to-unified-subscription.js +708 -0
  164. package/test/helpers/sanitize.js +222 -0
  165. package/test/helpers/slugify.js +394 -0
  166. package/test/helpers/storage.js +194 -0
  167. package/test/helpers/user.js +755 -0
  168. package/test/helpers/webhook-forward.js +418 -0
  169. package/test/mcp/discovery.js +53 -0
  170. package/test/mcp/oauth.js +161 -0
  171. package/test/mcp/protocol.js +268 -0
  172. package/test/mcp/roles.js +188 -0
  173. package/test/mcp/utils.js +245 -0
  174. package/test/routes/admin/create-post.js +364 -0
  175. package/test/routes/admin/database.js +131 -0
  176. package/test/routes/admin/deduplicate-image-alts.js +190 -0
  177. package/test/routes/admin/email.js +114 -0
  178. package/test/routes/admin/firestore-query.js +204 -0
  179. package/test/routes/admin/firestore.js +127 -0
  180. package/test/routes/admin/infer-contact.js +218 -0
  181. package/test/routes/admin/notification.js +198 -0
  182. package/test/routes/admin/post-resize-image.js +184 -0
  183. package/test/routes/admin/post.js +368 -0
  184. package/test/routes/admin/repo-content.js +223 -0
  185. package/test/routes/admin/stats.js +112 -0
  186. package/test/routes/content/post.js +54 -0
  187. package/test/routes/general/uuid.js +115 -0
  188. package/test/routes/marketing/campaign.js +125 -0
  189. package/test/routes/marketing/contact.js +370 -0
  190. package/test/routes/marketing/email-preferences.js +292 -0
  191. package/test/routes/marketing/push-send.js +32 -0
  192. package/test/routes/marketing/webhook-forward.js +61 -0
  193. package/test/routes/marketing/webhook.js +639 -0
  194. package/test/routes/payments/cancel.js +163 -0
  195. package/test/routes/payments/discount.js +80 -0
  196. package/test/routes/payments/dispute-alert.js +320 -0
  197. package/test/routes/payments/intent.js +336 -0
  198. package/test/routes/payments/portal.js +92 -0
  199. package/test/routes/payments/refund.js +179 -0
  200. package/test/routes/payments/trial-eligibility.js +71 -0
  201. package/test/routes/payments/webhook.js +107 -0
  202. package/test/routes/test/authenticate.js +59 -0
  203. package/test/routes/test/schema.js +554 -0
  204. package/test/routes/test/usage.js +342 -0
  205. package/test/routes/user/api-keys.js +156 -0
  206. package/test/routes/user/delete.js +136 -0
  207. package/test/routes/user/feedback.js +104 -0
  208. package/test/routes/user/sessions.js +199 -0
  209. package/test/routes/user/settings-validate.js +82 -0
  210. package/test/routes/user/signup.js +542 -0
  211. package/test/routes/user/subscription.js +99 -0
  212. package/test/routes/user/token.js +73 -0
  213. package/test/routes/user/user.js +157 -0
  214. package/test/rules/notifications.js +410 -0
  215. package/test/rules/payments-carts.js +371 -0
  216. package/test/rules/user.js +396 -0
@@ -0,0 +1,1178 @@
1
+ const package = require('../package.json');
2
+ const assert = require('assert');
3
+
4
+ beforeEach(() => {
5
+ });
6
+
7
+ before(() => {
8
+ });
9
+
10
+ after(() => {
11
+ });
12
+
13
+ /*
14
+ * ============
15
+ * Test Cases
16
+ * ============
17
+ */
18
+ describe(`${package.name}`, () => {
19
+ const Manager = (new (require('../src/manager/index.js')));
20
+
21
+ const options = {
22
+ resolveProcessor: true,
23
+ resolveType: true,
24
+
25
+ today: '2023-04-28T00:00:00.000Z',
26
+ // today: '2023-08-28T00:00:00.000Z',
27
+
28
+ // log: true,
29
+ }
30
+
31
+ const defaultProfileOrder = {
32
+ type: 'order',
33
+ details: {
34
+ }
35
+ }
36
+
37
+ const defaultProfileSubscription = {
38
+ type: 'subscription',
39
+ details: {
40
+ planFrequency: 'monthly',
41
+ }
42
+ }
43
+
44
+ function log() {
45
+ // console.log(...arguments);
46
+ }
47
+
48
+ describe('.dependencies()', () => {
49
+ Object.keys(package.dependencies).forEach((dependency) => {
50
+ it(`should load ${dependency}`, () => {
51
+ try {
52
+ const dep = require(dependency);
53
+ assert.ok(dep);
54
+ } catch (e) {
55
+ assert.fail(`Failed to load ${dependency}: ${e.message}`);
56
+ }
57
+ });
58
+ });
59
+ });
60
+
61
+ describe('.subscriptionResolver()', () => {
62
+
63
+ /*
64
+ GENERIC
65
+ */
66
+ // describe('error test', () => {
67
+ // const result = Manager.SubscriptionResolver({}, new Error('Test')).resolve(options);
68
+
69
+ // console.log('result', result);
70
+
71
+ // it('should resolve correctly', () => {
72
+ // return assert.deepStrictEqual(result, expected);
73
+ // });
74
+ // });
75
+
76
+ /*
77
+ * PAYPAL
78
+ */
79
+ describe('paypal', () => {
80
+ // Orders
81
+ describe('orders', () => {
82
+ describe('regular', () => {
83
+ const item = require('./payment-resolver/paypal/orders/regular.json');
84
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
85
+ const expected = {
86
+ processor: 'paypal',
87
+ type: 'order',
88
+ status: 'cancelled',
89
+ frequency: 'single',
90
+ resource: { id: '5CA68427PY850452F' },
91
+ payment: {
92
+ completed: true,
93
+ refunded: false,
94
+ },
95
+ start: { timestamp: '2023-04-27T03:39:50.000Z', timestampUNIX: 1682566790 },
96
+ expires: { timestamp: '2023-04-27T03:39:50.000Z', timestampUNIX: 1682566790 },
97
+ cancelled: { timestamp: '2023-04-27T03:39:50.000Z', timestampUNIX: 1682566790 },
98
+ lastPayment: {
99
+ amount: 1,
100
+ date: { timestamp: '2023-04-27T03:40:38.000Z', timestampUNIX: 1682566838 }
101
+ },
102
+ trial: {
103
+ active: false,
104
+ claimed: false,
105
+ daysLeft: 0,
106
+ },
107
+ }
108
+
109
+ log('result', result);
110
+
111
+ it('should resolve correctly', () => {
112
+ return assert.deepStrictEqual(result, expected);
113
+ });
114
+ });
115
+ });
116
+
117
+ // Subscriptions
118
+ describe('subscriptions', () => {
119
+ describe('active', () => {
120
+ const item = require('./payment-resolver/paypal/subscriptions/active.json');
121
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
122
+ const expected = {
123
+ processor: 'paypal',
124
+ type: 'subscription',
125
+ status: 'active',
126
+ frequency: 'monthly',
127
+ resource: { id: 'I-GLYNACJCERDD' },
128
+ payment: {
129
+ completed: true,
130
+ refunded: false,
131
+ },
132
+ start: { timestamp: '2023-03-22T22:38:03.000Z', timestampUNIX: 1679524683 },
133
+ expires: { timestamp: '2024-09-21T11:03:15.000Z', timestampUNIX: 1726916595 },
134
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
135
+ lastPayment: {
136
+ amount: 59.85,
137
+ date: { timestamp: '2023-08-22T11:03:15.000Z', timestampUNIX: 1692702195 }
138
+ },
139
+ trial: {
140
+ active: false,
141
+ claimed: false,
142
+ daysLeft: 0,
143
+ },
144
+ }
145
+
146
+ log('result', result);
147
+
148
+ it('should resolve correctly', () => {
149
+ return assert.deepStrictEqual(result, expected);
150
+ });
151
+ });
152
+
153
+ describe('trial => in-trial', () => {
154
+ const item = require('./payment-resolver/paypal/subscriptions/trial-in-trial.json');
155
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
156
+ const expected = {
157
+ processor: 'paypal',
158
+ type: 'subscription',
159
+ status: 'active',
160
+ frequency: 'annually',
161
+ resource: { id: 'I-HG5K7XD0BVPJ' },
162
+ payment: {
163
+ completed: true,
164
+ refunded: false,
165
+ },
166
+ start: { timestamp: '2023-04-28T02:16:58.000Z', timestampUNIX: 1682648218 },
167
+ expires: { timestamp: '2024-06-10T10:00:00.000Z', timestampUNIX: 1718013600 },
168
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
169
+ lastPayment: {
170
+ amount: 0,
171
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
172
+ },
173
+ trial: {
174
+ active: true,
175
+ claimed: true,
176
+ daysLeft: 13,
177
+ },
178
+ }
179
+
180
+ log('result', result);
181
+
182
+ it('should resolve correctly', () => {
183
+ return assert.deepStrictEqual(result, expected);
184
+ });
185
+ });
186
+
187
+ describe('trial => payment not completed', () => {
188
+ const item = require('./payment-resolver/paypal/subscriptions/trial-payment-not-complete.json');
189
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
190
+ const expected = {
191
+ processor: 'paypal',
192
+ type: 'subscription',
193
+ status: 'suspended',
194
+ frequency: 'monthly',
195
+ resource: { id: 'I-6YN0VNT6KM4W' },
196
+ payment: {
197
+ completed: false,
198
+ refunded: false,
199
+ },
200
+ start: { timestamp: '2023-05-11T10:52:00.000Z', timestampUNIX: 1683802320 },
201
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
202
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
203
+ lastPayment: {
204
+ amount: 0,
205
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
206
+ },
207
+ trial: {
208
+ active: false,
209
+ claimed: true,
210
+ daysLeft: 0,
211
+ },
212
+ }
213
+
214
+ log('result', result);
215
+
216
+ it('should resolve correctly', () => {
217
+ return assert.deepStrictEqual(result, expected);
218
+ });
219
+ });
220
+
221
+ describe('trial => payment overdue', () => {
222
+ const item = require('./payment-resolver/paypal/subscriptions/trial-payment-overdue.json');
223
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
224
+ const expected = {
225
+ processor: 'paypal',
226
+ type: 'subscription',
227
+ status: 'suspended',
228
+ frequency: 'annually',
229
+ resource: { id: 'I-PFLFF5TTAN4S' },
230
+ payment: {
231
+ completed: true,
232
+ refunded: false,
233
+ },
234
+ start: { timestamp: '2023-09-09T05:58:41.000Z', timestampUNIX: 1694239121 },
235
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
236
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
237
+ lastPayment: {
238
+ amount: 0,
239
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
240
+ },
241
+ trial: {
242
+ active: false,
243
+ claimed: true,
244
+ daysLeft: 0,
245
+ },
246
+ }
247
+
248
+ log('result', result);
249
+
250
+ it('should resolve correctly', () => {
251
+ return assert.deepStrictEqual(result, expected);
252
+ });
253
+ });
254
+
255
+ describe('trial => payment overdue (2)', () => {
256
+ const item = require('./payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json');
257
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
258
+ const expected = {
259
+ processor: 'paypal',
260
+ type: 'subscription',
261
+ status: 'suspended',
262
+ frequency: 'annually',
263
+ resource: { id: 'I-JU1H0XF32WU5' },
264
+ payment: {
265
+ completed: true,
266
+ refunded: false,
267
+ },
268
+ start: { timestamp: '2023-09-08T07:15:10.000Z', timestampUNIX: 1694157310 },
269
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
270
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
271
+ lastPayment: {
272
+ amount: 0,
273
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
274
+ },
275
+ trial: {
276
+ active: false,
277
+ claimed: true,
278
+ daysLeft: 0,
279
+ },
280
+ }
281
+
282
+ log('result', result);
283
+
284
+ it('should resolve correctly', () => {
285
+ return assert.deepStrictEqual(result, expected);
286
+ });
287
+ });
288
+
289
+ describe('trial => active => cancelled', () => {
290
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json');
291
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
292
+ const expected = {
293
+ processor: 'paypal',
294
+ type: 'subscription',
295
+ status: 'cancelled',
296
+ frequency: 'monthly',
297
+ resource: { id: 'I-MH92AV4A3EA6' },
298
+ payment: {
299
+ completed: true,
300
+ refunded: false,
301
+ },
302
+ start: { timestamp: '2023-03-31T14:48:51.000Z', timestampUNIX: 1680274131 },
303
+ expires: { timestamp: '2023-05-14T10:56:15.000Z', timestampUNIX: 1684061775 },
304
+ cancelled: { timestamp: '2023-04-18T10:14:56.000Z', timestampUNIX: 1681812896 },
305
+ lastPayment: {
306
+ amount: 19.95,
307
+ date: { timestamp: '2023-04-14T10:56:15.000Z', timestampUNIX: 1681469775 }
308
+ },
309
+ trial: {
310
+ active: false,
311
+ claimed: true,
312
+ daysLeft: 0,
313
+ },
314
+ }
315
+
316
+ log('result', result);
317
+
318
+ it('should resolve correctly', () => {
319
+ return assert.deepStrictEqual(result, expected);
320
+ });
321
+ });
322
+
323
+ describe('trial => active', () => {
324
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-active.json');
325
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
326
+ const expected = {
327
+ processor: 'paypal',
328
+ type: 'subscription',
329
+ status: 'active',
330
+ frequency: 'monthly',
331
+ resource: { id: 'I-VTXGPKDTMMK2' },
332
+ payment: {
333
+ completed: true,
334
+ refunded: false,
335
+ },
336
+ start: { timestamp: '2023-04-11T17:37:58.000Z', timestampUNIX: 1681234678 },
337
+ expires: { timestamp: '2024-05-25T10:28:22.000Z', timestampUNIX: 1716632902 },
338
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
339
+ lastPayment: {
340
+ amount: 19.95,
341
+ date: { timestamp: '2023-04-25T10:28:22.000Z', timestampUNIX: 1682418502 }
342
+ },
343
+ trial: {
344
+ active: false,
345
+ claimed: false,
346
+ daysLeft: 0,
347
+ },
348
+ }
349
+
350
+ log('result', result);
351
+
352
+ it('should resolve correctly', () => {
353
+ return assert.deepStrictEqual(result, expected);
354
+ });
355
+ });
356
+
357
+ describe('trial => cancelled', () => {
358
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-cancelled.json');
359
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
360
+ const expected = {
361
+ processor: 'paypal',
362
+ type: 'subscription',
363
+ status: 'cancelled',
364
+ frequency: 'monthly',
365
+ resource: { id: 'I-79C4RSSVKN95' },
366
+ payment: {
367
+ completed: true,
368
+ refunded: false,
369
+ },
370
+ start: { timestamp: '2023-03-31T08:41:35.000Z', timestampUNIX: 1680252095 },
371
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
372
+ cancelled: { timestamp: '2023-04-02T23:38:44.000Z', timestampUNIX: 1680478724 },
373
+ lastPayment: {
374
+ amount: 0,
375
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
376
+ },
377
+ trial: {
378
+ active: false,
379
+ claimed: true,
380
+ daysLeft: 0,
381
+ },
382
+ }
383
+
384
+ log('result', result);
385
+
386
+ it('should resolve correctly', () => {
387
+ return assert.deepStrictEqual(result, expected);
388
+ });
389
+ });
390
+
391
+ describe('trial => expired', () => {
392
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-expired.json');
393
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
394
+ const expected = {
395
+ processor: 'paypal',
396
+ type: 'subscription',
397
+ status: 'cancelled',
398
+ frequency: 'monthly',
399
+ resource: { id: 'I-BC83SG8TF205' },
400
+ payment: {
401
+ completed: true,
402
+ refunded: false,
403
+ },
404
+ start: { timestamp: '2023-06-05T15:16:16.000Z', timestampUNIX: 1685978176 },
405
+ expires: { timestamp: '2023-07-05T15:16:31.000Z', timestampUNIX: 1688570191 },
406
+ cancelled: { timestamp: '2023-06-05T15:16:33.000Z', timestampUNIX: 1685978193 },
407
+ lastPayment: {
408
+ amount: 3,
409
+ date: { timestamp: '2023-06-05T15:16:31.000Z', timestampUNIX: 1685978191 }
410
+ },
411
+ trial: {
412
+ active: false,
413
+ claimed: false,
414
+ daysLeft: 0,
415
+ },
416
+ }
417
+
418
+ log('result', result);
419
+
420
+ it('should resolve correctly', () => {
421
+ return assert.deepStrictEqual(result, expected);
422
+ });
423
+ });
424
+
425
+ describe('trial => refund', () => {
426
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-refund.json');
427
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
428
+ const expected = {
429
+ processor: 'paypal',
430
+ type: 'subscription',
431
+ status: 'cancelled',
432
+ frequency: 'annually',
433
+ resource: { id: 'I-JW7F1RK5KN8W' },
434
+ payment: {
435
+ completed: true,
436
+ refunded: true,
437
+ },
438
+ start: { timestamp: '2023-07-17T14:31:50.000Z', timestampUNIX: 1689604310 },
439
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
440
+ cancelled: { timestamp: '2023-07-31T11:33:32.000Z', timestampUNIX: 1690803212 },
441
+ lastPayment: {
442
+ amount: 191.4,
443
+ date: { timestamp: '2023-07-31T11:13:59.000Z', timestampUNIX: 1690802039 }
444
+ },
445
+ trial: {
446
+ active: false,
447
+ claimed: false,
448
+ daysLeft: 0,
449
+ },
450
+ }
451
+
452
+ log('result', result);
453
+
454
+ it('should resolve correctly', () => {
455
+ return assert.deepStrictEqual(result, expected);
456
+ });
457
+ });
458
+
459
+ describe('trial => suspended', () => {
460
+ const item = require('./payment-resolver/paypal/subscriptions/trial-to-suspended.json');
461
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
462
+ const expected = {
463
+ processor: 'paypal',
464
+ type: 'subscription',
465
+ status: 'suspended',
466
+ frequency: 'monthly',
467
+ resource: { id: 'I-A3AS9XBE0JEG' },
468
+ payment: {
469
+ completed: true,
470
+ refunded: false,
471
+ },
472
+ start: { timestamp: '2023-07-11T16:52:11.000Z', timestampUNIX: 1689094331 },
473
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
474
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
475
+ lastPayment: {
476
+ amount: 9.97,
477
+ date: { timestamp: '2023-07-11T16:53:50.000Z', timestampUNIX: 1689094430 }
478
+ },
479
+ trial: {
480
+ active: false,
481
+ claimed: false,
482
+ daysLeft: 0,
483
+ },
484
+ }
485
+
486
+ log('result', result);
487
+
488
+ it('should resolve correctly', () => {
489
+ return assert.deepStrictEqual(result, expected);
490
+ });
491
+ });
492
+ });
493
+ });
494
+
495
+ /*
496
+ * CHARGEBEE
497
+ */
498
+ describe('chargebee', () => {
499
+ // Orders
500
+ describe('orders', () => {
501
+ // describe('regular', () => {
502
+ // const item = require('./payment-resolver/chargebee/orders/regular.json');
503
+ // const result = Manager.SubscriptionResolver({}, item).resolve(options);
504
+ // const expected = {
505
+ // processor: 'chargebee',
506
+ // type: 'order',
507
+ // status: 'cancelled',
508
+ // frequency: 'single',
509
+ // resource: { id: '3065' },
510
+ // payment: {
511
+ // completed: false,
512
+ // refunded: false,
513
+ // },
514
+ // start: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 },
515
+ // expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
516
+ // cancelled: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 },
517
+ // lastPayment: {
518
+ // amount: 0,
519
+ // date: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 }
520
+ // },
521
+ // trial: {
522
+ // active: false,
523
+ // claimed: false,
524
+ // daysLeft: 0,
525
+ // },
526
+ // }
527
+
528
+ // log('result', result);
529
+
530
+ // it('should resolve correctly', () => {
531
+ // return assert.deepStrictEqual(result, expected);
532
+ // });
533
+ // });
534
+
535
+ describe('unpaid', () => {
536
+ const item = require('./payment-resolver/chargebee/orders/unpaid.json');
537
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
538
+ const expected = {
539
+ processor: 'chargebee',
540
+ type: 'order',
541
+ status: 'cancelled',
542
+ frequency: 'single',
543
+ resource: { id: '3065' },
544
+ payment: {
545
+ completed: false,
546
+ refunded: false,
547
+ },
548
+ start: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 },
549
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
550
+ cancelled: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 },
551
+ lastPayment: {
552
+ amount: 0,
553
+ date: { timestamp: '2023-04-27T09:34:43.000Z', timestampUNIX: 1682588083 }
554
+ },
555
+ trial: {
556
+ active: false,
557
+ claimed: false,
558
+ daysLeft: 0,
559
+ },
560
+ }
561
+
562
+ log('result', result);
563
+
564
+ it('should resolve correctly', () => {
565
+ return assert.deepStrictEqual(result, expected);
566
+ });
567
+ });
568
+ });
569
+
570
+ // Subscriptions
571
+ describe('subscriptions', () => {
572
+ describe('active', () => {
573
+ const item = require('./payment-resolver/chargebee/subscriptions/active.json');
574
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
575
+ const expected = {
576
+ processor: 'chargebee',
577
+ type: 'subscription',
578
+ status: 'active',
579
+ frequency: 'monthly',
580
+ resource: { id: 'AzZMxvTYTQUmw1Iw7' },
581
+ payment: {
582
+ completed: true,
583
+ refunded: false,
584
+ },
585
+ start: { timestamp: '2023-03-14T10:37:33.000Z', timestampUNIX: 1678790253 },
586
+ expires: { timestamp: '2024-09-13T10:37:33.000Z', timestampUNIX: 1726223853 },
587
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
588
+ lastPayment: {
589
+ amount: 19.95,
590
+ date: { timestamp: '2023-08-14T10:37:33.000Z', timestampUNIX: 1692009453 }
591
+ },
592
+ trial: {
593
+ active: false,
594
+ claimed: false,
595
+ daysLeft: 0,
596
+ }
597
+ }
598
+
599
+ log('result', result);
600
+
601
+ it('should resolve correctly', () => {
602
+ return assert.deepStrictEqual(result, expected);
603
+ });
604
+ });
605
+
606
+ describe('trial => skipped-to-active', () => {
607
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json');
608
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
609
+ const expected = {
610
+ processor: 'chargebee',
611
+ type: 'subscription',
612
+ status: 'active',
613
+ frequency: 'monthly',
614
+ resource: { id: '6oqX0TnhKo5R513B' },
615
+ payment: {
616
+ completed: true,
617
+ refunded: false,
618
+ },
619
+ start: { timestamp: '2023-08-22T20:55:52.000Z', timestampUNIX: 1692737752 },
620
+ expires: { timestamp: '2024-09-21T20:55:57.000Z', timestampUNIX: 1726952157 },
621
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
622
+ lastPayment: {
623
+ amount: 19.95,
624
+ date: { timestamp: '2023-08-22T20:55:57.000Z', timestampUNIX: 1692737757 }
625
+ },
626
+ trial: {
627
+ active: false,
628
+ claimed: false,
629
+ daysLeft: 0,
630
+ }
631
+ }
632
+
633
+ log('result', result);
634
+
635
+ it('should resolve correctly', () => {
636
+ return assert.deepStrictEqual(result, expected);
637
+ });
638
+ });
639
+
640
+ describe('trial => in-trial', () => {
641
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-in-trial.json');
642
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
643
+ const expected = {
644
+ processor: 'chargebee',
645
+ type: 'subscription',
646
+ status: 'active',
647
+ frequency: 'monthly',
648
+ resource: { id: '16CRCcTcWmQYKyT5' },
649
+ payment: {
650
+ completed: true,
651
+ refunded: false,
652
+ },
653
+ start: { timestamp: '2023-04-26T10:19:48.000Z', timestampUNIX: 1682504388 },
654
+ expires: { timestamp: '2024-06-09T10:19:48.000Z', timestampUNIX: 1717928388 },
655
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
656
+ lastPayment: {
657
+ amount: 0,
658
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
659
+ },
660
+ trial: {
661
+ active: true,
662
+ claimed: true,
663
+ daysLeft: 12,
664
+ },
665
+ }
666
+
667
+ log('result', result);
668
+
669
+ it('should resolve correctly', () => {
670
+ return assert.deepStrictEqual(result, expected);
671
+ });
672
+ });
673
+
674
+ describe('trial => active => cancelled', () => {
675
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json');
676
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
677
+ const expected = {
678
+ processor: 'chargebee',
679
+ type: 'subscription',
680
+ status: 'cancelled',
681
+ frequency: 'monthly',
682
+ resource: { id: 'AzqJXiTaQKh4m5Ta7' },
683
+ payment: {
684
+ completed: true,
685
+ refunded: false,
686
+ },
687
+ start: { timestamp: '2023-04-04T02:53:37.000Z', timestampUNIX: 1680576817 },
688
+ expires: { timestamp: '2023-05-18T02:53:37.000Z', timestampUNIX: 1684378417 },
689
+ cancelled: { timestamp: '2023-04-19T03:42:24.000Z', timestampUNIX: 1681875744 },
690
+ lastPayment: {
691
+ amount: 19.95,
692
+ date: { timestamp: '2023-04-18T02:53:37.000Z', timestampUNIX: 1681786417 }
693
+ },
694
+ trial: {
695
+ active: false,
696
+ claimed: true,
697
+ daysLeft: 0,
698
+ },
699
+ }
700
+
701
+ log('result', result);
702
+
703
+ it('should resolve correctly', () => {
704
+ return assert.deepStrictEqual(result, expected);
705
+ });
706
+ });
707
+
708
+ describe('trial => active', () => {
709
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-to-active.json');
710
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
711
+ const expected = {
712
+ processor: 'chargebee',
713
+ type: 'subscription',
714
+ status: 'active',
715
+ frequency: 'monthly',
716
+ resource: { id: 'AzyfbtTbMhiFM51DW' },
717
+ payment: {
718
+ completed: true,
719
+ refunded: false,
720
+ },
721
+ start: { timestamp: '2023-04-14T02:29:56.000Z', timestampUNIX: 1681439396 },
722
+ expires: { timestamp: '2024-05-28T02:29:56.000Z', timestampUNIX: 1716863396 },
723
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
724
+ lastPayment: {
725
+ amount: 19.95,
726
+ date: { timestamp: '2023-04-28T02:29:56.000Z', timestampUNIX: 1682648996 }
727
+ },
728
+ trial: {
729
+ active: false,
730
+ claimed: true,
731
+ daysLeft: 0,
732
+ },
733
+ }
734
+
735
+ log('result', result);
736
+
737
+ it('should resolve correctly', () => {
738
+ return assert.deepStrictEqual(result, expected);
739
+ });
740
+ });
741
+
742
+ describe('trial => cancelled', () => {
743
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-to-cancelled.json');
744
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
745
+ const expected = {
746
+ processor: 'chargebee',
747
+ type: 'subscription',
748
+ status: 'cancelled',
749
+ frequency: 'monthly',
750
+ resource: { id: 'AzZMshTbnEv7r1Eck' },
751
+ payment: {
752
+ completed: true,
753
+ refunded: false,
754
+ },
755
+ start: { timestamp: '2023-04-18T15:24:28.000Z', timestampUNIX: 1681831468 },
756
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
757
+ cancelled: { timestamp: '2023-04-25T10:41:02.000Z', timestampUNIX: 1682419262 },
758
+ lastPayment: {
759
+ amount: 0,
760
+ date: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 }
761
+ },
762
+ trial: {
763
+ active: false,
764
+ claimed: true,
765
+ daysLeft: 0,
766
+ },
767
+ }
768
+
769
+ log('result', result);
770
+
771
+ it('should resolve correctly', () => {
772
+ return assert.deepStrictEqual(result, expected);
773
+ });
774
+ });
775
+
776
+ describe('trial => refund', () => {
777
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-to-refund.json');
778
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
779
+ const expected = {
780
+ processor: 'chargebee',
781
+ type: 'subscription',
782
+ status: 'cancelled',
783
+ frequency: 'monthly',
784
+ resource: { id: 'AzymDoTjgzDShlvd' },
785
+ payment: {
786
+ completed: true,
787
+ refunded: true,
788
+ },
789
+ start: { timestamp: '2023-07-11T09:37:47.000Z', timestampUNIX: 1689068267 },
790
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
791
+ cancelled: { timestamp: '2023-07-15T13:23:15.000Z', timestampUNIX: 1689427395 },
792
+ lastPayment: {
793
+ amount: 19.95,
794
+ date: { timestamp: '2023-07-11T09:37:54.000Z', timestampUNIX: 1689068274 }
795
+ },
796
+ trial: {
797
+ active: false,
798
+ claimed: false,
799
+ daysLeft: 0,
800
+ },
801
+ }
802
+
803
+ log('result', result);
804
+
805
+ it('should resolve correctly', () => {
806
+ return assert.deepStrictEqual(result, expected);
807
+ });
808
+ });
809
+
810
+ describe('trial => suspendeded', () => {
811
+ const item = require('./payment-resolver/chargebee/subscriptions/trial-to-suspended.json');
812
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
813
+ const expected = {
814
+ processor: 'chargebee',
815
+ type: 'subscription',
816
+ status: 'suspended',
817
+ frequency: 'monthly',
818
+ resource: { id: 'Azym2sTkewehg121r' },
819
+ payment: {
820
+ completed: true,
821
+ refunded: false,
822
+ },
823
+ start: { timestamp: '2023-07-21T15:40:12.000Z', timestampUNIX: 1689954012 },
824
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
825
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
826
+ lastPayment: {
827
+ amount: 0,
828
+ date: { timestamp: '2023-08-04T15:40:12.000Z', timestampUNIX: 1691163612 }
829
+ },
830
+ trial: {
831
+ active: false,
832
+ claimed: true,
833
+ daysLeft: 0,
834
+ },
835
+ }
836
+
837
+ log('result', result);
838
+
839
+ it('should resolve correctly', () => {
840
+ return assert.deepStrictEqual(result, expected);
841
+ });
842
+ });
843
+ });
844
+
845
+ });
846
+
847
+ /*
848
+ * STRIPE
849
+ */
850
+ describe('stripe', () => {
851
+ // Orders
852
+ describe('orders', () => {
853
+ describe('regular', () => {
854
+ const item = require('./payment-resolver/stripe/orders/regular.json');
855
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
856
+ const expected = {
857
+ processor: 'stripe',
858
+ type: 'order',
859
+ status: 'cancelled',
860
+ frequency: 'single',
861
+ resource: { id: 'ch_3N1pAXJVFkvVyI7h1FM4wdxL' },
862
+ payment: {
863
+ completed: true,
864
+ refunded: false,
865
+ },
866
+ start: { timestamp: '2023-04-28T11:08:54.000Z', timestampUNIX: 1682680134 },
867
+ expires: { timestamp: '2023-04-28T11:08:54.000Z', timestampUNIX: 1682680134 },
868
+ cancelled: { timestamp: '2023-04-28T11:08:54.000Z', timestampUNIX: 1682680134 },
869
+ lastPayment: {
870
+ amount: 1.01,
871
+ date: { timestamp: '2023-04-28T11:08:54.000Z', timestampUNIX: 1682680134 }
872
+ },
873
+ trial: {
874
+ active: false,
875
+ claimed: false,
876
+ daysLeft: 0,
877
+ },
878
+ }
879
+
880
+ log('result', result);
881
+
882
+ it('should resolve correctly', () => {
883
+ return assert.deepStrictEqual(result, expected);
884
+ });
885
+ });
886
+ });
887
+
888
+ // Subscriptions
889
+ describe('subscriptions', () => {
890
+ describe('active', () => {
891
+ const item = require('./payment-resolver/stripe/subscriptions/active.json');
892
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
893
+ const expected = {
894
+ processor: 'stripe',
895
+ type: 'subscription',
896
+ status: 'active',
897
+ frequency: 'monthly',
898
+ resource: { id: 'sub_1McA4ZEvB7hJrWnu1o7GMybv' },
899
+ payment: {
900
+ completed: true,
901
+ refunded: false,
902
+ },
903
+ start: { timestamp: '2023-02-16T16:12:39.000Z', timestampUNIX: 1676563959 },
904
+ expires: { timestamp: '2024-09-15T16:12:39.000Z', timestampUNIX: 1726416759 },
905
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
906
+ lastPayment: {
907
+ amount: 6,
908
+ date: { timestamp: '2023-08-16T16:13:11.000Z', timestampUNIX: 1692202391 }
909
+ },
910
+ trial: {
911
+ active: false,
912
+ claimed: false,
913
+ daysLeft: 0,
914
+ },
915
+ }
916
+
917
+ log('result', result);
918
+
919
+ it('should resolve correctly', () => {
920
+ return assert.deepStrictEqual(result, expected);
921
+ });
922
+ });
923
+
924
+ describe('trial => in trial', () => {
925
+ const item = require('./payment-resolver/stripe/subscriptions/trial-in-trial.json');
926
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
927
+ const expected = {
928
+ processor: 'stripe',
929
+ type: 'subscription',
930
+ status: 'active',
931
+ frequency: 'monthly',
932
+ resource: { id: 'sub_1N1a4yEvB7hJrWnuCzx5ssWK' },
933
+ payment: {
934
+ completed: true,
935
+ refunded: false,
936
+ },
937
+ start: { timestamp: '2023-04-27T19:02:08.000Z', timestampUNIX: 1682622128 },
938
+ expires: { timestamp: '2024-06-10T19:02:08.000Z', timestampUNIX: 1718046128 },
939
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
940
+ lastPayment: {
941
+ amount: 0,
942
+ date: { timestamp: '2023-04-27T19:02:08.000Z', timestampUNIX: 1682622128 }
943
+ },
944
+ trial: {
945
+ active: true,
946
+ claimed: true,
947
+ daysLeft: 13,
948
+ },
949
+ }
950
+
951
+ log('result', result);
952
+
953
+ it('should resolve correctly', () => {
954
+ return assert.deepStrictEqual(result, expected);
955
+ });
956
+ });
957
+
958
+ describe('trial => active', () => {
959
+ const item = require('./payment-resolver/stripe/subscriptions/trial-to-active.json');
960
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
961
+ const expected = {
962
+ processor: 'stripe',
963
+ type: 'subscription',
964
+ status: 'active',
965
+ frequency: 'monthly',
966
+ resource: { id: 'sub_1MqedqJVFkvVyI7hYGbJyOFD' },
967
+ payment: {
968
+ completed: true,
969
+ refunded: false,
970
+ },
971
+ start: { timestamp: '2023-03-28T15:40:58.000Z', timestampUNIX: 1680018058 },
972
+ expires: { timestamp: '2024-05-11T15:40:58.000Z', timestampUNIX: 1715442058 },
973
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
974
+ lastPayment: {
975
+ amount: 6,
976
+ date: { timestamp: '2023-04-11T15:41:07.000Z', timestampUNIX: 1681227667 }
977
+ },
978
+ trial: {
979
+ active: false,
980
+ claimed: true,
981
+ daysLeft: 0,
982
+ },
983
+ }
984
+
985
+ log('result', result);
986
+
987
+ it('should resolve correctly', () => {
988
+ return assert.deepStrictEqual(result, expected);
989
+ });
990
+ });
991
+
992
+ // ...
993
+
994
+ describe('trial => cancelled', () => {
995
+ const item = require('./payment-resolver/stripe/subscriptions/trial-to-cancelled.json');
996
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
997
+ const expected = {
998
+ processor: 'stripe',
999
+ type: 'subscription',
1000
+ status: 'cancelled',
1001
+ frequency: 'monthly',
1002
+ resource: { id: 'sub_1Mv9VtCzY9baOpL0I2MRKfoj' },
1003
+ payment: {
1004
+ completed: true,
1005
+ refunded: false,
1006
+ },
1007
+ start: { timestamp: '2023-04-10T01:27:21.000Z', timestampUNIX: 1681090041 },
1008
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
1009
+ cancelled: { timestamp: '2023-04-17T07:13:15.000Z', timestampUNIX: 1681715595 },
1010
+ lastPayment: {
1011
+ amount: 0,
1012
+ date: { timestamp: '2023-04-10T01:27:21.000Z', timestampUNIX: 1681090041 }
1013
+ },
1014
+ trial: {
1015
+ active: false,
1016
+ claimed: true,
1017
+ daysLeft: 0,
1018
+ },
1019
+ }
1020
+
1021
+ log('result', result);
1022
+
1023
+ it('should resolve correctly', () => {
1024
+ return assert.deepStrictEqual(result, expected);
1025
+ });
1026
+ });
1027
+
1028
+ describe('trial => refund', () => {
1029
+ const item = require('./payment-resolver/stripe/subscriptions/trial-to-refund.json');
1030
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
1031
+ const expected = {
1032
+ processor: 'stripe',
1033
+ type: 'subscription',
1034
+ status: 'cancelled',
1035
+ frequency: 'annually',
1036
+ resource: { id: 'sub_1NWA2ZHGybgi7uQGF7ODZNEZ' },
1037
+ payment: {
1038
+ completed: true,
1039
+ refunded: true,
1040
+ },
1041
+ start: { timestamp: '2023-07-21T03:30:03.000Z', timestampUNIX: 1689910203 },
1042
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
1043
+ cancelled: { timestamp: '2023-08-03T19:51:57.000Z', timestampUNIX: 1691092317 },
1044
+ lastPayment: {
1045
+ amount: 72,
1046
+ date: { timestamp: '2023-07-21T03:30:03.000Z', timestampUNIX: 1689910203 }
1047
+ },
1048
+ trial: {
1049
+ active: false,
1050
+ claimed: false,
1051
+ daysLeft: 0,
1052
+ },
1053
+ }
1054
+
1055
+ log('result', result);
1056
+
1057
+ it('should resolve correctly', () => {
1058
+ return assert.deepStrictEqual(result, expected);
1059
+ });
1060
+ });
1061
+
1062
+ describe('trial => suspended', () => {
1063
+ const item = require('./payment-resolver/stripe/subscriptions/trial-to-suspended.json');
1064
+ const result = Manager.SubscriptionResolver({}, item).resolve(options);
1065
+ const expected = {
1066
+ processor: 'stripe',
1067
+ type: 'subscription',
1068
+ status: 'suspended',
1069
+ frequency: 'monthly',
1070
+ resource: { id: 'sub_1MrOiKCzY9baOpL0TNU5sQZQ' },
1071
+ payment: {
1072
+ completed: true,
1073
+ refunded: false,
1074
+ },
1075
+ start: { timestamp: '2023-03-30T16:52:40.000Z', timestampUNIX: 1680195160 },
1076
+ expires: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
1077
+ cancelled: { timestamp: '1970-01-01T00:00:00.000Z', timestampUNIX: 0 },
1078
+ lastPayment: {
1079
+ amount: 0,
1080
+ date: { timestamp: '2023-04-13T16:52:51.000Z', timestampUNIX: 1681404771 }
1081
+ },
1082
+ trial: {
1083
+ active: false,
1084
+ claimed: true,
1085
+ daysLeft: 0,
1086
+ },
1087
+ }
1088
+
1089
+ log('result', result);
1090
+
1091
+ it('should resolve correctly', () => {
1092
+ return assert.deepStrictEqual(result, expected);
1093
+ });
1094
+ });
1095
+ });
1096
+
1097
+ });
1098
+
1099
+ /*
1100
+ * COINBASE
1101
+ */
1102
+ describe('coinbase', () => {
1103
+ describe('order', () => {
1104
+ describe('regular', () => {
1105
+ const item = require('./payment-resolver/coinbase/orders/regular.json');
1106
+ const result = Manager.SubscriptionResolver(defaultProfileOrder, item).resolve(options);
1107
+ const expected = {
1108
+ processor: 'coinbase',
1109
+ type: 'order',
1110
+ status: 'cancelled',
1111
+ frequency: 'single',
1112
+ resource: { id: '8f783fa6-eaa3-4460-af64-cac26b183ed1' },
1113
+ payment: {
1114
+ completed: true,
1115
+ refunded: false,
1116
+ },
1117
+ start: { timestamp: '2023-04-26T09:59:19.000Z', timestampUNIX: 1682503159 },
1118
+ expires: { timestamp: '2023-04-26T09:59:19.000Z', timestampUNIX: 1682503159 },
1119
+ cancelled: { timestamp: '2023-04-26T09:59:19.000Z', timestampUNIX: 1682503159 },
1120
+ lastPayment: {
1121
+ amount: 16,
1122
+ date: { timestamp: '2023-04-26T10:06:55.000Z', timestampUNIX: 1682503615 }
1123
+ },
1124
+ trial: {
1125
+ active: false,
1126
+ claimed: false,
1127
+ daysLeft: 0,
1128
+ },
1129
+ }
1130
+
1131
+ log('result', result);
1132
+
1133
+ it('should resolve correctly', () => {
1134
+ return assert.deepStrictEqual(result, expected);
1135
+ });
1136
+ });
1137
+ });
1138
+
1139
+ describe('subscription', () => {
1140
+ describe('cancelled', () => {
1141
+ const item = require('./payment-resolver/coinbase/subscriptions/cancelled.json');
1142
+ const result = Manager.SubscriptionResolver(defaultProfileSubscription, item).resolve(options);
1143
+ const expected = {
1144
+ processor: 'coinbase',
1145
+ type: 'subscription',
1146
+ status: 'cancelled',
1147
+ frequency: 'monthly',
1148
+ resource: { id: '8f783fa6-eaa3-4460-af64-cac26b183ed1' },
1149
+ payment: {
1150
+ completed: true,
1151
+ refunded: false,
1152
+ },
1153
+ start: { timestamp: '2023-04-26T09:59:19.000Z', timestampUNIX: 1682503159 },
1154
+ expires: { timestamp: '2023-05-26T09:59:19.000Z', timestampUNIX: 1685095159 },
1155
+ cancelled: { timestamp: '2023-04-26T09:59:19.000Z', timestampUNIX: 1682503159 },
1156
+ lastPayment: {
1157
+ amount: 16,
1158
+ date: { timestamp: '2023-04-26T10:06:55.000Z', timestampUNIX: 1682503615 }
1159
+ },
1160
+ trial: {
1161
+ active: false,
1162
+ claimed: false,
1163
+ daysLeft: 0,
1164
+ },
1165
+ }
1166
+
1167
+ log('result', result);
1168
+
1169
+ it('should resolve correctly', () => {
1170
+ return assert.deepStrictEqual(result, expected);
1171
+ });
1172
+ });
1173
+ });
1174
+ });
1175
+
1176
+ });
1177
+
1178
+ })