Skip to content

Commit

Permalink
Merge branch 'master' into frontend-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt authored Apr 9, 2024
2 parents 2030f67 + 497c9da commit 5a88a43
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 3,684 deletions.
14 changes: 2 additions & 12 deletions presenter/.env.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# AUTH
# PUBLIC_ENV__AUTH__AUTHORITY and PUBLIC_ENV__AUTH__AUTHORITY_SIGNUP_URI
# are not default values since the default is to hide the signin/signup buttons
PUBLIC_ENV__AUTH__AUTHORITY="http://localhost:9000/application/o/dreammallearth/"
PUBLIC_ENV__AUTH__AUTHORITY_SIGNUP_URI="http://localhost:9000/if/flow/dreammallearth-enrollment/"
PUBLIC_ENV__AUTH__AUTHORITY_SIGNOUT_URI="http://localhost:9000/if/flow/dreammallearth-invalidation-flow/"
PUBLIC_ENV__AUTH__CLIENT_ID="G3g0sjCjph1NAyGeeu5Te5ltx1I7WZ0DGB8i6vOI"
PUBLIC_ENV__AUTH__REDIRECT_URI="http://localhost:3000/auth"
PUBLIC_ENV__AUTH__SILENT_REDIRECT_URI="http://localhost:3000/silent-refresh"
PUBLIC_ENV__AUTH__RESPONSE_TYPE="code"
PUBLIC_ENV__AUTH__SCOPE="openid profile posts"

PUBLIC_ENV__SIGNIN_REDIRECT_URI="http://localhost:3000/signin"
PUBLIC_ENV__SIGNUP_URI="http://localhost:9000/if/flow/dreammallearth-enrollment/"
PUBLIC_ENV__SIGNIN_URI="http://localhost:3000/signin"

# Endpoints
PUBLIC_ENV__ENDPOINTS__GRAPHQL_URI=http://localhost:4000/
Expand Down
20 changes: 0 additions & 20 deletions presenter/package-lock.json

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

3 changes: 1 addition & 2 deletions presenter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build": "vite build && npm run server:build",
"server": "node --loader ts-node/esm ./server/index.ts",
"server:dev": "npm run server",
"server:prod": "node ./build/index.cjs",
"server:prod": "cross-env NODE_ENV=production node ./build/index.cjs",
"server:prod:ts": "cross-env NODE_ENV=production npm run server",
"server:build": "tsx scripts/buildServer/buildServer",
"storybook": "storybook dev -p 6006",
Expand Down Expand Up @@ -78,7 +78,6 @@
"express": "^4.19.2",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"oidc-client-ts": "^3.0.1",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"sass": "^1.74.1",
Expand Down
11 changes: 1 addition & 10 deletions presenter/renderer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import i18n from '#plugins/i18n'
import pinia from '#plugins/pinia'
import CreateVuetify from '#plugins/vuetify'
import { locales } from '#src/locales'
import AuthService from '#src/services/AuthService'
import { useAuthStore } from '#stores/authStore'

const vuetify = CreateVuetify(i18n)

