mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
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:
commit
d8502ef3a9
@ -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,
|
||||
},
|
||||
|
||||
85
src/resolvers/badges.spec.js
Normal file
85
src/resolvers/badges.spec.js
Normal 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 }
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -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 }
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user