From ad111f57018ca1df23f31ea413ca3f6196927089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Mon, 6 May 2019 19:26:53 +0200 Subject: [PATCH] Double-check changed expectations, fix tests See: https://github.com/Human-Connection/Human-Connection/pull/478/files#r281267486 > We found the reason for it: If you have an exclamation mark in the schema e.g. > email! and the response would e.g. expect the email for each User object, and > the server does not have an email for the client, then the entire User object > gets nullified. --- .../middleware/permissionsMiddleware.spec.js | 9 +++++++-- webapp/components/User/index.spec.js | 19 ++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/src/middleware/permissionsMiddleware.spec.js b/backend/src/middleware/permissionsMiddleware.spec.js index ccc65d578..e3c4beb00 100644 --- a/backend/src/middleware/permissionsMiddleware.spec.js +++ b/backend/src/middleware/permissionsMiddleware.spec.js @@ -40,10 +40,13 @@ describe('authorization', () => { }) it('does not expose the owner\'s email address', async () => { + let response = {} try { await action() } catch (error) { - expect(error.response.data).toEqual({ User: [ null ] }) + response = error.response.data + } finally { + expect(response).toEqual({ User: [ null ] }) } }) }) @@ -74,11 +77,13 @@ describe('authorization', () => { }) it('does not expose the owner\'s email address', async () => { + let response try { await action() } catch (error) { - expect(error.response.data).toEqual({ User: [ null ] }) + response = error.response.data } + expect(response).toEqual({ User: [ null ] }) }) }) }) diff --git a/webapp/components/User/index.spec.js b/webapp/components/User/index.spec.js index 13cdf87f8..4bc286d20 100644 --- a/webapp/components/User/index.spec.js +++ b/webapp/components/User/index.spec.js @@ -49,12 +49,11 @@ describe('User', () => { return mount(User, { store, propsData, mocks, stubs, localVue }) } - // TODO this is not working - mixin missing? - /*it('renders anonymous user', () => { + it('renders anonymous user', () => { const wrapper = Wrapper() - expect(wrapper.text()).not.toMatch('Tilda Swinton') - expect(wrapper.text()).toMatch('Anonymus') - })*/ + expect(wrapper.text()).toBe('') + expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym') + }) describe('given an user', () => { beforeEach(() => { @@ -66,7 +65,7 @@ describe('User', () => { it('renders user name', () => { const wrapper = Wrapper() - expect(wrapper.text()).not.toMatch('Anonymous') + expect(mocks.$t).not.toHaveBeenCalledWith('profile.userAnonym') expect(wrapper.text()).toMatch('Tilda Swinton') }) @@ -75,13 +74,11 @@ describe('User', () => { propsData.user.disabled = true }) - // TODO recheck what we want to display if a user is disabled - // it seems not reasonable to diplay Anonymous - /*it('renders anonymous user', () => { + it('renders anonymous user', () => { const wrapper = Wrapper() expect(wrapper.text()).not.toMatch('Tilda Swinton') - expect(wrapper.text()).toMatch('Anonymus') - })*/ + expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym') + }) describe('current user is a moderator', () => { beforeEach(() => {