|
@@ -52,7 +52,7 @@ async function instance(source = names[0]) {
|
|
|
async function withProducts(source = names[0]) {
|
|
async function withProducts(source = names[0]) {
|
|
|
const vm = await instance(source)
|
|
const vm = await instance(source)
|
|
|
if (!vm.isSelf) { vm.memberSearch = 'NG2'; await settle(); await vm.searchMember(); await settle() }
|
|
if (!vm.isSelf) { vm.memberSearch = 'NG2'; await settle(); await vm.searchMember(); await settle() }
|
|
|
- if (vm.isUpgrade) { vm.form.upgradeValue = { value: 'L2', diffPv: 999 }; vm.handleChangeLevel(vm.form.upgradeValue) }
|
|
|
|
|
|
|
+ if (vm.isUpgrade) { vm.form.upgradeValue = { value: 'L2', diffPv: vm.upgradeOption[0].REPAIR_PV }; vm.handleChangeLevel(vm.form.upgradeValue) }
|
|
|
vm.toggleProduct(vm.tableData[0])
|
|
vm.toggleProduct(vm.tableData[0])
|
|
|
vm.changeQuantity({ row: product, value: 2 })
|
|
vm.changeQuantity({ row: product, value: 2 })
|
|
|
vm.stage = 'checkout'
|
|
vm.stage = 'checkout'
|
|
@@ -110,7 +110,7 @@ beforeEach(() => {
|
|
|
shop.fetchShoppingCart.mockImplementation(async() => settings())
|
|
shop.fetchShoppingCart.mockImplementation(async() => settings())
|
|
|
user.getUserInfo.mockResolvedValue({ data: { IS_DEC: '1' }})
|
|
user.getUserInfo.mockResolvedValue({ data: { IS_DEC: '1' }})
|
|
|
user.fetchFullInfo.mockResolvedValue({ data: { userId: 'U2', countryId: '1', REAL_NAME: 'Target member' }})
|
|
user.fetchFullInfo.mockResolvedValue({ data: { userId: 'U2', countryId: '1', REAL_NAME: 'Target member' }})
|
|
|
- user.fetchUpgradeInfo.mockResolvedValue({ data: { baseInfo: { ADD_AT: '2020-01-01', REAL_NAME: 'Target member', DEC_NAME: 'Silver', IS_MAX: false, LEVEL_LIST: [{ ID: 'L2', LEVEL_NAME: 'Gold', REPAIR_PV: 999 }], UPGRADE_FUNC: 'Product', NOW_PERF: 10, NEXT_PERF: 1009 }}})
|
|
|
|
|
|
|
+ user.fetchUpgradeInfo.mockResolvedValue({ data: { baseInfo: { ADD_AT: '2020-01-01', REAL_NAME: 'Target member', DEC_NAME: 'Silver', IS_MAX: false, LEVEL_LIST: [{ ID: 'L2', LEVEL_NAME: 'Gold', REPAIR_PV: 120 }], UPGRADE_FUNC: 'Product', NOW_PERF: 10, NEXT_PERF: 1009 }}})
|
|
|
user.fetchUpgrade.mockResolvedValue({ data: { userBalance: { cash: 10000 }, decUserName: 'RC1', allDecPackage: {}, allGoods: [product], region: [], sellType: [{ sell_type: payList }] }})
|
|
user.fetchUpgrade.mockResolvedValue({ data: { userBalance: { cash: 10000 }, decUserName: 'RC1', allDecPackage: {}, allGoods: [product], region: [], sellType: [{ sell_type: payList }] }})
|
|
|
getRegionList.mockResolvedValue({ data: [] })
|
|
getRegionList.mockResolvedValue({ data: [] })
|
|
|
;[shop.createOrder, shop.createApproachOrder, shop.createReconsumeOrder, shop.createApproachReconsumeOrder, shop.createAutoMaintenanceOrder, shop.createApproachAutoMaintenanceOrder, user.fetchSendUpgrade].forEach(api => api.mockResolvedValue({ data: { SN: 'ORDER1', ORDER_AMOUNT: 200 }}))
|
|
;[shop.createOrder, shop.createApproachOrder, shop.createReconsumeOrder, shop.createApproachReconsumeOrder, shop.createAutoMaintenanceOrder, shop.createApproachAutoMaintenanceOrder, user.fetchSendUpgrade].forEach(api => api.mockResolvedValue({ data: { SN: 'ORDER1', ORDER_AMOUNT: 200 }}))
|
|
@@ -457,16 +457,82 @@ it('uses the returned maintenance threshold and excludes PRP', async() => {
|
|
|
expect(shop.createAutoMaintenanceOrder).not.toHaveBeenCalled()
|
|
expect(shop.createAutoMaintenanceOrder).not.toHaveBeenCalled()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-it('preserves upgrade information and does not introduce a difference-BV rejection', async() => {
|
|
|
|
|
|
|
+it.each(['cash', 'pay_stack'])('blocks an insufficient upgrade cart and submission with %s', async payType => {
|
|
|
const vm = await withProducts('member-upgrade')
|
|
const vm = await withProducts('member-upgrade')
|
|
|
|
|
+ vm.form.upgradeValue = { value: 'L2', diffPv: 220 }
|
|
|
|
|
+ vm.handleChangeLevel(vm.form.upgradeValue)
|
|
|
|
|
+ vm.stage = 'cart'
|
|
|
|
|
+ await settle()
|
|
|
expect(user.fetchUpgradeInfo).toHaveBeenCalledWith({ userName: 'NG2' })
|
|
expect(user.fetchUpgradeInfo).toHaveBeenCalledWith({ userName: 'NG2' })
|
|
|
expect(user.fetchUpgrade).toHaveBeenCalledWith({ userName: 'NG2' })
|
|
expect(user.fetchUpgrade).toHaveBeenCalledWith({ userName: 'NG2' })
|
|
|
- expect(vm.needDiffPv).toBe(999)
|
|
|
|
|
|
|
+ expect(vm.needDiffPv).toBe(220)
|
|
|
expect(vm.pricePvSum).toBe('120.00')
|
|
expect(vm.pricePvSum).toBe('120.00')
|
|
|
- vm.activePayType = 'cash'
|
|
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade.is-insufficient')).not.toBeNull()
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade-warning').textContent).toContain('Cart BV (120) must be ≥ 220 BV to upgrade to Gold.')
|
|
|
|
|
+ const button = vm.$el.querySelector('.ng-purchase-summary .el-button--primary')
|
|
|
|
|
+ expect(button.disabled).toBe(true)
|
|
|
|
|
+ router.push.mockClear()
|
|
|
|
|
+ button.click()
|
|
|
|
|
+ vm.navigate('checkout')
|
|
|
|
|
+ expect(router.push).not.toHaveBeenCalled()
|
|
|
|
|
+ vm.stage = 'checkout'
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(router.push).toHaveBeenCalledWith(expect.objectContaining({ path: '/dashboard/cart' }))
|
|
|
|
|
+ vm.activePayType = payType
|
|
|
vm.submitOrder()
|
|
vm.submitOrder()
|
|
|
await settle()
|
|
await settle()
|
|
|
- expect(user.fetchSendUpgrade).toHaveBeenCalledWith(expect.objectContaining({ decLv: 'L2', insertUserName: 'NG2', goodsId: ['P1'], goodsNum: [2], province: 'S1', nowPerf: 10, nextPerf: 1009 }))
|
|
|
|
|
|
|
+ expect(user.fetchSendUpgrade).not.toHaveBeenCalled()
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it('updates upgrade eligibility when quantity or the target level changes', async() => {
|
|
|
|
|
+ const vm = await withProducts('member-upgrade')
|
|
|
|
|
+ vm.stage = 'cart'
|
|
|
|
|
+ vm.form.upgradeValue = { value: 'L2', diffPv: '220' }
|
|
|
|
|
+ vm.handleChangeLevel(vm.form.upgradeValue)
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+ vm.changeQuantity({ row: product, value: 4 })
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.pricePvSum).toBe('240.00')
|
|
|
|
|
+ expect(vm.canCheckout).toBe(true)
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade.is-sufficient')).not.toBeNull()
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade-warning')).toBeNull()
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-summary .el-button--primary').disabled).toBe(false)
|
|
|
|
|
+ vm.upgradeOption.push({ ID: 'L3', LEVEL_NAME: 'Platinum', REPAIR_PV: '300' })
|
|
|
|
|
+ vm.form.upgradeValue = { value: 'L3', diffPv: '300' }
|
|
|
|
|
+ vm.handleChangeLevel(vm.form.upgradeValue)
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade-warning').textContent).toContain('≥ 300 BV to upgrade to Platinum.')
|
|
|
|
|
+ vm.changeQuantity({ row: product, value: 5 })
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.pricePvSum).toBe('300.00')
|
|
|
|
|
+ expect(vm.canCheckout).toBe(true)
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade.is-sufficient')).not.toBeNull()
|
|
|
|
|
+ vm.changeQuantity({ row: product, value: 4 })
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it.each([undefined, null, '', -1, 'bad', Infinity])('blocks upgrading when the required BV is invalid: %s', async difference => {
|
|
|
|
|
+ const vm = await withProducts('member-upgrade')
|
|
|
|
|
+ vm.handleChangeLevel({ value: 'L2', diffPv: difference })
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+ vm.submitOrder()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(user.fetchSendUpgrade).not.toHaveBeenCalled()
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+it('allows equality, zero and numeric string upgrade requirements across stock quantities', async() => {
|
|
|
|
|
+ const vm = await withProducts('member-upgrade')
|
|
|
|
|
+ for (const difference of [0, '0', 60, '120', 220]) {
|
|
|
|
|
+ vm.handleChangeLevel({ value: 'L2', diffPv: difference })
|
|
|
|
|
+ for (let quantity = 1; quantity <= product.STORE_NUMS; quantity++) {
|
|
|
|
|
+ vm.changeQuantity({ row: product, value: quantity })
|
|
|
|
|
+ expect(vm.canCheckout).toBe(quantity * 60 >= Number(difference))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it.each([NaN, 0, -1, 1.5, 10, Infinity])('rejects invalid quantity %s without corrupting totals', async quantity => {
|
|
it.each([NaN, 0, -1, 1.5, 10, Infinity])('rejects invalid quantity %s without corrupting totals', async quantity => {
|
|
@@ -556,7 +622,7 @@ it('does not add a Reporting Center ID requirement to the upgrade request', asyn
|
|
|
expect(user.fetchSendUpgrade).toHaveBeenCalledWith(expect.objectContaining({ decUserName: '' }))
|
|
expect(user.fetchSendUpgrade).toHaveBeenCalledWith(expect.objectContaining({ decUserName: '' }))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-it.each(submissions)('%s submits once, preserving the original member and delivery fields', async(source, api, unused, destination) => {
|
|
|
|
|
|
|
+it.each(submissions)('%s submits once, preserving the original member and delivery fields', async(source, api) => {
|
|
|
const vm = await withProducts(source)
|
|
const vm = await withProducts(source)
|
|
|
vm.activePayType = 'cash'
|
|
vm.activePayType = 'cash'
|
|
|
vm.submitOrder()
|
|
vm.submitOrder()
|
|
@@ -569,7 +635,7 @@ it.each(submissions)('%s submits once, preserving the original member and delive
|
|
|
expect(sent.payType).toBe('cash')
|
|
expect(sent.payType).toBe('cash')
|
|
|
if (vm.isSelf) expect(sent).toEqual({ goodsId: ['P1'], goodsNum: [2], payPassword: 'fixture-password', email: 'operator@example.test', addressId: 'A1', address: undefined, payType: 'cash', userName: 'RC1' })
|
|
if (vm.isSelf) expect(sent).toEqual({ goodsId: ['P1'], goodsNum: [2], payPassword: 'fixture-password', email: 'operator@example.test', addressId: 'A1', address: undefined, payType: 'cash', userName: 'RC1' })
|
|
|
else if (!vm.isUpgrade) expect(sent).toEqual({ goodsId: ['P1'], goodsNum: [2], payPassword: 'fixture-password', email: 'operator@example.test', addressId: 'A1', payType: 'cash', userName: 'NG2', consignee: 'Recipient', acceptMobile: '123', province: ['S1'], lgaName: 'District', cityName: 'City', detailaddress: 'Street', decUserName: 'RC1' })
|
|
else if (!vm.isUpgrade) expect(sent).toEqual({ goodsId: ['P1'], goodsNum: [2], payPassword: 'fixture-password', email: 'operator@example.test', addressId: 'A1', payType: 'cash', userName: 'NG2', consignee: 'Recipient', acceptMobile: '123', province: ['S1'], lgaName: 'District', cityName: 'City', detailaddress: 'Street', decUserName: 'RC1' })
|
|
|
- expect(router.push).toHaveBeenLastCalledWith({ path: destination })
|
|
|
|
|
|
|
+ expect(router.push).toHaveBeenLastCalledWith({ path: '/guest-order', query: { order: 'ORDER1' }})
|
|
|
expect(vm.cartItems).toEqual([])
|
|
expect(vm.cartItems).toEqual([])
|
|
|
expect(drafts.readDraft(source, 'OP1:login-1')).toBeNull()
|
|
expect(drafts.readDraft(source, 'OP1:login-1')).toBeNull()
|
|
|
})
|
|
})
|
|
@@ -621,12 +687,14 @@ it('handles cancellation failure and accepts a payment callback only once', asyn
|
|
|
expect(vm.visible).toBe(true)
|
|
expect(vm.visible).toBe(true)
|
|
|
expect(vm.cartItems).toHaveLength(1)
|
|
expect(vm.cartItems).toHaveLength(1)
|
|
|
vm.processPayment()
|
|
vm.processPayment()
|
|
|
- const timer = vm.countdownTimer
|
|
|
|
|
|
|
+ expect(router.push).toHaveBeenCalledWith({ path: '/guest-order', query: { order: 'ORDER1' }})
|
|
|
|
|
+ const navigationCount = router.push.mock.calls.length
|
|
|
vm.processPayment()
|
|
vm.processPayment()
|
|
|
- expect(vm.countdownTimer).toBe(timer)
|
|
|
|
|
|
|
+ expect(vm.payDialog).toBe(false)
|
|
|
|
|
+ expect(vm.countdownTimer).toBeNull()
|
|
|
expect(vm.cartItems).toEqual([])
|
|
expect(vm.cartItems).toEqual([])
|
|
|
jest.advanceTimersByTime(5000)
|
|
jest.advanceTimersByTime(5000)
|
|
|
- expect(router.push).toHaveBeenLastCalledWith({ path: '/shop/member-order' })
|
|
|
|
|
|
|
+ expect(router.push).toHaveBeenCalledTimes(navigationCount)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it.each(submissions)('%s matches the actual legacy submission payload', async(source, api) => {
|
|
it.each(submissions)('%s matches the actual legacy submission payload', async(source, api) => {
|
|
@@ -789,7 +857,7 @@ it('restricts cart origins and keeps all six new routes out of the login whiteli
|
|
|
;['__proto__', 'https://example.test', '', undefined].forEach(source => expect(routes.purchasePath(source)).toBe('/dashboard/index'))
|
|
;['__proto__', 'https://example.test', '', undefined].forEach(source => expect(routes.purchasePath(source)).toBe('/dashboard/index'))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-it.each(['cart', 'checkout'])('selects the upgrade level through the %s UI and submits the original fields without a new BV gate', async stage => {
|
|
|
|
|
|
|
+it.each(['cart', 'checkout'])('selects an eligible upgrade level through the %s UI and submits the original fields', async stage => {
|
|
|
const vm = await withProducts('member-upgrade')
|
|
const vm = await withProducts('member-upgrade')
|
|
|
vm.form.upgradeValue = ''
|
|
vm.form.upgradeValue = ''
|
|
|
vm.toLevel = ''
|
|
vm.toLevel = ''
|
|
@@ -800,15 +868,16 @@ it.each(['cart', 'checkout'])('selects the upgrade level through the %s UI and s
|
|
|
const input = vm.$el.querySelector('#ng-purchase-upgrade-level')
|
|
const input = vm.$el.querySelector('#ng-purchase-upgrade-level')
|
|
|
expect(input).not.toBeNull()
|
|
expect(input).not.toBeNull()
|
|
|
expect(vm.$el.querySelector('.ng-purchase-upgrade').textContent).toMatch(/Upgrade difference\s*—/)
|
|
expect(vm.$el.querySelector('.ng-purchase-upgrade').textContent).toMatch(/Upgrade difference\s*—/)
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
input.click()
|
|
input.click()
|
|
|
await settle()
|
|
await settle()
|
|
|
const option = Array.from(document.querySelectorAll('.ng-refactor-popper .el-select-dropdown__item')).find(node => node.textContent.trim() === 'Gold')
|
|
const option = Array.from(document.querySelectorAll('.ng-refactor-popper .el-select-dropdown__item')).find(node => node.textContent.trim() === 'Gold')
|
|
|
expect(option).toBeDefined()
|
|
expect(option).toBeDefined()
|
|
|
option.click()
|
|
option.click()
|
|
|
await settle()
|
|
await settle()
|
|
|
- expect(vm.form.upgradeValue).toEqual({ value: 'L2', diffPv: 999 })
|
|
|
|
|
|
|
+ expect(vm.form.upgradeValue).toEqual({ value: 'L2', diffPv: 120 })
|
|
|
expect(vm.toLevel).toBe('L2')
|
|
expect(vm.toLevel).toBe('L2')
|
|
|
- expect(vm.needDiffPv).toBe(999)
|
|
|
|
|
|
|
+ expect(vm.needDiffPv).toBe(120)
|
|
|
expect(Number(vm.pricePvSum)).toBe(120)
|
|
expect(Number(vm.pricePvSum)).toBe(120)
|
|
|
expect(vm.canCheckout).toBe(true)
|
|
expect(vm.canCheckout).toBe(true)
|
|
|
vm.stage = stage === 'cart' ? 'checkout' : 'cart'
|
|
vm.stage = stage === 'cart' ? 'checkout' : 'cart'
|
|
@@ -842,6 +911,36 @@ it('displays an interface-provided zero upgrade difference without replacing it
|
|
|
expect(vm.$el.querySelector('.ng-purchase-upgrade').textContent).toMatch(/Upgrade difference\s*0 BV/)
|
|
expect(vm.$el.querySelector('.ng-purchase-upgrade').textContent).toMatch(/Upgrade difference\s*0 BV/)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+it.each(['cart', 'checkout'])('selects an object-keyed upgrade level in %s without a render error when BV is insufficient', async stage => {
|
|
|
|
|
+ const response = { data: { baseInfo: { REAL_NAME: 'Target member', DEC_NAME: 'Silver', IS_MAX: false, LEVEL_LIST: { 4: { ID: '4', LEVEL_NAME: 'Gold', REPAIR_PV: '220' }}, NOW_PERF: 10, NEXT_PERF: 230 }}}
|
|
|
|
|
+ user.fetchUpgradeInfo.mockResolvedValue(response)
|
|
|
|
|
+ const vm = await instance('member-upgrade')
|
|
|
|
|
+ vm.memberSearch = 'NG2'
|
|
|
|
|
+ await vm.searchMember()
|
|
|
|
|
+ vm.toggleProduct(vm.tableData[0])
|
|
|
|
|
+ vm.stage = stage
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ vm.$el.querySelector('#ng-purchase-upgrade-level').click()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ const option = Array.from(document.querySelectorAll('.ng-refactor-popper .el-select-dropdown__item')).find(node => node.textContent.trim() === 'Gold')
|
|
|
|
|
+ expect(option).toBeDefined()
|
|
|
|
|
+ option.click()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(componentErrors).toEqual([])
|
|
|
|
|
+ expect(vm.$el.querySelector('#ng-purchase-upgrade-level').value).toBe('Gold')
|
|
|
|
|
+ expect(vm.toLevel).toBe('4')
|
|
|
|
|
+ expect(vm.needDiffPv).toBe('220')
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade-warning').textContent).toContain('Cart BV (60) must be ≥ 220 BV to upgrade to Gold.')
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade.is-insufficient')).not.toBeNull()
|
|
|
|
|
+ expect(vm.canCheckout).toBe(false)
|
|
|
|
|
+ vm.changeQuantity({ row: product, value: 4 })
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ expect(vm.$el.querySelector('#ng-purchase-upgrade-level').value).toBe('Gold')
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade-warning')).toBeNull()
|
|
|
|
|
+ expect(vm.$el.querySelector('.ng-purchase-upgrade.is-sufficient')).not.toBeNull()
|
|
|
|
|
+ expect(vm.canCheckout).toBe(true)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
it.each(names)('%s connects the shared payment selection without changing totals or submitting', async source => {
|
|
it.each(names)('%s connects the shared payment selection without changing totals or submitting', async source => {
|
|
|
const vm = await withProducts(source)
|
|
const vm = await withProducts(source)
|
|
|
const radios = Array.from(vm.$el.querySelectorAll('.ng-payment-methods-options input'))
|
|
const radios = Array.from(vm.$el.querySelectorAll('.ng-payment-methods-options input'))
|