Expand All @@ -20,8 +18,7 @@ function createApp(pageContext: PageContext, isClient = true) {
let rootComponent: InstanceType<typeof PageWithWrapper>
const PageWithWrapper = defineComponent({
setup: () => {
provide(DefaultApolloClient, createApolloClient(getToken))
provide('authService', new AuthService())
provide(DefaultApolloClient, createApolloClient())
},
data: () => ({
Page: markRaw(pageContext.Page),
Expand Down Expand Up @@ -55,12 +52,6 @@ function createApp(pageContext: PageContext, isClient = true) {
app.use(i18n)
app.use(vuetify)

const auth = useAuthStore()

const getToken = (): string => {
return auth.accessToken
}

objectAssign(app, {
changePage: (pageContext: PageContext) => {
Object.assign(pageContextReactive, pageContext)
Expand Down
18 changes: 2 additions & 16 deletions presenter/renderer/plugins/apollo.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { ApolloClient, InMemoryCache } from '@apollo/client/core'
import { setContext } from '@apollo/client/link/context'
import { createHttpLink } from '@apollo/client/link/http'
// import { onError } from '@apollo/client/link/error'

import { ENDPOINTS } from '#src/env'

const createAuthLink = (getToken: () => string) => {
return setContext((_, { headers }) => {
const token = getToken()
return {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
headers: {
...headers,
...(token && { authorization: `Bearer ${token}` }),
},
}
})
}

const httpLink = createHttpLink({
uri: ENDPOINTS.GRAPHQL_URI,
})
Expand All @@ -37,10 +23,10 @@ const errorLink = onError(({ graphQLErrors, networkError }) => {

const cache = new InMemoryCache()

export const createApolloClient = (getToken: () => string) => {
export const createApolloClient = () => {
return new ApolloClient({
ssrMode: true,
link: createAuthLink(getToken).concat(httpLink), // errorLink.concat(httpLink),
link: httpLink, // errorLink.concat(httpLink),
cache,
})
}
43 changes: 0 additions & 43 deletions presenter/scripts/tests/mock.authService.ts

This file was deleted.

112 changes: 8 additions & 104 deletions presenter/src/components/menu/HeaderMenu.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { mount } from '@vue/test-utils'
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 { AUTH } from '#src/env'
import { useAuthStore } from '#stores/authStore'
import { authService } from '#tests/mock.authService'

import HeaderMenu from './HeaderMenu.vue'

vi.mock('vike/client/router')
vi.mocked(navigate).mockResolvedValue()

describe('HeaderMenu', () => {
it('renders', () => {
AUTH.AUTHORITY = ''
AUTH.AUTHORITY_SIGNUP_URI = ''
AUTH.SIGNUP_URI = ''
AUTH.SIGNIN_URI = ''

const wrapper = mount(VApp, {
slots: {
Expand All @@ -39,9 +33,8 @@ describe('HeaderMenu', () => {
let wrapper: ReturnType<typeof Wrapper>

beforeEach(() => {
AUTH.AUTHORITY = 'authority'
AUTH.AUTHORITY_SIGNUP_URI = 'http://sign-up.uri'
AUTH.SIGNIN_REDIRECT_URI = 'http://sigin-in.uri'
AUTH.SIGNUP_URI = 'http://sign-up.uri'
AUTH.SIGNIN_URI = 'http://sigin-in.uri'
wrapper = Wrapper()
})

Expand All @@ -61,102 +54,13 @@ describe('HeaderMenu', () => {
})

describe('sign up button', () => {
const spy = vi.spyOn(authService, 'signUp')

beforeEach(() => {
beforeEach(async () => {
vi.clearAllMocks()
await wrapper.find('button.sign-up').trigger('click')
})

describe('without error', () => {
beforeEach(async () => {
await wrapper.find('button.sign-up').trigger('click')
})

it('call auth service signUp', () => {
expect(spy).toBeCalled()
})
})

describe('with error', () => {
const consoleSpy = vi.spyOn(console, 'log')

beforeEach(async () => {
spy.mockRejectedValue('Oh no!')
await wrapper.find('button.sign-up').trigger('click')
})

it('logs the error', () => {
expect(consoleSpy).toBeCalledWith('auth error', 'Oh no!')
})
})
})

describe('logged in', () => {
const authStore = useAuthStore()

beforeEach(() => {
authStore.save({
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',
})
})

it('has a sign out button', () => {
expect(wrapper.find('button.sign-out').exists()).toBe(true)
})

it('has no sign in/up button', () => {
expect(wrapper.find('button.sign-up').exists()).toBe(false)
expect(wrapper.find('button.sign-in').exists()).toBe(false)
})

describe('click sign out', () => {
const authSpy = vi.spyOn(authService, 'signOut')
const storeSpy = vi.spyOn(authStore, 'clear')

beforeEach(() => {
vi.clearAllMocks()
})

describe('without error', () => {
beforeEach(async () => {
await wrapper.find('button.sign-out').trigger('click')
})

it('calls auth service sign out', () => {
expect(authSpy).toBeCalled()
})

it('clears the store', () => {
expect(storeSpy).toBeCalled()
})
})

describe('with error', () => {
const consoleSpy = vi.spyOn(console, 'log')

beforeEach(async () => {
authSpy.mockRejectedValue('Error!')
await wrapper.find('button.sign-out').trigger('click')
})

it('logs the error', () => {
expect(consoleSpy).toBeCalledWith('auth error', 'Error!')
})
})
it('changes window location', () => {
expect(global.window.location.href).toBe('http://sign-up.uri/')
})
})
})
Expand Down
Loading

0 comments on commit 5a88a43

Please sign in to comment.