mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Start unit testing report feature
This commit is contained in:
parent
a473e8e059
commit
40c210a0ce
@ -1,7 +1,7 @@
|
||||
import { request } from 'graphql-request'
|
||||
import { GraphQLClient, request } from 'graphql-request'
|
||||
import { create, cleanDatabase } from './seed/factories'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import { host } from './jest/helpers'
|
||||
import { host, login } from './jest/helpers'
|
||||
|
||||
describe('login', () => {
|
||||
const mutation = (params) => {
|
||||
@ -60,3 +60,60 @@ describe('login', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('report', () => {
|
||||
beforeEach(async () => {
|
||||
await create('user', {
|
||||
email: 'test@example.org',
|
||||
password: '1234'
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await cleanDatabase()
|
||||
})
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
let client
|
||||
it('throws authorization error', async () => {
|
||||
client = new GraphQLClient(host)
|
||||
await expect(
|
||||
client.request(`mutation {
|
||||
report(
|
||||
description: "I don't like this user",
|
||||
resource: {
|
||||
id: "u1",
|
||||
type: user
|
||||
}
|
||||
) { id, createdAt }
|
||||
}`)
|
||||
).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
|
||||
describe('authenticated', () => {
|
||||
let headers
|
||||
let response
|
||||
beforeEach(async () => {
|
||||
headers = await login({ email: 'test@example.org', password: '1234' })
|
||||
client = new GraphQLClient(host, { headers })
|
||||
response = await client.request(`mutation {
|
||||
report(
|
||||
description: "I don't like this user",
|
||||
resource: {
|
||||
id: "u1",
|
||||
type: user
|
||||
}
|
||||
) { id, createdAt }
|
||||
}`,
|
||||
{ headers }
|
||||
)
|
||||
})
|
||||
it('creates a report', () => {
|
||||
let { id, createdAt } = response.report
|
||||
expect(response).toEqual({
|
||||
report: { id, createdAt }
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { request } from 'graphql-request'
|
||||
|
||||
// this is the to-be-tested server host
|
||||
// not to be confused with the seeder host
|
||||
export const host = 'http://127.0.0.1:4123'
|
||||
|
||||
export async function authenticatedHeaders ({ email, password }) {
|
||||
export async function login ({ email, password }) {
|
||||
const mutation = `
|
||||
mutation {
|
||||
login(email:"${email}", password:"${password}"){
|
||||
@ -13,4 +15,4 @@ export async function authenticatedHeaders ({ email, password }) {
|
||||
return {
|
||||
authorization: `Bearer ${response.login.token}`
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { create, cleanDatabase } from '../seed/factories'
|
||||
import { host, authenticatedHeaders } from '../jest/helpers'
|
||||
import { host, login } from '../jest/helpers'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
|
||||
describe('authorization', () => {
|
||||
@ -45,7 +45,7 @@ describe('authorization', () => {
|
||||
|
||||
describe('as owner', () => {
|
||||
it('exposes the owner\'s email address', async () => {
|
||||
headers = await authenticatedHeaders({
|
||||
headers = await login({
|
||||
email: 'owner@example.org',
|
||||
password: 'iamtheowner'
|
||||
})
|
||||
@ -55,7 +55,7 @@ describe('authorization', () => {
|
||||
|
||||
describe('as someone else', () => {
|
||||
it('does not expose the owner\'s email address', async () => {
|
||||
headers = await authenticatedHeaders({
|
||||
headers = await login({
|
||||
email: 'someone@example.org',
|
||||
password: 'else'
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user