Merge branch '194-create-unit-test-for-badges' of https://github.com/Human-Connection/Nitro-Backend into 194-create-unit-test-for-badges

This commit is contained in:
Wolfgang Huß 2019-03-01 13:55:20 +01:00
commit d8502ef3a9
3 changed files with 96 additions and 10 deletions

View File

@ -32,7 +32,8 @@ const permissions = shield({
CreatePost: isAuthenticated,
// TODO UpdatePost: isOwner,
// TODO DeletePost: isOwner,
report: isAuthenticated
report: isAuthenticated,
CreateBadge: isAuthenticated
// addFruitToBasket: isAuthenticated
// CreateUser: allow,
},

View File

@ -0,0 +1,85 @@
import Factory from '../seed/factories'
import { GraphQLClient } from 'graphql-request'
import { host, login } from '../jest/helpers'
const factory = Factory()
describe('report', () => {
beforeEach(async () => {
await factory.create('User', {
email: 'user@example.org',
password: '1234'
})
await factory.create('User', {
id: 'u2',
name: 'moderator',
role: 'moderator',
email: 'moderator@example.org'
})
await factory.create('User', {
id: 'u3',
name: 'admin',
role: 'moderator',
email: 'admin@example.org'
})
})
afterEach(async () => {
await factory.cleanDatabase()
})
const params = {
id: 'b1',
key: 'indiegogo_en_racoon',
type: 'crowdfunding',
status: 'permanent',
icon: '/img/badges/indiegogo_en_racoon.svg'
}
describe('unauthenticated', () => {
let client
it('throws authorization error', async () => {
client = new GraphQLClient(host)
let { id, key, type, status, icon } = params
await expect(
client.request(`mutation {
CreateBadge(
id: "${id}",
key: "${key}",
type: ${type},
status: ${status},
icon: "${icon}"
) { id }
}`)
).rejects.toThrow('Not Authorised')
})
describe('authenticated admin', () => {
let headers
let response
let { id, key, type, status, icon } = params
beforeEach(async () => {
headers = await login({ email: 'admin@example.org', password: '1234' })
client = new GraphQLClient(host, { headers })
response = await client.request(`mutation {
CreateBadge(
id: "${id}",
key: "${key}",
type: ${type},
status: ${status},
icon: "${icon}"
) { id }
}`,
{ headers }
)
})
it('creates a badge', () => {
let { id } = response.CreateBadge
expect(response).toEqual({
CreateBadge: { id }
})
})
})
})
})

View File

@ -10,14 +10,14 @@ export default function (params) {
} = params
return `
mutation {
CreateBadge(
id: "${id}",
key: "${key}",
type: ${type},
status: ${status},
icon: "${icon}"
) { id }
}
mutation {
CreateBadge(
id: "${id}",
key: "${key}",
type: ${type},
status: ${status},
icon: "${icon}"
) { id }
}
`
}