Skip to content

Commit

Permalink
Added tests for redeemables.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaliszuk committed Mar 25, 2024
1 parent c05d95f commit 8113612
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/sdk/test/customers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { voucherifyClient as client } from './client'
import { generateRandomString } from './utils/generateRandomString'
import { generateCustomerCSV } from './utils/generateCustomerCSV'
import { CustomerRequest, DiscountVouchersTypesEnum, DistributionsPublicationsCreateParams } from '@voucherify/sdk'

jest.setTimeout(15000)

Expand Down Expand Up @@ -173,4 +174,34 @@ describe('Customers API', () => {
}
expect(updatedCustomerWithNoAddress.address).toEqual(removedAddress)
})

it('Should return redeemable for customer', async () => {
const createdCustomer: CustomerRequest = await client.customers.create({ source_id: generateRandomString() })

const discountCampaign = await client.campaigns.create({
campaign_type: 'DISCOUNT_COUPONS',
name: generateRandomString(),
type: 'AUTO_UPDATE',
voucher: {
code_config: {
length: 3,
},
type: 'DISCOUNT_VOUCHER',
discount: {
amount_off: 0,
type: DiscountVouchersTypesEnum.AMOUNT,
},
},
})

const distributionsPublicationsCreateParams: DistributionsPublicationsCreateParams = {
customer: createdCustomer,
campaign: discountCampaign,
}

await client.distributions.publications.create(distributionsPublicationsCreateParams)

const redeemables = await client.customers.listRedeemables(createdCustomer.id as string)
expect(redeemables.data).toBeDefined()
})
})
41 changes: 41 additions & 0 deletions packages/sdk/test/referrals.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { voucherifyClient as client } from './client'
import { generateRandomString } from './utils/generateRandomString'
import { CustomerRequest, DiscountVouchersTypesEnum, DistributionsPublicationsCreateParams } from '@voucherify/sdk'

jest.setTimeout(15000)

describe('Referrals API', () => {
it('Should return redeemable holders for campaign and member', async () => {
const createdCustomer: CustomerRequest = await client.customers.create({ source_id: generateRandomString() })

const referralCampaign = await client.campaigns.create({
campaign_type: 'REFERRAL_PROGRAM',
name: generateRandomString(),
type: 'AUTO_UPDATE',
voucher: {
code_config: {
length: 3,
},
type: 'DISCOUNT_VOUCHER',
discount: {
amount_off: 0,
type: DiscountVouchersTypesEnum.AMOUNT,
},
is_referral_code: true,
},
})

const distributionsPublicationsCreateParams: DistributionsPublicationsCreateParams = {
customer: createdCustomer,
campaign: referralCampaign,
}

const publication = await client.distributions.publications.create(distributionsPublicationsCreateParams)

const redeemables = await client.referrals.listHolders(referralCampaign.id, publication.voucher.id)
expect(redeemables.data).toBeDefined()

const redeemables2 = await client.referrals.listHolders(null, publication.voucher.id)
expect(redeemables2.data).toBeDefined()
})
})

0 comments on commit 8113612

Please sign in to comment.