Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should stop import on first error by default', async () => {
// Set batchSize to 1 so it executes serially
codeImport = new DiscountCodeImport({ apiConfig, batchSize: 1 }, logger)
// Make codes unique
const discountCodesSample = preparedDiscountCodes.map(codeObj => {
const uniqueCode = codeObj.code
return { ...codeObj, code: `${uniqueCode}bar` }
})
// Make code invalid
discountCodesSample[1].code = ''
discountCodesSample[2].code = ''
try {
await codeImport.run(discountCodesSample)
} catch (e) {
expect(e.summary.created).toBe(1)
expect(e.summary.errors).toHaveLength(1)
expect(e.summary.errors[0]).toMatch(/'code' should not be empty/)
it('should continueOnProblems if `continueOnProblems`', async () => {
codeImport = new DiscountCodeImport(
{
apiConfig,
batchSize: 5,
continueOnProblems: true,
},
logger
)
// Make codes unique
const discountCodesSample = preparedDiscountCodes.map(codeObj => {
const uniqueCode = codeObj.code
return { ...codeObj, code: `${uniqueCode}foobar` }
})
// Make code invalid
discountCodesSample[1].code = ''
discountCodesSample[7].cartDiscounts = 'INVALID-CART-DISCOUNT'
[allowedTypes.discountCode]: (options) => {
const service = new DiscountCodeImporter(
Object.assign({}, options.config, {
apiConfig: {
host: options.authHost,
projectKey: options.credentials.project_key,
credentials: {
clientId: options.credentials.client_id,
clientSecret: options.credentials.client_secret,
},
apiUrl: options.host,
protocol: options.protocol,
oauth_protocol: options.authProtocol,
},
accessToken: options.accessToken,
batchSize: options.batch,
}),
log,