From 1004718892cea46a415385971099d2924d164c38 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 2 Dec 2021 06:30:41 +0100 Subject: [PATCH 1/2] Added moderator query to the creationFormular so we can send the right moderator id. --- admin/src/components/CreationFormular.vue | 14 ++++++++++++++ admin/src/graphql/verifyLogin.js | 11 +++++++++++ admin/src/store/store.js | 3 +++ backend/src/graphql/model/User.ts | 4 ++++ backend/src/graphql/resolver/UserResolver.ts | 2 ++ 5 files changed, 34 insertions(+) create mode 100644 admin/src/graphql/verifyLogin.js diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 5d29c6fcb..b6a12433e 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -126,6 +126,7 @@ diff --git a/admin/src/graphql/verifyLogin.js b/admin/src/graphql/verifyLogin.js new file mode 100644 index 000000000..59f5e7eb1 --- /dev/null +++ b/admin/src/graphql/verifyLogin.js @@ -0,0 +1,11 @@ +import gql from 'graphql-tag' + +export const verifyLogin = gql` + query { + verifyLogin { + firstName + lastName + id + } + } +` diff --git a/admin/src/store/store.js b/admin/src/store/store.js index 140a92391..d67537499 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -18,6 +18,9 @@ export const mutations = { token: (state, token) => { state.token = token }, + moderator: (state, moderator) => { + state.moderator = moderator + }, } export const actions = { diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index cdb46c954..c7b5806ca 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -12,6 +12,7 @@ export class User { */ constructor(json?: any) { if (json) { + this.id = json.id this.email = json.email this.firstName = json.first_name this.lastName = json.last_name @@ -24,6 +25,9 @@ export class User { } } + @Field(() => Number) + id: number + @Field(() => String) email: string diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 7f5f7dc43..ce403ac0e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -207,6 +207,7 @@ export class UserResolver { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUser = await loginUserRepository.findByEmail(userEntity.email) const user = new User() + user.id = userEntity.id user.email = userEntity.email user.firstName = userEntity.firstName user.lastName = userEntity.lastName @@ -276,6 +277,7 @@ export class UserResolver { } const user = new User() + user.id = userEntity.id user.email = email user.firstName = loginUser.firstName user.lastName = loginUser.lastName From 4e1baeae2e50f4d723854e4a87938aafaedf6812 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 2 Dec 2021 07:06:38 +0100 Subject: [PATCH 2/2] Test the apollo query for verifyLogin so we get the moderator before an creation. --- admin/src/components/CreationFormular.spec.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index fcdf97cfa..e1bbff1cc 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -3,6 +3,16 @@ import CreationFormular from './CreationFormular.vue' const localVue = global.localVue +const apolloMock = jest.fn().mockResolvedValue({ + data: { + verifyLogin: { + name: 'success', + id: 0, + }, + }, +}) +const stateCommitMock = jest.fn() + const mocks = { $moment: jest.fn(() => { return { @@ -14,6 +24,12 @@ const mocks = { }), } }), + $apollo: { + query: apolloMock, + }, + $store: { + commit: stateCommitMock, + }, } const propsData = { @@ -39,6 +55,23 @@ describe('CreationFormular', () => { expect(wrapper.find('.component-creation-formular').exists()).toBeTruthy() }) + describe('server sends back moderator data', () => { + it('called store commit with mocked data', () => { + expect(stateCommitMock).toBeCalledWith('moderator', { name: 'success', id: 0 }) + }) + }) + + describe('server throws error for moderator data call', () => { + beforeEach(() => { + jest.clearAllMocks() + apolloMock.mockRejectedValue({ message: 'Ouch!' }) + wrapper = Wrapper() + }) + it('has called store commit with fake data', () => { + expect(stateCommitMock).toBeCalledWith('moderator', { id: 0, name: 'Test Moderator' }) + }) + }) + describe('radio buttons to selcet month', () => { it('has three radio buttons', () => { expect(wrapper.findAll('input[type="radio"]').length).toBe(3)