Add authentication tests for AddPostEmotions, emotionsCount

This commit is contained in:
Matt Rider 2019-07-16 11:02:43 -03:00
parent c3edaa9d31
commit 16f077fe65
4 changed files with 81 additions and 0 deletions

View File

@ -167,6 +167,7 @@ const permissions = shield(
// RemoveBadgeRewarded: isAdmin,
reward: isAdmin,
unreward: isAdmin,
// why is this here? will we support buying/selling fruit??
// addFruitToBasket: isAuthenticated
follow: isAuthenticated,
unfollow: isAuthenticated,
@ -180,6 +181,7 @@ const permissions = shield(
DeleteUser: isDeletingOwnAccount,
requestPasswordReset: allow,
resetPassword: allow,
AddPostEmotions: isAuthenticated,
},
User: {
email: isMyOwn,

View File

@ -44,6 +44,7 @@ export default {
delete params.categoryIds
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
params.id = params.id || uuid()
let createPostCypher = `CREATE (post:Post {params})
WITH post
MATCH (author:User {id: $userId})

View File

@ -383,3 +383,77 @@ describe('DeletePost', () => {
})
})
})
describe('AddPostEmotions', () => {
let addPostEmotionsVariables
const addPostEmotionsMutation = `
mutation($from: _UserInput!, $to: _PostInput!, $data: _EMOTEDInput!) {
AddPostEmotions(from: $from, to: $to, data: $data) {
from {
id
}
to {
id
}
emotion
}
}
`
describe('emotions', () => {
beforeEach(async () => {
const asAuthor = Factory()
authorParams = {
id: 'u25',
email: 'wanna-add-emotions@example.org',
password: '1234',
}
await asAuthor.create('User', authorParams)
await asAuthor.authenticateAs(authorParams)
await asAuthor.create('Post', {
id: 'p1376',
title: postTitle,
content: postContent,
})
addPostEmotionsVariables = {
from: { id: authorParams.id },
to: { id: 'p1376' },
data: { emotion: 'happy' },
}
})
// it('supports setting emotions for a post', () => {})
describe('unauthenticated', () => {
it('throws authorization error', async () => {
client = new GraphQLClient(host)
await expect(
client.request(addPostEmotionsMutation, {
from: { id: 'u25' },
to: { id: 'p1376' },
data: { emotion: 'happy' },
}),
).rejects.toThrow('Not Authorised')
})
})
describe('authenticated as author', () => {
let headers
beforeEach(async () => {
headers = await login(authorParams)
client = new GraphQLClient(host, { headers })
})
it('adds an emotion to the post', async () => {
const expected = {
AddPostEmotions: {
from: addPostEmotionsVariables.from,
to: addPostEmotionsVariables.to,
emotion: 'happy',
},
}
await expect(
client.request(addPostEmotionsMutation, addPostEmotionsVariables),
).resolves.toEqual(expected)
})
})
})
})

View File

@ -50,6 +50,10 @@ type Post {
)
emotions: [EMOTED]
emotionsCount: Int!
@cypher(
statement: "MATCH (this)<-[emoted:EMOTED]-(:User) RETURN COUNT(DISTINCT emoted)"
)
}
type Mutation {