Follow @mattwr18's other suggestion

This commit is contained in:
Robert Schäfer 2019-07-03 23:03:06 +02:00
parent ef46f71c0d
commit 09ff79763d
2 changed files with 16 additions and 9 deletions

View File

@ -78,14 +78,14 @@ const invitationLimitReached = rule({
const result = await session.run(
`
MATCH (user:User {id:$id})-[:GENERATED]->(i:InvitationCode)
RETURN COUNT(i) as count
RETURN COUNT(i) >= 3 as limitReached
`,
{ id: user.id },
)
const [count] = result.records.map(record => {
return record.get('count').toNumber()
const [limitReached] = result.records.map(record => {
return record.get('limitReached')
})
return count >= 3
return limitReached
} catch (e) {
throw e
} finally {

View File

@ -128,14 +128,15 @@ describe('SignupByInvitation', () => {
}
})
it.todo('throws Authorization error')
describe('with invalid InvitationCode', () => {
describe('with valid email but invalid InvitationCode', () => {
beforeEach(() => {
variables.email = 'any-email@example.org'
variables.token = 'wut?'
})
it.todo('throws UserInputError')
it('throws UserInputError', async () => {
await expect(action()).rejects.toThrow('Invitation code already used or does not exist.')
})
})
describe('with valid InvitationCode', () => {
@ -238,6 +239,7 @@ describe('SignupByInvitation', () => {
})
describe('if the EmailAddress already exists but without user account', () => {
// shall we re-send the registration email?
it.todo('decide what to do')
})
})
@ -250,7 +252,12 @@ describe('Signup', () => {
Signup(email: $email) { email }
}`
it.todo('throws AuthorizationError')
it('throws AuthorizationError', async () => {
client = new GraphQLClient(host)
await expect(
client.request(mutation, { email: 'get-me-a-user-account@example.org' }),
).rejects.toThrow('Not Authorised')
})
describe('as admin', () => {
beforeEach(async () => {