old stand

This commit is contained in:
ogerly 2019-09-12 16:37:30 +02:00
parent 33942f6475
commit 4b97131225
8 changed files with 53 additions and 20 deletions

View File

@ -87,12 +87,11 @@ module.exports = {
type: 'string',
allow: [null],
},
/* termsAndConditionsAgreedAt: {
termsAndConditionsAgreedAt: {
type: 'string',
isoDate: true,
allow: [null],
// required: true, TODO
}, */
},
shouted: {
type: 'relationship',
relationship: 'SHOUTED',

View File

@ -82,6 +82,7 @@ export default {
if (!regEx.test(termsAndConditionsAgreedVersion)) {
throw new UserInputError('Invalid version format!')
}
args.termsAndConditionsAgreedAt = new Date().toISOString()
let { nonce, email } = args
email = email.toLowerCase()

View File

@ -340,6 +340,7 @@ describe('SignupVerification', () => {
) {
id
termsAndConditionsAgreedVersion
termsAndConditionsAgreedAt
}
}
`
@ -352,6 +353,7 @@ describe('SignupVerification', () => {
password: '123',
email: 'john@example.org',
termsAndConditionsAgreedVersion: '0.0.1',
termsAndConditionsAgreedAt: null,
}
})
@ -444,11 +446,11 @@ describe('SignupVerification', () => {
expect(emails).toHaveLength(1)
})
it('is version of terms and conditions saved correctly', async () => {
it('if a current date of the General Terms and Conditions is available', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
data: {
SignupVerification: expect.objectContaining({
termsAndConditionsAgreedVersion: '0.0.1',
termsAndConditionsAgreedAt: expect.any(String),
}),
},
})

View File

@ -94,6 +94,7 @@ export default {
if (!regEx.test(termsAndConditionsAgreedVersion)) {
throw new ForbiddenError('Invalid version format!')
}
args.termsAndConditionsAgreedAt = new Date().toISOString()
}
args = await fileUpload(args, { file: 'avatarUpload', url: 'avatar' })
try {
@ -165,7 +166,6 @@ export default {
},
...Resolver('User', {
undefinedToNull: [
'termsAndConditionsAgreedVersion',
'actorId',
'avatar',
'coverImg',
@ -174,7 +174,7 @@ export default {
'locationName',
'about',
'termsAndConditionsAgreedVersion',
// TODO: 'termsAndConditionsAgreedAt',
'termsAndConditionsAgreedAt',
],
boolean: {
followedByCurrentUser:

View File

@ -84,6 +84,8 @@ describe('UpdateUser', () => {
password: '1234',
id: 'u47',
name: 'John Doe',
termsAndConditionsAgreedVersion: null,
termsAndConditionsAgreedAt: null,
}
variables = {
@ -102,6 +104,7 @@ describe('UpdateUser', () => {
id
name
termsAndConditionsAgreedVersion
termsAndConditionsAgreedAt
}
}
`
@ -171,12 +174,16 @@ describe('UpdateUser', () => {
)
})
it('given a new agreed version of terms and conditions', async () => {
describe('given a new agreed version of terms and conditions', () => {
beforeEach(async () => {
variables = { ...variables, termsAndConditionsAgreedVersion: '0.0.2' }
})
it('update termsAndConditionsAgreedVersion', async () => {
const expected = {
data: {
UpdateUser: expect.objectContaining({
termsAndConditionsAgreedVersion: '0.0.2',
termsAndConditionsAgreedAt: expect.any(String),
}),
},
}
@ -185,6 +192,27 @@ describe('UpdateUser', () => {
expected,
)
})
})
describe('given any attribute other than termsAndConditionsAgreedVersion', () => {
beforeEach(async () => {
variables = { ...variables, name: 'any name' }
})
it('update termsAndConditionsAgreedVersion', async () => {
const expected = {
data: {
UpdateUser: expect.objectContaining({
termsAndConditionsAgreedVersion: null,
termsAndConditionsAgreedAt: null,
}),
},
}
await expect(mutate({ mutation: updateUserMutation, variables })).resolves.toMatchObject(
expected,
)
})
})
it('rejects if version of terms and conditions has wrong format', async () => {
variables = {

View File

@ -19,5 +19,6 @@ type Mutation {
locationName: String
about: String
termsAndConditionsAgreedVersion: String
termsAndConditionsAgreedAt: String
): User
}

View File

@ -25,6 +25,7 @@ type User {
updatedAt: String
termsAndConditionsAgreedVersion: String
termsAndConditionsAgreedAt: String
friends: [User]! @relation(name: "FRIENDS", direction: "BOTH")
friendsCount: Int! @cypher(statement: "MATCH (this)<-[: FRIENDS]->(r: User) RETURN COUNT(DISTINCT r)")
@ -164,6 +165,7 @@ type Mutation {
locationName: String
about: String
termsAndConditionsAgreedVersion: String
termsAndConditionsAgreedAt: String
): User
DeleteUser(id: ID!, resource: [Deletable]): User

View File

@ -14,8 +14,8 @@ export default function create() {
role: 'user',
avatar: faker.internet.avatar(),
about: faker.lorem.paragraph(),
// termsAndConditionsAgreedAt: new Date().toISOString(),
termsAndConditionsAgreedVersion: '0.0.1',
termsAndConditionsAgreedAt: '2019-08-01T10:47:19.212Z',
}
defaults.slug = slugify(defaults.name, { lower: true })
args = {