From f3c31aed28dcd4d33e0e6ecbe72ff084b74bdb7e Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 13 Sep 2019 01:11:30 +0200 Subject: [PATCH] Don't expose termsAndConditionsAgreedAt 1. Don't expose `termsAndConditionsAgreedAt` as input param, because of ..why? 2. Make the `termsAndConditionsAgreedVersion` a *required* input param for `SignupVerification`. If new users register, they have to confirm the terms and conditions. I added another test to check what happens if the user sends `null`. 3. Sorry @ogerly for confusing you with my review here: https://github.com/Human-Connection/Human-Connection/pull/1556#pullrequestreview-287516516 What I meant is that we want to simulate a user with no `termsAndConditionsAgreedVersion`. But of course the `variables` must have it set when you run the mutations. Now we have the exclamation mark in the input param, see point 1 :point_up: --- .../src/schema/resolvers/registration.spec.js | 27 ++++++++++++++++--- .../src/schema/types/type/EmailAddress.gql | 3 +-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/backend/src/schema/resolvers/registration.spec.js b/backend/src/schema/resolvers/registration.spec.js index e71fbffa3..ca19f03c4 100644 --- a/backend/src/schema/resolvers/registration.spec.js +++ b/backend/src/schema/resolvers/registration.spec.js @@ -62,7 +62,7 @@ describe('CreateInvitationCode', () => { name: 'Inviter', email: 'inviter@example.org', password: '1234', - termsAndConditionsAgreedVersion: '0.0.1', + termsAndConditionsAgreedVersion: null, }) authenticatedUser = await user.toJson() }) @@ -352,8 +352,7 @@ describe('SignupVerification', () => { name: 'John Doe', password: '123', email: 'john@example.org', - termsAndConditionsAgreedVersion: null, - termsAndConditionsAgreedAt: null, + termsAndConditionsAgreedVersion: '0.1.0', } }) @@ -446,6 +445,16 @@ describe('SignupVerification', () => { expect(emails).toHaveLength(1) }) + it('updates termsAndConditionsAgreedVersion', async () => { + await expect(mutate({ mutation, variables })).resolves.toMatchObject({ + data: { + SignupVerification: expect.objectContaining({ + termsAndConditionsAgreedVersion: '0.1.0', + }), + }, + }) + }) + it('updates termsAndConditionsAgreedAt', async () => { await expect(mutate({ mutation, variables })).resolves.toMatchObject({ data: { @@ -456,6 +465,18 @@ describe('SignupVerification', () => { }) }) + it('rejects if version of terms and conditions is missing', async () => { + variables = { ...variables, termsAndConditionsAgreedVersion: null } + await expect(mutate({ mutation, variables })).resolves.toMatchObject({ + errors: [ + { + message: + 'Variable "$termsAndConditionsAgreedVersion" of non-null type "String!" must not be null.', + }, + ], + }) + }) + it('rejects if version of terms and conditions has wrong format', async () => { variables = { ...variables, termsAndConditionsAgreedVersion: 'invalid version format' } await expect(mutate({ mutation, variables })).resolves.toMatchObject({ diff --git a/backend/src/schema/types/type/EmailAddress.gql b/backend/src/schema/types/type/EmailAddress.gql index 7501a3e8c..4bf8ff724 100644 --- a/backend/src/schema/types/type/EmailAddress.gql +++ b/backend/src/schema/types/type/EmailAddress.gql @@ -18,7 +18,6 @@ type Mutation { avatarUpload: Upload locationName: String about: String - termsAndConditionsAgreedVersion: String - termsAndConditionsAgreedAt: String + termsAndConditionsAgreedVersion: String! ): User }