-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* router structure changed * Fix relative paths * Login route guards moved to separate components * Tests for loginById added * loginByToken tests added * Remove unneeded stubActions option
- Loading branch information
Showing
6 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { describe, test, beforeEach, vi, expect } from 'vitest'; | ||
import loginById from './loginById'; | ||
import useAuth from '@/stores/auth'; | ||
import type { RouteLocationNormalized } from 'vue-router'; | ||
import { createApp } from 'vue'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { setActivePinia } from 'pinia'; | ||
|
||
const userId = faker.datatype.uuid(); | ||
|
||
const to: Partial<RouteLocationNormalized> = { | ||
params: { | ||
userId, | ||
}, | ||
}; | ||
|
||
describe('loginById', () => { | ||
let auth: ReturnType<typeof useAuth>; | ||
|
||
beforeEach(() => { | ||
const app = createApp({}); | ||
const pinia = createTestingPinia({ createSpy: vi.fn }); | ||
app.use(pinia); | ||
setActivePinia(pinia); | ||
|
||
auth = useAuth(); | ||
}); | ||
|
||
test('should call loginWithUserId', async () => { | ||
await loginById(to as RouteLocationNormalized); | ||
|
||
expect(auth.loginWithUserId).toHaveBeenCalled(); | ||
expect(auth.loginWithUserId).toHaveBeenCalledWith(userId); | ||
}); | ||
|
||
test('should return directions to home', async () => { | ||
expect(await loginById(to as RouteLocationNormalized)).toStrictEqual({ | ||
name: 'home', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { RouteLocationNormalized } from 'vue-router'; | ||
import useAuth from '@/stores/auth'; | ||
|
||
const loginByToken = async (to: RouteLocationNormalized) => { | ||
const auth = useAuth(); | ||
await auth.loginWithUserId(String(to.params.userId)); | ||
|
||
return { name: 'home' }; | ||
}; | ||
|
||
export default loginByToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { describe, test, beforeEach, vi, expect } from 'vitest'; | ||
import loginByToken from './loginByToken'; | ||
import useAuth from '@/stores/auth'; | ||
import type { RouteLocationNormalized } from 'vue-router'; | ||
import { createApp } from 'vue'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { setActivePinia } from 'pinia'; | ||
|
||
const passwordlessToken = faker.datatype.uuid(); | ||
|
||
const to: Partial<RouteLocationNormalized> = { | ||
params: { | ||
passwordlessToken, | ||
}, | ||
}; | ||
|
||
describe('loginByToken', () => { | ||
let auth: ReturnType<typeof useAuth>; | ||
|
||
beforeEach(() => { | ||
const app = createApp({}); | ||
const pinia = createTestingPinia({ createSpy: vi.fn }); | ||
app.use(pinia); | ||
setActivePinia(pinia); | ||
|
||
auth = useAuth(); | ||
}); | ||
|
||
test('should call exchangeTokens', async () => { | ||
await loginByToken(to as RouteLocationNormalized); | ||
|
||
expect(auth.exchangeTokens).toHaveBeenCalled(); | ||
expect(auth.exchangeTokens).toHaveBeenCalledWith(passwordlessToken); | ||
}); | ||
|
||
test('should return directions to home', async () => { | ||
expect(await loginByToken(to as RouteLocationNormalized)).toStrictEqual({ | ||
name: 'home', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { RouteLocationNormalized } from 'vue-router'; | ||
import useAuth from '@/stores/auth'; | ||
|
||
const loginByToken = async (to: RouteLocationNormalized) => { | ||
const auth = useAuth(); | ||
await auth.exchangeTokens(String(to.params.passwordlessToken)); | ||
return { name: 'home' }; | ||
}; | ||
|
||
export default loginByToken; |