-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { createTestingPinia } from '@pinia/testing' | ||
import { config } from '@vue/test-utils' | ||
|
||
import pinia from '#plugins/pinia' | ||
|
||
config.global.plugins.push(pinia) | ||
config.global.plugins.push(createTestingPinia()) |
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 |
---|---|---|
@@ -1,23 +1,114 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
import { navigate } from 'vike/client/router' | ||
import { describe, it, expect, beforeEach, vi } from 'vitest' | ||
import { Component, h } from 'vue' | ||
import { VApp } from 'vuetify/components' | ||
|
||
import { useAuthStore } from '#stores/authStore' | ||
import { authService } from '#tests/mock.authService' | ||
|
||
import AuthPage from './+Page.vue' | ||
import { title } from './+title' | ||
|
||
vi.mock('vike/client/router') | ||
vi.mocked(navigate).mockResolvedValue() | ||
|
||
describe('AuthPage', () => { | ||
const wrapper = mount(VApp, { | ||
slots: { | ||
default: h(AuthPage as Component), | ||
}, | ||
const Wrapper = () => { | ||
return mount(VApp, { | ||
slots: { | ||
default: h(AuthPage as Component), | ||
}, | ||
}) | ||
} | ||
|
||
const authServiceSpy = vi.spyOn(authService, 'signInCallback') | ||
const authStore = useAuthStore() | ||
|
||
let wrapper: ReturnType<typeof Wrapper> | ||
|
||
describe('signin callback without error', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
authServiceSpy.mockResolvedValue({ | ||
access_token: 'access_token', | ||
profile: { | ||
aud: 'aud', | ||
sub: 'sub', | ||
exp: 1, | ||
iat: 1, | ||
iss: 'iss', | ||
}, | ||
token_type: 'token_type', | ||
session_state: null, | ||
state: null, | ||
expires_in: 0, | ||
expired: false, | ||
scopes: ['email'], | ||
toStorageString: () => 'toStorageString', | ||
}) | ||
wrapper = Wrapper() | ||
}) | ||
|
||
it('title returns correct title', () => { | ||
expect(title).toBe('DreamMall | Authentifizierung') | ||
}) | ||
|
||
it('renders', () => { | ||
expect(wrapper.element).toMatchSnapshot() | ||
}) | ||
|
||
it('calls authservie signin callback', () => { | ||
expect(authServiceSpy).toBeCalled() | ||
}) | ||
|
||
it('updates the store', () => { | ||
expect(authStore.save).toBeCalledWith( | ||
expect.objectContaining({ | ||
access_token: 'access_token', | ||
profile: { | ||
aud: 'aud', | ||
sub: 'sub', | ||
exp: 1, | ||
iat: 1, | ||
iss: 'iss', | ||
}, | ||
token_type: 'token_type', | ||
}), | ||
) | ||
}) | ||
|
||
it('navigates to /', () => { | ||
expect(navigate).toBeCalledWith('/') | ||
}) | ||
}) | ||
|
||
it('title returns correct title', () => { | ||
expect(title).toBe('DreamMall | Authentifizierung') | ||
describe('no user returned', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
authServiceSpy.mockResolvedValue() | ||
}) | ||
|
||
it('throws an error', () => { | ||
try { | ||
wrapper = Wrapper() | ||
} catch (err) { | ||
expect(err).toBe('Could not Sign In') | ||
} | ||
}) | ||
}) | ||
|
||
it('renders', () => { | ||
expect(wrapper.element).toMatchSnapshot() | ||
describe('signin callback with error', () => { | ||
const consoleSpy = vi.spyOn(global.console, 'log') | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
authServiceSpy.mockRejectedValue('Ouch!') | ||
wrapper = Wrapper() | ||
}) | ||
|
||
it('logs the error on console', () => { | ||
expect(consoleSpy).toBeCalledWith('auth error', 'Ouch!') | ||
}) | ||
}) | ||
}) |
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