mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
fix tests
This commit is contained in:
parent
ee40603637
commit
156db583e7
@ -42,7 +42,7 @@ export default {
|
||||
},
|
||||
setDefaultCommunity() {
|
||||
// when we already get an identifier via url we choose this if the community exist
|
||||
if (this.communityIdentifier) {
|
||||
if (this.communityIdentifier && this.communities.length >= 1) {
|
||||
const foundCommunity = this.communities.find((community) => {
|
||||
if (
|
||||
community.uuid === this.communityIdentifier ||
|
||||
@ -82,6 +82,9 @@ export default {
|
||||
updated() {
|
||||
this.setDefaultCommunity()
|
||||
},
|
||||
mounted() {
|
||||
this.setDefaultCommunity()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
@ -4,7 +4,7 @@ import flushPromises from 'flush-promises'
|
||||
import { SEND_TYPES } from '@/pages/Send'
|
||||
import { createMockClient } from 'mock-apollo-client'
|
||||
import VueApollo from 'vue-apollo'
|
||||
import { userAndCommunity, selectCommunities as selectCommunitiesQuery } from '@/graphql/queries'
|
||||
import { user, selectCommunities as selectCommunitiesQuery } from '@/graphql/queries'
|
||||
|
||||
const mockClient = createMockClient()
|
||||
const apolloProvider = new VueApollo({
|
||||
@ -47,23 +47,21 @@ describe('TransactionForm', () => {
|
||||
})
|
||||
}
|
||||
|
||||
const userAndCommunityMock = jest.fn()
|
||||
const userMock = jest.fn()
|
||||
|
||||
mockClient.setRequestHandler(
|
||||
userAndCommunity,
|
||||
userAndCommunityMock
|
||||
.mockRejectedValueOnce({ message: 'Query user name fails!' })
|
||||
.mockResolvedValue({
|
||||
data: {
|
||||
user: {
|
||||
firstName: 'Bibi',
|
||||
lastName: 'Bloxberg',
|
||||
},
|
||||
community: {
|
||||
name: 'Gradido Entwicklung',
|
||||
},
|
||||
user,
|
||||
userMock.mockRejectedValueOnce({ message: 'Query user name fails!' }).mockResolvedValue({
|
||||
data: {
|
||||
user: {
|
||||
firstName: 'Bibi',
|
||||
lastName: 'Bloxberg',
|
||||
},
|
||||
}),
|
||||
community: {
|
||||
name: 'Gradido Entwicklung',
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
mockClient.setRequestHandler(
|
||||
@ -410,7 +408,8 @@ Die ganze Welt bezwingen.“`)
|
||||
describe('with gradido ID', () => {
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
mocks.$route.query.gradidoID = 'gradido-ID'
|
||||
mocks.$route.params.userIdentifier = 'gradido-ID'
|
||||
mocks.$route.params.communityIdentifier = 'community-ID'
|
||||
wrapper = Wrapper()
|
||||
await wrapper.vm.$nextTick()
|
||||
})
|
||||
@ -421,8 +420,9 @@ Die ganze Welt bezwingen.“`)
|
||||
})
|
||||
|
||||
it('queries the username', () => {
|
||||
expect(userAndCommunityMock).toBeCalledWith({
|
||||
expect(userMock).toBeCalledWith({
|
||||
identifier: 'gradido-ID',
|
||||
communityIdentifier: 'community-ID',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -47,7 +47,12 @@ describe('Name', () => {
|
||||
describe('with linked user', () => {
|
||||
beforeEach(async () => {
|
||||
await wrapper.setProps({
|
||||
linkedUser: { firstName: 'Bibi', lastName: 'Bloxberg', gradidoID: 'gradido-ID' },
|
||||
linkedUser: {
|
||||
firstName: 'Bibi',
|
||||
lastName: 'Bloxberg',
|
||||
gradidoID: 'gradido-ID',
|
||||
communityUuid: 'community UUID',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@ -70,10 +75,11 @@ describe('Name', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('pushes query for gradidoID', () => {
|
||||
it('pushes params for gradidoID and community UUID', () => {
|
||||
expect(routerPushMock).toBeCalledWith({
|
||||
query: {
|
||||
gradidoID: 'gradido-ID',
|
||||
params: {
|
||||
communityIdentifier: 'community UUID',
|
||||
userIdentifier: 'gradido-ID',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@ -37,9 +37,9 @@ export default {
|
||||
async tunnelEmail() {
|
||||
if (this.$route.path !== '/send') await this.$router.push({ path: '/send' })
|
||||
this.$router.push({
|
||||
query: {
|
||||
gradidoID: this.linkedUser.gradidoID,
|
||||
communityUuid: this.linkedUser.communityUuid,
|
||||
params: {
|
||||
userIdentifier: this.linkedUser.gradidoID,
|
||||
communityIdentifier: this.linkedUser.communityUuid,
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ describe('Login', () => {
|
||||
commit: mockStoreCommit,
|
||||
state: {
|
||||
publisherId: 12345,
|
||||
redirectPath: '/overview',
|
||||
},
|
||||
},
|
||||
$loading: {
|
||||
|
||||
@ -106,7 +106,7 @@ export default {
|
||||
if (this.$route.params.code) {
|
||||
this.$router.push(`/redeem/${this.$route.params.code}`)
|
||||
} else {
|
||||
this.$router.push('/overview')
|
||||
this.$router.push(this.$store.state.redirectPath)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@ -38,6 +38,7 @@ describe('Send', () => {
|
||||
},
|
||||
$route: {
|
||||
query: {},
|
||||
params: {},
|
||||
},
|
||||
$router: {
|
||||
push: routerPushMock,
|
||||
@ -175,7 +176,9 @@ describe('Send', () => {
|
||||
|
||||
describe('with gradidoID query', () => {
|
||||
beforeEach(() => {
|
||||
mocks.$route.query.gradidoID = 'gradido-ID'
|
||||
jest.clearAllMocks()
|
||||
mocks.$route.params.userIdentifier = 'gradido-ID'
|
||||
mocks.$route.params.communityIdentifier = 'community-ID'
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
@ -226,11 +229,7 @@ describe('Send', () => {
|
||||
})
|
||||
|
||||
it('resets the gradido ID query in route', () => {
|
||||
expect(routerPushMock).toBeCalledWith({
|
||||
query: {
|
||||
gradidoID: undefined,
|
||||
},
|
||||
})
|
||||
expect(routerPushMock).toBeCalledWith('send')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -36,6 +36,8 @@ const addNavigationGuards = (router, store, apollo) => {
|
||||
// handle authentication
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.meta.requiresAuth && !store.state.token) {
|
||||
// store redirect path
|
||||
store.commit('redirectPath', to.path)
|
||||
next({ path: '/login' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
@ -66,11 +66,11 @@ describe('router', () => {
|
||||
|
||||
describe('send', () => {
|
||||
it('requires authorization', () => {
|
||||
expect(routes.find((r) => r.path === '/send').meta.requiresAuth).toBeTruthy()
|
||||
expect(routes.find((r) => r.path.startsWith('/send')).meta.requiresAuth).toBeTruthy()
|
||||
})
|
||||
|
||||
it('loads the "Send" page', async () => {
|
||||
const component = await routes.find((r) => r.path === '/send').component()
|
||||
const component = await routes.find((r) => r.path.startsWith('/send')).component()
|
||||
expect(component.default.name).toBe('Send')
|
||||
})
|
||||
})
|
||||
|
||||
@ -58,6 +58,9 @@ export const mutations = {
|
||||
setDarkMode: (state, darkMode) => {
|
||||
state.darkMode = !!darkMode
|
||||
},
|
||||
redirectPath: (state, redirectPath) => {
|
||||
state.redirectPath = redirectPath || '/overview'
|
||||
},
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
@ -89,6 +92,7 @@ export const actions = {
|
||||
commit('hideAmountGDT', true)
|
||||
commit('email', '')
|
||||
commit('setDarkMode', false)
|
||||
commit('redirectPath', '/overview')
|
||||
localStorage.clear()
|
||||
},
|
||||
}
|
||||
@ -119,6 +123,7 @@ try {
|
||||
hideAmountGDT: null,
|
||||
email: '',
|
||||
darkMode: false,
|
||||
redirectPath: '/overview',
|
||||
},
|
||||
getters: {},
|
||||
// Syncronous mutation of the state
|
||||
|
||||
@ -264,7 +264,7 @@ describe('Vuex store', () => {
|
||||
|
||||
it('calls twelve commits', () => {
|
||||
logout({ commit, state })
|
||||
expect(commit).toHaveBeenCalledTimes(13)
|
||||
expect(commit).toHaveBeenCalledTimes(14)
|
||||
})
|
||||
|
||||
it('commits token', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user