|
@@ -10,7 +10,7 @@ jest.mock('@/router', () => ({ push: jest.fn(), replace: jest.fn() }))
|
|
|
|
|
|
|
|
const product = { ID: 'P1', GOODS_NAME: 'Product', SELL_PRICE: 100, MARKET_PRICE: 120, DISCOUNT: 80, STORE_NUMS: 5, TAX_RATE: 7.5, COIN: 'NGN' }
|
|
const product = { ID: 'P1', GOODS_NAME: 'Product', SELL_PRICE: 100, MARKET_PRICE: 120, DISCOUNT: 80, STORE_NUMS: 5, TAX_RATE: 7.5, COIN: 'NGN' }
|
|
|
const instances = []
|
|
const instances = []
|
|
|
-const shipping = { consignee: 'Recipient', acceptMobile: '123456789', province: ['R1'], lgaName: 'District', cityName: 'City', detailaddress: 'Street', email: 'guest@example.test' }
|
|
|
|
|
|
|
+const shipping = { consignee: 'Recipient', acceptMobile: '123456789', province: ['R1'], lgaName: 'District', cityName: 'City', detailaddress: 'Street' }
|
|
|
async function settle() { for (let i = 0; i < 12; i++) { await Promise.resolve(); await Vue.nextTick() } }
|
|
async function settle() { for (let i = 0; i < 12; i++) { await Promise.resolve(); await Vue.nextTick() } }
|
|
|
async function instance(market = 'ng', stage = 'catalog') {
|
|
async function instance(market = 'ng', stage = 'catalog') {
|
|
|
const vm = new (Vue.extend(behavior))({ propsData: { market, stage }})
|
|
const vm = new (Vue.extend(behavior))({ propsData: { market, stage }})
|
|
@@ -36,7 +36,7 @@ beforeEach(() => {
|
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [product], totalCount: 1 }})
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [product], totalCount: 1 }})
|
|
|
shop.fetchGuestCart.mockResolvedValue({ data: { sellType: [{ id: 1, sell_type: [{ label: 'pay_stack', name: 'Paystack' }] }], freight: 10, freeShipping: 500, coin: 'NGN' }})
|
|
shop.fetchGuestCart.mockResolvedValue({ data: { sellType: [{ id: 1, sell_type: [{ label: 'pay_stack', name: 'Paystack' }] }], freight: 10, freeShipping: 500, coin: 'NGN' }})
|
|
|
getGuestRegionList.mockResolvedValue({ data: [{ value: 'R1', label: 'Region' }] })
|
|
getGuestRegionList.mockResolvedValue({ data: [{ value: 'R1', label: 'Region' }] })
|
|
|
- shop.createGuestOrder.mockResolvedValue({ data: { SN: 'ORDER1', amount: 130, currency: 'NGN' }})
|
|
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'ORDER1', amount: 130, currency: 'NGN', EMAIL: 'guest@example.test' }})
|
|
|
})
|
|
})
|
|
|
afterEach(() => { instances.splice(0).forEach(vm => vm.$destroy()) })
|
|
afterEach(() => { instances.splice(0).forEach(vm => vm.$destroy()) })
|
|
|
|
|
|
|
@@ -124,22 +124,36 @@ it('keeps selections across pages and rejects unavailable or fractional quantiti
|
|
|
vm.toggleProduct({ ...product, ID: 'P3', STORE_NUMS: 0 })
|
|
vm.toggleProduct({ ...product, ID: 'P3', STORE_NUMS: 0 })
|
|
|
expect(vm.items).toHaveLength(2)
|
|
expect(vm.items).toHaveLength(2)
|
|
|
})
|
|
})
|
|
|
-it('requires shipping and email before calling the order API, with no passwords or member identity', async() => {
|
|
|
|
|
|
|
+it('requires shipping but no email input before calling the order API, with no passwords or member identity', async() => {
|
|
|
const vm = await instance()
|
|
const vm = await instance()
|
|
|
vm.toggleProduct(product)
|
|
vm.toggleProduct(product)
|
|
|
vm.stage = 'checkout'
|
|
vm.stage = 'checkout'
|
|
|
await settle()
|
|
await settle()
|
|
|
vm.openEmail()
|
|
vm.openEmail()
|
|
|
expect(vm.emailVisible).toBe(false)
|
|
expect(vm.emailVisible).toBe(false)
|
|
|
- Object.assign(vm.form, shipping, { email: 'invalid' })
|
|
|
|
|
|
|
+ Object.assign(vm.form, shipping)
|
|
|
vm.openEmail()
|
|
vm.openEmail()
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
- expect(shop.createGuestOrder).not.toHaveBeenCalled()
|
|
|
|
|
- vm.form.email = shipping.email
|
|
|
|
|
- await vm.continuePayment()
|
|
|
|
|
- expect(shop.createGuestOrder).toHaveBeenCalledWith({ ...shipping, countryId: '620699181539139625', goodsId: ['P1'], goodsNum: [1], payType: 'pay_stack' })
|
|
|
|
|
|
|
+ expect(shop.createGuestOrder).toHaveBeenCalledWith({ ...shipping, email: '', countryId: '620699181539139625', goodsId: ['P1'], goodsNum: [1], payType: 'pay_stack' })
|
|
|
|
|
+ expect(vm.form.email).toBe('guest@example.test')
|
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
})
|
|
|
|
|
+it.each([undefined, '', 'invalid', null, 123])('retains the order and reports a missing or invalid server payment email %s without creating another order', async email => {
|
|
|
|
|
+ const vm = await checkout()
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'ORDER1', amount: 130, currency: 'NGN', EMAIL: email }})
|
|
|
|
|
+ await vm.continuePayment()
|
|
|
|
|
+ expect(shop.createGuestOrder).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(vm.pending.SN).toBe('ORDER1')
|
|
|
|
|
+ expect(vm.sdkActive).toBe(false)
|
|
|
|
|
+ expect(vm.submitting).toBe(false)
|
|
|
|
|
+ expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|
|
|
|
|
+ expect(vm.$message.error).toHaveBeenCalledWith('The order did not return a valid payment email. Please contact customer service with your order number.')
|
|
|
|
|
+ vm.closePayment()
|
|
|
|
|
+ vm.openEmail()
|
|
|
|
|
+ await vm.continuePayment()
|
|
|
|
|
+ expect(shop.createGuestOrder).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|
|
|
|
|
+})
|
|
|
it('blocks duplicate submit and retains the same unpaid order after cancellation', async() => {
|
|
it('blocks duplicate submit and retains the same unpaid order after cancellation', async() => {
|
|
|
const vm = await checkout()
|
|
const vm = await checkout()
|
|
|
let resolve
|
|
let resolve
|
|
@@ -147,7 +161,7 @@ it('blocks duplicate submit and retains the same unpaid order after cancellation
|
|
|
const first = vm.continuePayment()
|
|
const first = vm.continuePayment()
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
expect(shop.createGuestOrder).toHaveBeenCalledTimes(1)
|
|
expect(shop.createGuestOrder).toHaveBeenCalledTimes(1)
|
|
|
- resolve({ data: { SN: 'ORDER1', amount: 130, currency: 'NGN' }})
|
|
|
|
|
|
|
+ resolve({ data: { SN: 'ORDER1', amount: 130, currency: 'NGN', EMAIL: 'guest@example.test' }})
|
|
|
await first
|
|
await first
|
|
|
const callback = vm.paymentCallback
|
|
const callback = vm.paymentCallback
|
|
|
vm.closePayment()
|
|
vm.closePayment()
|
|
@@ -166,7 +180,7 @@ it('blocks duplicate submit and retains the same unpaid order after cancellation
|
|
|
})
|
|
})
|
|
|
it('requires review of a changed server payment amount and currency before starting the SDK', async() => {
|
|
it('requires review of a changed server payment amount and currency before starting the SDK', async() => {
|
|
|
const vm = await checkout()
|
|
const vm = await checkout()
|
|
|
- shop.createGuestOrder.mockResolvedValue({ data: { SN: 'ORDER1', amount: 10, currency: 'USD' }})
|
|
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'ORDER1', amount: 10, currency: 'USD', EMAIL: 'guest@example.test' }})
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
expect(vm.pending.currency).toBe('USD')
|
|
expect(vm.pending.currency).toBe('USD')
|
|
|
expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|
|
expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|
|
@@ -185,12 +199,12 @@ it.each([
|
|
|
vm.stage = 'checkout'
|
|
vm.stage = 'checkout'
|
|
|
await settle()
|
|
await settle()
|
|
|
vm.openEmail()
|
|
vm.openEmail()
|
|
|
- shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', DEC_SN: 'DECLARATION1', COUNTRY_ID: countryId, CURRENCY_ID: currencyId, PAY_AMOUNT: 130, ORDER_AMOUNT: 150, PAY_AMOUNT_STANDARD: 0.075, EXCHANGE_RATE: '1200', EMAIL: '', STATUS: 1 }})
|
|
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', DEC_SN: 'DECLARATION1', COUNTRY_ID: countryId, CURRENCY_ID: currencyId, PAY_AMOUNT: 130, ORDER_AMOUNT: 150, PAY_AMOUNT_STANDARD: 0.075, EXCHANGE_RATE: '1200', EMAIL: ' guest@example.test ', STATUS: 1 }})
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
expect(vm.pending).toEqual({ SN: 'RECORD1', amount: 130, currency, subunits: 13000 })
|
|
expect(vm.pending).toEqual({ SN: 'RECORD1', amount: 130, currency, subunits: 13000 })
|
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
|
expect(vm.metadata.cart_id).toBe('RECORD1')
|
|
expect(vm.metadata.cart_id).toBe('RECORD1')
|
|
|
- expect(vm.form.email).toBe(shipping.email)
|
|
|
|
|
|
|
+ expect(vm.form.email).toBe('guest@example.test')
|
|
|
expect(vm.$router.push).not.toHaveBeenCalled()
|
|
expect(vm.$router.push).not.toHaveBeenCalled()
|
|
|
vm.closePayment()
|
|
vm.closePayment()
|
|
|
vm.openEmail()
|
|
vm.openEmail()
|
|
@@ -201,15 +215,15 @@ it.each([
|
|
|
it('accepts ORDER_AMOUNT when the returned order record has no PAY_AMOUNT', async() => {
|
|
it('accepts ORDER_AMOUNT when the returned order record has no PAY_AMOUNT', async() => {
|
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [{ ...product, LOCAL_CURRENCY_ID: '104' }], totalCount: 1 }})
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [{ ...product, LOCAL_CURRENCY_ID: '104' }], totalCount: 1 }})
|
|
|
const vm = await checkout()
|
|
const vm = await checkout()
|
|
|
- shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', COUNTRY_ID: '620699181539139625', CURRENCY_ID: '104', ORDER_AMOUNT: 130 }})
|
|
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', COUNTRY_ID: '620699181539139625', CURRENCY_ID: '104', ORDER_AMOUNT: 130, EMAIL: 'guest@example.test' }})
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
expect(vm.pending).toEqual({ SN: 'RECORD1', amount: 130, currency: 'NGN', subunits: 13000 })
|
|
expect(vm.pending).toEqual({ SN: 'RECORD1', amount: 130, currency: 'NGN', subunits: 13000 })
|
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
expect(vm.$refs.paystack.payWithPaystack).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
})
|
|
|
-it('updates the email amount and requests confirmation when the order record changes the total', async() => {
|
|
|
|
|
|
|
+it('updates the payment amount and requests confirmation when the order record changes the total', async() => {
|
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [{ ...product, LOCAL_CURRENCY_ID: '104' }], totalCount: 1 }})
|
|
shop.fetchGuestProducts.mockResolvedValue({ data: { list: [{ ...product, LOCAL_CURRENCY_ID: '104' }], totalCount: 1 }})
|
|
|
const vm = await checkout()
|
|
const vm = await checkout()
|
|
|
- shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', COUNTRY_ID: '620699181539139625', CURRENCY_ID: '104', PAY_AMOUNT: 95 }})
|
|
|
|
|
|
|
+ shop.createGuestOrder.mockResolvedValue({ data: { SN: 'RECORD1', COUNTRY_ID: '620699181539139625', CURRENCY_ID: '104', PAY_AMOUNT: 95, EMAIL: 'guest@example.test' }})
|
|
|
await vm.continuePayment()
|
|
await vm.continuePayment()
|
|
|
expect(vm.pending.amount).toBe(95)
|
|
expect(vm.pending.amount).toBe(95)
|
|
|
expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|
|
expect(vm.$refs.paystack.payWithPaystack).not.toHaveBeenCalled()
|