-
Notifications
You must be signed in to change notification settings - Fork 16
/
redemptions.spec.ts
56 lines (51 loc) · 1.37 KB
/
redemptions.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { voucherifyClient as client } from './client'
import { DiscountVouchersTypesEnum } from '@voucherify/sdk'
import { generateRandomString } from './utils/generateRandomString'
jest.setTimeout(15000)
describe('Redemptions API', () => {
it('redemption that failed due validation rule validate error should has .error.message element if defined in validation rule', async () => {
const errorMessage = 'CUSTOMER NOT IN SEGMENT'
const validationRule = await client.validationRules.create({
name: 'Customer must be in segment',
rules: {
1: {
name: 'customer_segment',
rules: {},
property: null,
conditions: {
$is: ['seg_' + generateRandomString()],
},
},
logic: '1',
},
error: {
message: errorMessage,
},
})
const voucher = await client.vouchers.create({
type: 'DISCOUNT_VOUCHER',
discount: {
amount_off: 2000,
type: DiscountVouchersTypesEnum.AMOUNT,
},
redemption: {
quantity: 1,
},
metadata: {},
validation_rules: [validationRule.id],
})
try {
await client.redemptions.redeem(voucher.code, {
customer: {
source_id: 'cust_' + generateRandomString(),
name: 'John Doe',
object: 'customer',
},
})
} catch (error) {
expect(error.message).toBeDefined()
expect(error.error.message).toBeDefined()
expect(error.error.message).toEqual(errorMessage)
}
})
})