mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Follow @mattwr18 code review 👍
This commit is contained in:
parent
10ae4abaae
commit
ef46f71c0d
@ -12,31 +12,39 @@ afterEach(async () => {
|
|||||||
|
|
||||||
describe('users', () => {
|
describe('users', () => {
|
||||||
describe('User', () => {
|
describe('User', () => {
|
||||||
const query = `query($email: String) { User(email: $email) { id } }`
|
describe('query by email address', () => {
|
||||||
const variables = { email: 'any-email-address@example.org' }
|
|
||||||
beforeEach(() => {
|
|
||||||
client = new GraphQLClient(host)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('is forbidden', async () => {
|
|
||||||
await expect(client.request(query, variables)).rejects.toThrow('Not Authorised')
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('as admin', () => {
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const userParams = {
|
await factory.create('User', { name: 'Johnny', email: 'any-email-address@example.org' })
|
||||||
role: 'admin',
|
|
||||||
email: 'admin@example.org',
|
|
||||||
password: '1234',
|
|
||||||
}
|
|
||||||
const factory = Factory()
|
|
||||||
await factory.create('User', userParams)
|
|
||||||
const headers = await login(userParams)
|
|
||||||
client = new GraphQLClient(host, { headers })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('is permitted', async () => {
|
const query = `query($email: String) { User(email: $email) { name } }`
|
||||||
await expect(client.request(query, variables)).resolves.toEqual({ User: [] })
|
const variables = { email: 'any-email-address@example.org' }
|
||||||
|
beforeEach(() => {
|
||||||
|
client = new GraphQLClient(host)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('is forbidden', async () => {
|
||||||
|
await expect(client.request(query, variables)).rejects.toThrow('Not Authorised')
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('as admin', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const userParams = {
|
||||||
|
role: 'admin',
|
||||||
|
email: 'admin@example.org',
|
||||||
|
password: '1234',
|
||||||
|
}
|
||||||
|
const factory = Factory()
|
||||||
|
await factory.create('User', userParams)
|
||||||
|
const headers = await login(userParams)
|
||||||
|
client = new GraphQLClient(host, { headers })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('is permitted', async () => {
|
||||||
|
await expect(client.request(query, variables)).resolves.toEqual({
|
||||||
|
User: [{ name: 'Johnny' }],
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -141,7 +141,7 @@ type Query {
|
|||||||
first: Int
|
first: Int
|
||||||
offset: Int
|
offset: Int
|
||||||
orderBy: [_UserOrdering]
|
orderBy: [_UserOrdering]
|
||||||
filter: _UserFilter # adding this would expose email
|
filter: _UserFilter
|
||||||
): [User]
|
): [User]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user