|
@@ -136,35 +136,118 @@ it.each(['cash', 'pay_stack'])('keeps the exact legacy %s request and payment re
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-it('keeps MARKET_PRICE totals, BV and legacy tax for a range of stock quantities', async() => {
|
|
|
|
|
|
|
+it.each([0, '0', 100, '100.25'])('uses member price %s for totals, BV and inclusive tax across stock quantities', async price => {
|
|
|
|
|
+ user.fetchWelcomePack.mockImplementation(async() => {
|
|
|
|
|
+ const response = settings()
|
|
|
|
|
+ response.data.allGoods[0].SELL_PRICE = price
|
|
|
|
|
+ return response
|
|
|
|
|
+ })
|
|
|
const vm = await order()
|
|
const vm = await order()
|
|
|
for (let quantity = 1; quantity <= 10; quantity++) {
|
|
for (let quantity = 1; quantity <= 10; quantity++) {
|
|
|
vm.changeProductQuantity({ row: vm.tableData[0], index: 0, value: quantity })
|
|
vm.changeProductQuantity({ row: vm.tableData[0], index: 0, value: quantity })
|
|
|
vm.selectProduct()
|
|
vm.selectProduct()
|
|
|
expect(vm.form.goodsNum).toEqual([quantity])
|
|
expect(vm.form.goodsNum).toEqual([quantity])
|
|
|
- expect(Number(vm.sellPriceSum)).toBe(120 * quantity)
|
|
|
|
|
|
|
+ expect(Number(vm.sellPriceSum)).toBe(Number(price) * quantity)
|
|
|
expect(Number(vm.pricePvSum)).toBe(60 * quantity)
|
|
expect(Number(vm.pricePvSum)).toBe(60 * quantity)
|
|
|
- expect(vm.payAmount).toBe(120 * quantity)
|
|
|
|
|
- expect(Number(vm.taxSum)).toBe(Number((120 * quantity * 7.5 / 107.5).toFixed(2)))
|
|
|
|
|
|
|
+ expect(vm.payAmount).toBe(Number(price) * quantity)
|
|
|
|
|
+ expect(Number(vm.taxSum)).toBe(Number((Number(price) * quantity * 7.5 / 107.5).toFixed(2)))
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+it('matches the member card price with subtotal, tax, payment summary and product details', async() => {
|
|
|
|
|
+ user.fetchWelcomePack.mockImplementation(async() => {
|
|
|
|
|
+ const response = settings()
|
|
|
|
|
+ response.data.allGoods[0] = { ...product, SELL_PRICE: '199000.00', MARKET_PRICE: '299900.00', PRICE_PV: '70' }
|
|
|
|
|
+ response.data.userBalance.cash = 250000
|
|
|
|
|
+ return response
|
|
|
|
|
+ })
|
|
|
|
|
+ const vm = await order()
|
|
|
|
|
+ vm.form.payType = 'cash'
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-signup-product-price strong').textContent).toBe('NGN 199,000')
|
|
|
|
|
+ const totals = vm.$el.querySelector('.ng-signup-totals').textContent
|
|
|
|
|
+ expect(totals).toContain('NGN 199,000')
|
|
|
|
|
+ expect(totals).toContain('NGN 13,883.72')
|
|
|
|
|
+ const payment = vm.$el.querySelector('.ng-payment-methods-detail').textContent
|
|
|
|
|
+ expect(payment).toContain('NGN 199,000')
|
|
|
|
|
+ expect(payment).toContain('NGN 51,000')
|
|
|
|
|
+ expect(payment).not.toContain('not enough to cover this order')
|
|
|
|
|
+ vm.$el.querySelector('.ng-signup-product-view').click()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.product.taxAmount).toBe(13883.72)
|
|
|
|
|
+ expect(document.body.querySelector('.ng-product-details-dialog').textContent).toContain('NGN 13,883.72')
|
|
|
|
|
+ expect(vm.tableData[0]).toMatchObject({ SELL_PRICE: '199000.00', MARKET_PRICE: '299900.00' })
|
|
|
|
|
+ vm.onSubmit()
|
|
|
|
|
+ expect(vm.payAmount).toBe(199000)
|
|
|
|
|
+ expect(user.createWelcomePack).toHaveBeenCalledTimes(1)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it.each([100, 119])('accepts cash balance %s when it covers the member price but not the market price', async balance => {
|
|
|
|
|
+ const vm = await order()
|
|
|
|
|
+ vm.userBalance.cash = balance
|
|
|
|
|
+ vm.form.payType = 'cash'
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.$el.textContent).not.toContain('not enough to cover this order')
|
|
|
|
|
+ vm.onSubmit()
|
|
|
|
|
+ expect(vm.payAmount).toBe(100)
|
|
|
|
|
+ expect(user.createWelcomePack).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(vm.userBalance.cash).toBe(balance)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it('recalculates multiple member products and clears all totals when they are removed', async() => {
|
|
|
|
|
+ user.fetchWelcomePack.mockImplementation(async() => {
|
|
|
|
|
+ const response = settings()
|
|
|
|
|
+ response.data.allGoods.push({ ...product, ID: 'P2', SELL_PRICE: '73.40', MARKET_PRICE: '99.90', PRICE_PV: '28.4' })
|
|
|
|
|
+ return response
|
|
|
|
|
+ })
|
|
|
|
|
+ const vm = await order()
|
|
|
|
|
+ vm.toggleProduct(vm.tableData[1])
|
|
|
|
|
+ vm.changeProductQuantity({ row: vm.tableData[0], index: 0, value: 3 })
|
|
|
|
|
+ vm.changeProductQuantity({ row: vm.tableData[1], index: 1, value: 2 })
|
|
|
|
|
+ vm.selectProduct()
|
|
|
|
|
+ expect(Number(vm.sellPriceSum)).toBe(446.8)
|
|
|
|
|
+ expect(vm.payAmount).toBe(446.8)
|
|
|
|
|
+ expect(Number(vm.pricePvSum)).toBe(236.8)
|
|
|
|
|
+ expect(Number(vm.taxSum)).toBe(31.17)
|
|
|
|
|
+ expect(vm.form.goodsId).toEqual(['P1', 'P2'])
|
|
|
|
|
+ expect(vm.form.goodsNum).toEqual([3, 2])
|
|
|
|
|
+ vm.tableData.slice().forEach(row => vm.toggleProduct(row))
|
|
|
|
|
+ vm.selectProduct()
|
|
|
|
|
+ expect(Number(vm.sellPriceSum)).toBe(0)
|
|
|
|
|
+ expect(Number(vm.pricePvSum)).toBe(0)
|
|
|
|
|
+ expect(Number(vm.taxSum)).toBe(0)
|
|
|
|
|
+ expect(vm.payAmount).toBe(0)
|
|
|
|
|
+ expect(vm.form.goodsId).toEqual([])
|
|
|
|
|
+ expect(vm.form.goodsNum).toEqual([])
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it('preserves the old page market-price calculations', () => {
|
|
|
|
|
+ const vm = mount({ ...Legacy, created: undefined, render: h => h('div') })
|
|
|
|
|
+ vm.multipleSelection = [{ ...product, goodsNum: 1 }]
|
|
|
|
|
+ vm.handleSureChange()
|
|
|
|
|
+ vm.selectProduct()
|
|
|
|
|
+ expect(Number(vm.sellPriceSum)).toBe(120)
|
|
|
|
|
+ expect(vm.payAmount).toBe(120)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
it('shows balance shortage without changing the original balance or submitting', async() => {
|
|
it('shows balance shortage without changing the original balance or submitting', async() => {
|
|
|
const vm = await order()
|
|
const vm = await order()
|
|
|
- vm.userBalance.cash = 119
|
|
|
|
|
|
|
+ vm.userBalance.cash = 99
|
|
|
vm.form.payType = 'cash'
|
|
vm.form.payType = 'cash'
|
|
|
await settle()
|
|
await settle()
|
|
|
expect(vm.$el.textContent).toContain('not enough to cover this order')
|
|
expect(vm.$el.textContent).toContain('not enough to cover this order')
|
|
|
expect(vm.$el.textContent).toContain('Balance after payment')
|
|
expect(vm.$el.textContent).toContain('Balance after payment')
|
|
|
vm.onSubmit()
|
|
vm.onSubmit()
|
|
|
expect(user.createWelcomePack).not.toHaveBeenCalled()
|
|
expect(user.createWelcomePack).not.toHaveBeenCalled()
|
|
|
- expect(vm.userBalance.cash).toBe(119)
|
|
|
|
|
|
|
+ expect(vm.userBalance.cash).toBe(99)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('keeps editable fields and pickup events connected without changing the legacy request fields', async() => {
|
|
it('keeps editable fields and pickup events connected without changing the legacy request fields', async() => {
|
|
|
const vm = await order()
|
|
const vm = await order()
|
|
|
- const fields = vm.$children[0].$children.find(child => child.$options.name === 'WelcomePackFields')
|
|
|
|
|
- fields.$emit('change', { realName: 'Updated member', way: 'pickup' })
|
|
|
|
|
|
|
+ const name = vm.$el.querySelector('#ng-welcome-realName')
|
|
|
|
|
+ name.value = 'Updated member'
|
|
|
|
|
+ name.dispatchEvent(new Event('input', { bubbles: true }))
|
|
|
|
|
+ vm.$el.querySelector('input[type="radio"][value="pickup"]').click()
|
|
|
await settle()
|
|
await settle()
|
|
|
expect(vm.form.realName).toBe('Updated member')
|
|
expect(vm.form.realName).toBe('Updated member')
|
|
|
expect(vm.areaDisabled).toBe(true)
|
|
expect(vm.areaDisabled).toBe(true)
|