|
1 | 1 | jest.mock('src/config', () => ({ |
2 | 2 | ENV_CONFIG: { |
| 3 | + ENGAGEMENT_PAYMENT_RELEASE_WINDOW_DAYS: 5, |
3 | 4 | SENDGRID_TEMPLATE_ID_PAYMENT_SETUP_NOTIFICATION: 'template-id', |
4 | 5 | TGBillingAccounts: [80000062, 80002800], |
5 | 6 | TOPCODER_WALLET_URL: 'https://wallet.topcoder.com', |
@@ -256,6 +257,73 @@ describe('WinningsService', () => { |
256 | 257 | }); |
257 | 258 | }); |
258 | 259 |
|
| 260 | + it('applies a short release window to engagement payments', async () => { |
| 261 | + const beforeCreate = Date.now(); |
| 262 | + |
| 263 | + await service.createWinningWithPayments( |
| 264 | + { |
| 265 | + winnerId: 'user-1', |
| 266 | + type: WinningsType.PAYMENT, |
| 267 | + origin: 'Topcoder', |
| 268 | + category: WinningsCategory.ENGAGEMENT_PAYMENT, |
| 269 | + title: 'Engagement work', |
| 270 | + description: 'Engagement payment', |
| 271 | + externalId: 'assignment-1', |
| 272 | + details: [ |
| 273 | + { |
| 274 | + totalAmount: 100, |
| 275 | + grossAmount: 100, |
| 276 | + installmentNumber: 1, |
| 277 | + currency: PrizeType.USD, |
| 278 | + billingAccount: '123456', |
| 279 | + }, |
| 280 | + ], |
| 281 | + } as any, |
| 282 | + 'creator-1', |
| 283 | + ); |
| 284 | + |
| 285 | + const persistedPayment = |
| 286 | + tx.winnings.create.mock.calls[0][0].data.payment.create[0]; |
| 287 | + |
| 288 | + const releaseDate = new Date(persistedPayment.release_date).getTime(); |
| 289 | + const daysUntilRelease = (releaseDate - beforeCreate) / (24 * 60 * 60 * 1000); |
| 290 | + |
| 291 | + expect(daysUntilRelease).toBeGreaterThanOrEqual(4.99); |
| 292 | + expect(daysUntilRelease).toBeLessThanOrEqual(5.01); |
| 293 | + }); |
| 294 | + |
| 295 | + it('keeps the default release window for non-engagement payments', async () => { |
| 296 | + await service.createWinningWithPayments( |
| 297 | + { |
| 298 | + winnerId: 'user-1', |
| 299 | + type: WinningsType.PAYMENT, |
| 300 | + origin: 'Topcoder', |
| 301 | + category: WinningsCategory.CONTEST_PAYMENT, |
| 302 | + title: 'Contest payout', |
| 303 | + description: 'Contest payment', |
| 304 | + externalId: 'challenge-1', |
| 305 | + details: [ |
| 306 | + { |
| 307 | + totalAmount: 100, |
| 308 | + grossAmount: 100, |
| 309 | + installmentNumber: 1, |
| 310 | + currency: PrizeType.USD, |
| 311 | + billingAccount: '80001012', |
| 312 | + }, |
| 313 | + ], |
| 314 | + } as any, |
| 315 | + 'creator-1', |
| 316 | + ); |
| 317 | + |
| 318 | + const persistedPayment = |
| 319 | + tx.winnings.create.mock.calls[0][0].data.payment.create[0]; |
| 320 | + |
| 321 | + expect(persistedPayment.release_date).toBeUndefined(); |
| 322 | + expect( |
| 323 | + Object.prototype.hasOwnProperty.call(persistedPayment, 'release_date'), |
| 324 | + ).toBe(false); |
| 325 | + }); |
| 326 | + |
259 | 327 | it('rejects engagement payment details that do not match the assignment billing account', async () => { |
260 | 328 | await expect( |
261 | 329 | service.createWinningWithPayments( |
|
0 commit comments