-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additions to stacked validations and stacked redemptions (#270)
- Loading branch information
1 parent
f50a7f5
commit d532cc4
Showing
6 changed files
with
118 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@voucherify/sdk': patch | ||
--- | ||
|
||
Type support for partial redemptions. General update to responses of /validations and /redemptions endpoints. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,56 @@ | ||
import { voucherifyClient as client } from './client' | ||
import {DiscountVouchersTypesEnum} from "@voucherify/sdk"; | ||
import {generateRandomString} from "./utils/generateRandomString"; | ||
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' | ||
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 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 | ||
] | ||
}) | ||
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) | ||
} | ||
}) | ||
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) | ||
} | ||
}) | ||
}) |