|
| 1 | +require('../../src/bootstrap') |
| 2 | +const logger = require('../../src/common/logger') |
| 3 | +const paymentService = require('../../src/services/PaymentService') |
| 4 | + |
| 5 | +const options = [ |
| 6 | + { |
| 7 | + name: 'Test joi validation for projectId-1', |
| 8 | + content: { |
| 9 | + userHandle: 'pshah_manager', |
| 10 | + amount: 3, |
| 11 | + billingAccountId: 80000069, |
| 12 | + name: 'test payment for pshah_manager', |
| 13 | + description: '## test payment' |
| 14 | + } |
| 15 | + }, |
| 16 | + { |
| 17 | + name: 'Test joi validation for projectId-2', |
| 18 | + content: { |
| 19 | + projectId: 'project', |
| 20 | + userHandle: 'pshah_manager', |
| 21 | + amount: 3, |
| 22 | + billingAccountId: 80000069, |
| 23 | + name: 'test payment for pshah_manager', |
| 24 | + description: '## test payment' |
| 25 | + } |
| 26 | + }, |
| 27 | + { |
| 28 | + name: 'Test joi validation for userHandle', |
| 29 | + content: { |
| 30 | + projectId: 17234, |
| 31 | + amount: 3, |
| 32 | + billingAccountId: 80000069, |
| 33 | + name: 'test payment for pshah_manager', |
| 34 | + description: '## test payment' |
| 35 | + } |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'Test joi validation for amount-1', |
| 39 | + content: { |
| 40 | + projectId: 17234, |
| 41 | + userHandle: 'pshah_manager', |
| 42 | + billingAccountId: 80000069, |
| 43 | + name: 'test payment for pshah_manager', |
| 44 | + description: '## test payment' |
| 45 | + } |
| 46 | + }, |
| 47 | + { |
| 48 | + name: 'Test joi validation for amount-2', |
| 49 | + content: { |
| 50 | + projectId: 17234, |
| 51 | + userHandle: 'pshah_manager', |
| 52 | + amount: -10, |
| 53 | + billingAccountId: 80000069, |
| 54 | + name: 'test payment for pshah_manager', |
| 55 | + description: '## test payment' |
| 56 | + } |
| 57 | + }, |
| 58 | + { |
| 59 | + name: 'Successful payment creation', |
| 60 | + content: { |
| 61 | + projectId: 17234, |
| 62 | + userHandle: 'pshah_manager', |
| 63 | + amount: 3, |
| 64 | + billingAccountId: 80000069, |
| 65 | + name: 'test payment for pshah_manager', |
| 66 | + description: '## test payment' |
| 67 | + } |
| 68 | + }, |
| 69 | + { |
| 70 | + name: 'Successful payment creation without name and description', |
| 71 | + content: { |
| 72 | + projectId: 17234, |
| 73 | + userHandle: 'pshah_customer', |
| 74 | + amount: 2, |
| 75 | + billingAccountId: 80000069 |
| 76 | + } |
| 77 | + }, |
| 78 | + { |
| 79 | + name: 'Failing payment creation with no active billing account', |
| 80 | + content: { |
| 81 | + projectId: 16839, |
| 82 | + userHandle: 'pshah_customer', |
| 83 | + amount: 2, |
| 84 | + billingAccountId: 80000069, |
| 85 | + name: 'test payment for pshah_customer', |
| 86 | + description: '## test payment' |
| 87 | + } |
| 88 | + }, |
| 89 | + { |
| 90 | + name: 'Failing payment creation with non existing user', |
| 91 | + content: { |
| 92 | + projectId: 17234, |
| 93 | + userHandle: 'eisbilir', |
| 94 | + amount: 2, |
| 95 | + billingAccountId: 80000069 |
| 96 | + } |
| 97 | + } |
| 98 | +] |
| 99 | + |
| 100 | +const test = async () => { |
| 101 | + for (const option of options) { |
| 102 | + logger.info({ component: 'demo-payment', context: 'test', message: `Starting to create payment for: ${option.name}` }) |
| 103 | + await paymentService.createPayment(option.content) |
| 104 | + .then(data => { |
| 105 | + logger.info({ component: 'demo-payment', context: 'test', message: `Payment successfuly created for: ${option.name}` }) |
| 106 | + }) |
| 107 | + // eslint-disable-next-line handle-callback-err |
| 108 | + .catch(err => { |
| 109 | + logger.error({ component: 'demo-payment', context: 'test', message: `Payment can't be created for: ${option.name}` }) |
| 110 | + }) |
| 111 | + } |
| 112 | +} |
| 113 | +// wait for bootstrap to complete it's job. |
| 114 | +setTimeout(test, 2000) |
0 commit comments