mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
* refactor: externalize all remaining queries in spec files * User with different queries due to permissions * fix notification:groups * fix hashtagsmiddleware * fix blockedUsers * fix softDeleteMiddleware * fix shouts.spec * fix userInteractions spec * fix mutedUsers spec * seocialMedia spec * fix notificationMiddleware.spec * fix user.spce & fix undefined activeCategories * fix notifications.spec * fix userInteractions.spec * fix blockedUsers & mutedUsers spec * remove unused comment * fix locations spec * fix orderByMiddleware & spec * fix lint * fix shout spec
100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
import { createTestClient } from 'apollo-server-testing'
|
|
|
|
import Factory, { cleanDatabase } from '@db/factories'
|
|
import { getNeode, getDriver } from '@db/neo4j'
|
|
import { Post } from '@graphql/queries/Post'
|
|
import createServer from '@src/server'
|
|
|
|
let query, aUser, bUser, post, authenticatedUser, variables
|
|
|
|
const driver = getDriver()
|
|
const neode = getNeode()
|
|
|
|
beforeAll(async () => {
|
|
await cleanDatabase()
|
|
|
|
aUser = await Factory.build('user', {
|
|
id: 'a-user',
|
|
})
|
|
bUser = await Factory.build('user', {
|
|
id: 'b-user',
|
|
})
|
|
post = await Factory.build('post')
|
|
authenticatedUser = await aUser.toJson()
|
|
const { server } = createServer({
|
|
context: () => {
|
|
return {
|
|
driver,
|
|
neode,
|
|
user: authenticatedUser,
|
|
cypherParams: {
|
|
currentUserId: authenticatedUser ? authenticatedUser.id : null,
|
|
},
|
|
}
|
|
},
|
|
})
|
|
query = createTestClient(server).query
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await cleanDatabase()
|
|
await driver.close()
|
|
})
|
|
|
|
describe('middleware/userInteractions', () => {
|
|
describe('given one post', () => {
|
|
it('does not change clickedCount when queried without ID', async () => {
|
|
await expect(query({ query: Post, variables })).resolves.toMatchObject({
|
|
data: {
|
|
Post: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
clickedCount: 0,
|
|
}),
|
|
]),
|
|
},
|
|
})
|
|
})
|
|
|
|
it('changes clickedCount when queried with ID', async () => {
|
|
variables = { id: post.get('id') }
|
|
await expect(query({ query: Post, variables })).resolves.toMatchObject({
|
|
data: {
|
|
Post: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
clickedCount: 1,
|
|
}),
|
|
]),
|
|
},
|
|
})
|
|
})
|
|
|
|
it('does not change clickedCount when same user queries the post again', async () => {
|
|
await expect(query({ query: Post, variables })).resolves.toMatchObject({
|
|
data: {
|
|
Post: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
clickedCount: 1,
|
|
}),
|
|
]),
|
|
},
|
|
})
|
|
})
|
|
|
|
it('changes clickedCount when another user queries the post', async () => {
|
|
authenticatedUser = await bUser.toJson()
|
|
await expect(query({ query: Post, variables })).resolves.toMatchObject({
|
|
data: {
|
|
Post: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
clickedCount: 2,
|
|
}),
|
|
]),
|
|
},
|
|
})
|
|
})
|
|
})
|
|
})
|