Add backend tests for custom queries

This commit is contained in:
Matt Rider 2019-08-06 10:58:30 +02:00
parent 9613250710
commit d795ee50a9

View File

@ -443,7 +443,6 @@ describe('emotions', () => {
}
}
`
describe('unauthenticated', () => {
it('throws authorization error', async () => {
client = new GraphQLClient(host)
@ -601,4 +600,55 @@ describe('emotions', () => {
})
})
})
describe('posts emotions count', () => {
let headers
let postsEmotionsCountByEmotionVariables
let postsEmotionsCountByCurrentUserVariables
const postsEmotionsCountByEmotionQuery = `
query($postId: ID!, $data: _EMOTEDInput!) {
postsEmotionsCountByEmotion(postId: $postId, data: $data)
}
`
const postsEmotionsCountByCurrentUserQuery = `
query($postId: ID!) {
postsEmotionsCountByCurrentUser(postId: $postId)
}
`
beforeEach(async () => {
headers = await login(authorParams)
client = new GraphQLClient(host, { headers })
await factory.emote({
from: authorParams.id,
to: 'p1376',
data: 'cry',
})
postsEmotionsCountByEmotionVariables = {
postId: 'p1376',
data: { emotion: 'cry' },
}
postsEmotionsCountByCurrentUserVariables = { postId: 'p1376' }
})
describe('postsEmotionsCountByEmotion', () => {
it("returns a post's emotions count", async () => {
await expect(
client.request(postsEmotionsCountByEmotionQuery, postsEmotionsCountByEmotionVariables),
).resolves.toEqual({ postsEmotionsCountByEmotion: 1 })
})
})
describe('postsEmotionsCountByEmotion', () => {
it("returns a currentUser's emotions on a post", async () => {
await expect(
client.request(
postsEmotionsCountByCurrentUserQuery,
postsEmotionsCountByCurrentUserVariables,
),
).resolves.toEqual({ postsEmotionsCountByCurrentUser: ['cry'] })
})
})
})
})