|
| 1 | +import { LoginSource, PaymentTypes } from '@/util/constants' |
1 | 2 | import { createLocalVue, shallowMount } from '@vue/test-utils' |
2 | 3 | import { useBusinessStore, useOrgStore, useUserStore } from '@/stores' |
3 | 4 | import AccountPaymentMethods from '@/components/auth/account-settings/payment/AccountPaymentMethods.vue' |
4 | | -import { LoginSource } from '@/util/constants' |
5 | 5 | import VueRouter from 'vue-router' |
6 | 6 | import Vuetify from 'vuetify' |
7 | 7 |
|
| 8 | +vi.mock('@/composables/product-payment-factory', () => ({ |
| 9 | + useProductPayment: () => ({ |
| 10 | + hasProductOrPaymentBackendChanges: vi.fn().mockResolvedValue(false) |
| 11 | + }) |
| 12 | +})) |
| 13 | + |
8 | 14 | const vuetify = new Vuetify({}) |
9 | 15 |
|
10 | 16 | vi.mock('../../../src/services/user.services') |
@@ -77,4 +83,42 @@ describe('AccountPaymentMethods.vue', () => { |
77 | 83 | it('renders the components properly and address is being shown', () => { |
78 | 84 | expect(wrapper.findComponent(AccountPaymentMethods).exists()).toBe(true) |
79 | 85 | }) |
| 86 | + |
| 87 | + const bcolErrorFields = { |
| 88 | + code: 'BCOL API Error', |
| 89 | + detail: null, |
| 90 | + message: { |
| 91 | + detail: 'Invalid User ID or Password', |
| 92 | + title: 'Invalid Credentials', |
| 93 | + type: 'INVALID_CREDENTIALS' |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + async function saveWithMockError (errorData: object) { |
| 98 | + const orgStore = useOrgStore() |
| 99 | + orgStore.updateOrg = vi.fn().mockRejectedValue({ |
| 100 | + response: { status: 400, data: errorData } |
| 101 | + }) |
| 102 | + wrapper.vm.selectedPaymentMethod = PaymentTypes.CREDIT_CARD |
| 103 | + wrapper.vm.isBtnSaved = false |
| 104 | + wrapper.vm.$refs.errorDialog = { open: vi.fn(), close: vi.fn() } |
| 105 | + await wrapper.vm.save() |
| 106 | + } |
| 107 | + |
| 108 | + it('sets errorText and errorTitle correctly for a 400 BCOL error response', async () => { |
| 109 | + await saveWithMockError(bcolErrorFields) |
| 110 | + |
| 111 | + expect(wrapper.vm.errorTitle).toBe('Invalid Credentials') |
| 112 | + expect(wrapper.vm.errorText).toBe('BCOL API Error<br>Invalid User ID or Password') |
| 113 | + }) |
| 114 | + |
| 115 | + it('sets errorText and errorTitle correctly for a 400 BCOL error with rootCause', async () => { |
| 116 | + await saveWithMockError({ |
| 117 | + errorMessage: 'API backend third party service error.', |
| 118 | + rootCause: bcolErrorFields |
| 119 | + }) |
| 120 | + |
| 121 | + expect(wrapper.vm.errorTitle).toBe('Invalid Credentials') |
| 122 | + expect(wrapper.vm.errorText).toBe('BCOL API Error<br>Invalid User ID or Password') |
| 123 | + }) |
80 | 124 | }) |
0 commit comments