mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Add authentication tests for AddPostEmotions, emotionsCount
This commit is contained in:
parent
c3edaa9d31
commit
16f077fe65
@ -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,
|
||||
|
||||
@ -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})
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -50,6 +50,10 @@ type Post {
|
||||
)
|
||||
|
||||
emotions: [EMOTED]
|
||||
emotionsCount: Int!
|
||||
@cypher(
|
||||
statement: "MATCH (this)<-[emoted:EMOTED]-(:User) RETURN COUNT(DISTINCT emoted)"
|
||||
)
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user