-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added `error` object in VoucherifyError. * Added validation_rules to VouchersCreateParameters (mostly for test case) * Added test Redemptions API with `redemption that failed due validation rule validate error should has .error.message element if defined in validation rule` test. * Changeset. * Removed comma from VouchersCreateParameters
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 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 | ||
--- | ||
|
||
Added `error` object in `VoucherifyError`. Added `validation_rules` in VouchersCreateParameters. |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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) | ||
} | ||
}) | ||
}) |