mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Implement unauthenticated part
This commit is contained in:
parent
8a05de5b2d
commit
3b6cd55c0f
@ -1,5 +1,66 @@
|
||||
import Factory from '../../seed/factories'
|
||||
import { gql } from '../../jest/helpers'
|
||||
import { getDriver, neode as getNeode } from '../../bootstrap/neo4j'
|
||||
import createServer from '../../server'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
|
||||
const factory = Factory()
|
||||
const neode = getNeode()
|
||||
|
||||
let mutate
|
||||
let authenticatedUser
|
||||
let user
|
||||
let variables
|
||||
const driver = getDriver()
|
||||
|
||||
beforeEach(async () => {
|
||||
variables = {}
|
||||
})
|
||||
|
||||
beforeAll(() => {
|
||||
const { server } = createServer({
|
||||
context: () => {
|
||||
return {
|
||||
driver,
|
||||
neode,
|
||||
user: authenticatedUser,
|
||||
}
|
||||
},
|
||||
})
|
||||
mutate = createTestClient(server).mutate
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await factory.cleanDatabase()
|
||||
})
|
||||
|
||||
describe('AddEmailAddress', () => {
|
||||
it.todo('throws AuthorizationError')
|
||||
const mutation = gql`
|
||||
mutation($email: String!) {
|
||||
AddEmailAddress(email: $email){
|
||||
email
|
||||
verifiedAt
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
`
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, email: 'new-email@example.org' }
|
||||
})
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
beforeEach(() => {
|
||||
authenticatedUser = null
|
||||
})
|
||||
|
||||
it('throws AuthorizationError', async () => {
|
||||
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
|
||||
data: { AddEmailAddress: null },
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticated', () => {
|
||||
it.todo('creates a new unverified `EmailAddress` node')
|
||||
it.todo('connects EmailAddress to the authenticated user')
|
||||
@ -7,11 +68,40 @@ describe('AddEmailAddress', () => {
|
||||
describe('even if an unverified `EmailAddress` already exists with that email', () =>{
|
||||
it.todo('creates a new unverified `EmailAddress` node')
|
||||
})
|
||||
|
||||
describe('but if a verified `EmailAddress` already exists with that email', () =>{
|
||||
it.todo('throws UserInputError because of unique constraints')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('VerifyEmailAddress', () => {
|
||||
it.todo('throws AuthorizationError')
|
||||
const mutation = gql`
|
||||
mutation($email: String!, $nonce: String!) {
|
||||
VerifyEmailAddress(email: $email, nonce: $nonce){
|
||||
email
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, email: 'to-be-verified@example.org', nonce: '123456' }
|
||||
})
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
beforeEach(() => {
|
||||
authenticatedUser = null
|
||||
})
|
||||
|
||||
it('throws AuthorizationError', async () => {
|
||||
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
|
||||
data: { VerifyEmailAddress: null },
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticated', () => {
|
||||
describe('if no unverified `EmailAddress` node exists', () => {
|
||||
it.todo('throws UserInputError')
|
||||
|
||||
@ -20,4 +20,9 @@ type Mutation {
|
||||
about: String
|
||||
termsAndConditionsAgreedVersion: String!
|
||||
): User
|
||||
AddEmailAddress(email: String!): EmailAddress
|
||||
VerifyEmailAddress(
|
||||
nonce: String!
|
||||
email: String!
|
||||
): EmailAddress
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user