Skip to content

Commit

Permalink
Product payment unit tests (#3269)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Feb 19, 2025
1 parent 78ac2a8 commit 55e6987
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 18 deletions.
4 changes: 2 additions & 2 deletions auth-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-web",
"version": "2.8.10",
"version": "2.8.11",
"appName": "Auth Web",
"sbcName": "SBC Common Components",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,13 @@ export default defineComponent({
emit('emit-bcol-info')
}
// Exclude currentOrganization, it's already included in NextPageMixin, but we need it (not on template)
// Will remove this when we refactor NextPageMixin.
/* eslint-disable @typescript-eslint/no-unused-vars */
const { currentOrganization, ...refs } = toRefs(state)
return {
...toRefs(state),
...refs,
form,
setSelectedProduct,
setSelectedPayment,
Expand Down
8 changes: 4 additions & 4 deletions auth-web/src/stores/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ export const useOrgStore = defineStore('org', () => {
membershipType: MembershipType.User
}
}
async function syncMembership(orgId: number): Promise<Member> {

async function syncMembership (orgId: number): Promise<Member> {
const { roles } = KeyCloakService.getUserInfo()

// If user has any of the roles in the mapping, assign the permissions and membership type
Expand All @@ -351,10 +351,10 @@ export const useOrgStore = defineStore('org', () => {
const { data: membership } = await UserService.getMembership(orgId)
const { accountStatus: statusCode } = state.currentAccountSettings
const { data: permissions } = await PermissionService.getPermissions(statusCode, membership?.membershipTypeCode)

state.permissions = permissions || []
state.currentMembership = membership

return membership
}

Expand Down
52 changes: 42 additions & 10 deletions auth-web/tests/unit/components/PaymentMethods.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Account, PaymentTypes } from '@/util/constants'
import { createLocalVue, mount } from '@vue/test-utils'

import { Account } from '@/util/constants'
import PaymentMethods from '@/components/auth/common/PaymentMethods.vue'
import VueRouter from 'vue-router'
import Vuetify from 'vuetify'
import can from '@/directives/can'
import { useOrgStore } from '@/stores'

describe('PaymentMethods.vue', () => {
let wrapper: any
let wrapperFactory: any
const config = {
'AUTH_API_URL': 'https://localhost:8080/api/v1/11',
'PAY_API_URL': 'https://pay-api-dev.apps.silver.devops.gov.bc.ca/api/v1'
Expand All @@ -16,17 +18,25 @@ describe('PaymentMethods.vue', () => {

beforeEach(() => {
const localVue = createLocalVue()

const orgStore = useOrgStore()
orgStore.currentOrganization = { id: 123 } as any
const vuetify = new Vuetify({})
localVue.directive('can', can)

wrapper = mount(PaymentMethods, {
localVue,
vuetify,
propsData: {
currentOrgType: Account.PREMIUM
}
})
const router = new VueRouter()

wrapperFactory = (propsData) => {
return mount(PaymentMethods, {
localVue,
router,
vuetify,
propsData: {
...propsData
}
})
}

wrapper = wrapperFactory({ currentOrgType: Account.PREMIUM })

vi.resetModules()
vi.clearAllMocks()
Expand Down Expand Up @@ -98,4 +108,26 @@ describe('PaymentMethods.vue', () => {
await wrapper.vm.$nextTick()
expect(wrapper.vm.isPaymentSelected(method2)).toBe(false)
})

it('should not go into PAD view mode if createAccount is true ', async () => {
useOrgStore().currentOrgPADInfo = { 'bankAccountNumber': '123456' }
wrapper = wrapperFactory({ isCreateAccount: false, currentSelectedPaymentMethod: PaymentTypes.PAD })
await wrapper.vm.$nextTick()
wrapper.find('.payment-card-contents')
expect(wrapper.find('.banking-info').text('Banking Information')).toBeTruthy()
wrapper = wrapperFactory({ isCreateAccount: true, currentSelectedPaymentMethod: PaymentTypes.PAD })
await wrapper.vm.$nextTick()
expect(wrapper.find('.banking-info').exists()).toBeFalsy()
})

it('Entering BCOL info should enable button create account button', async () => {
wrapper = wrapperFactory({ currentOrganization: { id: 123 } as any,
isCreateAccount: true,
currentSelectedPaymentMethod: PaymentTypes.BCOL })
await wrapper.vm.$nextTick()
wrapper.find('[data-test="input-user-id"]').setValue('123456789')
wrapper.find('[data-test="input-user-password"]').setValue('123456789')
await wrapper.vm.$nextTick()
expect(wrapper.emitted()).toHaveProperty('emit-bcol-info')
})
})
92 changes: 92 additions & 0 deletions auth-web/tests/unit/components/SelectProductPayment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Account, PaymentTypes } from '@/util/constants'
import { createLocalVue, mount } from '@vue/test-utils'
import SelectProductPayment from '@/components/auth/create-account/SelectProductPayment.vue'
import VueRouter from 'vue-router'
import Vuetify from 'vuetify'
import can from '@/directives/can'
import { useOrgStore } from '@/stores'

describe('SelectProductPayment.vue', () => {
let wrapper: any
let wrapperFactory: any

const config = {
'AUTH_API_URL': 'https://localhost:8080/api/v1/11',
'PAY_API_URL': 'https://pay-api-dev.apps.silver.devops.gov.bc.ca/api/v1'
}

sessionStorage['AUTH_API_CONFIG'] = JSON.stringify(config)

beforeEach(() => {
const localVue = createLocalVue()

const vuetify = new Vuetify({})
localVue.directive('can', can)
const orgStore = useOrgStore()
orgStore.setCurrentOrganization({
id: 1,
name: 'Test Org'
})

const router = new VueRouter()

wrapperFactory = (propsData) => {
return mount(SelectProductPayment, {
localVue,
router,
vuetify,
propsData: {
...propsData
}
})
}

wrapper = wrapperFactory({ currentOrgType: Account.PREMIUM })

vi.resetModules()
vi.clearAllMocks()
})

afterEach(() => {
wrapper.destroy()
})

it('is a Vue instance', () => {
expect(wrapper.vm).toBeTruthy()
})

it('initial selection should be empty', () => {
expect(wrapper.vm.$data.selectedPaymentMethod).toBeFalsy()
})

it('currentOrganization should be on state, used for BCOL and PAD', async () => {
expect(wrapper.vm.currentOrganization).toBeTruthy()
})

it('correct isPaymentValid', async () => {
wrapper.setData({ selectedPaymentMethod: PaymentTypes.PAD })
await wrapper.vm.$nextTick()
expect(wrapper.vm.isPaymentValid).toBe(wrapper.vm.isPADValid)
wrapper.setData({ selectedPaymentMethod: PaymentTypes.BCOL })
await wrapper.vm.$nextTick()
expect(wrapper.vm.isPaymentValid).toBe(wrapper.vm.currentOrganization.bcolProfile?.password)
wrapper.setData({ selectedPaymentMethod: PaymentTypes.EJV })
await wrapper.vm.$nextTick()
expect(wrapper.vm.isPaymentValid).toBe(wrapper.vm.isEJVValid)
wrapper.setData({ selectedPaymentMethod: PaymentTypes.CREDIT_CARD })
await wrapper.vm.$nextTick()
expect(wrapper.vm.isPaymentValid).toBe(!!wrapper.vm.selectedPaymentMethod)
})

it('correct finish button text', async () => {
wrapper = wrapperFactory({ govmAccount: true })
await wrapper.vm.$nextTick()
expect(wrapper.vm.finishButtonText).toBe('Next')
wrapper = wrapperFactory({ govmAccount: false, readOnly: false })
await wrapper.vm.$nextTick()
expect(wrapper.vm.finishButtonText).toBe('Create Account')
wrapper = wrapperFactory({ govmAccount: false, readOnly: true })
await wrapper.vm.$nextTick()
expect(wrapper.vm.finishButtonText).toBe('Submit')
})
})

0 comments on commit 55e6987

Please sign in to comment.