Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JazzarKarim committed Jan 7, 2025
1 parent ff3bb54 commit 9b08b57
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions business-registry-dashboard/tests/unit/stores/affiliations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ mockNuxtImport('useConnectLaunchdarklyStore', () => {
)
})

// Add mock for useRoute
const mockRoute = { params: {} }
mockNuxtImport('useRoute', () => {
return () => mockRoute
})

describe('useAffiliationsStore', () => {
let store: any

Expand All @@ -169,25 +175,48 @@ describe('useAffiliationsStore', () => {
vi.clearAllMocks()
vi.resetAllMocks()
mockAuthenticated = true
mockRoute.params = {} // Reset route params after each test
})

describe('loadAffiliations', () => {
it('should fetch and set affiliations correctly', async () => {
mockGetStoredFlag.mockReturnValue(true) // set LDFlags.AffiliationInvitationRequestAccess = true - allow invitations fetch
mockGetStoredFlag.mockReturnValue(true)
mockAuthApi
.mockResolvedValueOnce(mockEntities) // affiliations
.mockResolvedValueOnce({ // invitations
.mockResolvedValueOnce(mockEntities)
.mockResolvedValueOnce({
affiliationInvitations: []
})

const affStore = useAffiliationsStore()

await affStore.loadAffiliations()
await flushPromises()

// Should use accountStore.currentAccount.id since not staff
expect(mockAuthApi).toHaveBeenCalledWith('/orgs/123/affiliations?new=true')
// results mapped to business object
expect(affStore.affiliations.results).toEqual(processedAffiliations)
expect(affStore.affiliations.count).toEqual(4)
})

it('should use route param orgId when user is staff', async () => {
store.currentAccount.accountType = 'STAFF' // Make user staff
mockRoute.params.orgId = '456' // Set route param

Check failure on line 205 in business-registry-dashboard/tests/unit/stores/affiliations.test.ts

View workflow job for this annotation

GitHub Actions / business-registry-ui-ci / linting-pnpm (21, 9)

Trailing spaces not allowed
mockGetStoredFlag.mockReturnValue(true)
mockAuthApi
.mockResolvedValueOnce(mockEntities)
.mockResolvedValueOnce({
affiliationInvitations: []
})

// wait for getAffiliatedEntities to finish
const affStore = useAffiliationsStore()

await affStore.loadAffiliations()
await flushPromises()

expect(mockAuthApi).toHaveBeenCalledTimes(2) // once for affiliations and another for invitations
// Should use route.params.orgId since user is staff
expect(mockAuthApi).toHaveBeenCalledWith('/orgs/456/affiliations?new=true')
// results mapped to business object
expect(affStore.affiliations.results).toEqual(processedAffiliations)
expect(affStore.affiliations.count).toEqual(4)
Expand Down

0 comments on commit 9b08b57

Please sign in to comment.