How to use @commercetools/discount-code-importer - 3 common examples

To help you get started, we’ve selected a few @commercetools/discount-code-importer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / nodejs / integration-tests / cli / discount-codes.it.js View on Github external
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/)
github commercetools / nodejs / integration-tests / cli / discount-codes.it.js View on Github external
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'
github sphereio / sphere-node-cli / lib / commands / import.js View on Github external
[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,

@commercetools/discount-code-importer

Import discount codes to the commercetools platform.

MIT
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis

Popular @commercetools/discount-code-importer functions