mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
test current user query for active categories
This commit is contained in:
parent
bcaeee44fa
commit
860949dc6a
@ -20,7 +20,7 @@ export default {
|
||||
const result = await transaction.run(
|
||||
`
|
||||
MATCH (user:User {id: $id})
|
||||
MATCH (category:Category) WHERE NOT ((user)-[:NOT_INTERESTED_IN]->(category))
|
||||
OPTIONAL MATCH (category:Category) WHERE NOT ((user)-[:NOT_INTERESTED_IN]->(category))
|
||||
WITH user, [(user)<-[:OWNED_BY]-(medium:SocialMedia) | properties(medium) ] as media, category
|
||||
RETURN user {.*, socialMedia: media, activeCategories: collect(category.id) } as user
|
||||
`,
|
||||
|
||||
@ -6,6 +6,7 @@ import { createTestClient } from 'apollo-server-testing'
|
||||
import createServer, { context } from '../../server'
|
||||
import encode from '../../jwt/encode'
|
||||
import { getNeode } from '../../db/neo4j'
|
||||
import { categories } from '../../constants/categories'
|
||||
|
||||
const neode = getNeode()
|
||||
let query, mutate, variables, req, user
|
||||
@ -118,6 +119,7 @@ describe('currentUser', () => {
|
||||
}
|
||||
email
|
||||
role
|
||||
activeCategories
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -172,6 +174,49 @@ describe('currentUser', () => {
|
||||
}
|
||||
await respondsWith(expected)
|
||||
})
|
||||
|
||||
describe('with categories in DB', () => {
|
||||
beforeEach(async () => {
|
||||
await Promise.all(
|
||||
categories.map(async ({ icon, name }, index) => {
|
||||
await Factory.build('category', {
|
||||
id: `cat${index + 1}`,
|
||||
slug: name,
|
||||
name,
|
||||
icon,
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('returns all categories', async () => {
|
||||
const result = await query({ query: currentUserQuery, variables })
|
||||
expect(result.data.currentUser.activeCategories).toHaveLength(categories.length)
|
||||
})
|
||||
|
||||
describe('with categories saved for current user', () => {
|
||||
const saveCategorySettings = gql`
|
||||
mutation ($activeCategories: [String]) {
|
||||
saveCategorySettings(activeCategories: $activeCategories)
|
||||
}
|
||||
`
|
||||
beforeEach(async () => {
|
||||
await mutate({
|
||||
mutation: saveCategorySettings,
|
||||
variables: { activeCategories: ['cat1', 'cat3', 'cat5', 'cat7'] },
|
||||
})
|
||||
})
|
||||
|
||||
it('returns only the saved active categories', async () => {
|
||||
const result = await query({ query: currentUserQuery, variables })
|
||||
expect(result.data.currentUser.activeCategories).toHaveLength(4)
|
||||
expect(result.data.currentUser.activeCategories).toContain('cat1')
|
||||
expect(result.data.currentUser.activeCategories).toContain('cat3')
|
||||
expect(result.data.currentUser.activeCategories).toContain('cat5')
|
||||
expect(result.data.currentUser.activeCategories).toContain('cat7')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user