mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
all categories saved returns empty array
This commit is contained in:
parent
32e7c8971c
commit
a65e306b85
@ -21,16 +21,21 @@ export default {
|
||||
`
|
||||
MATCH (user:User {id: $id})
|
||||
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
|
||||
OPTIONAL MATCH (cats:Category)
|
||||
WITH user, [(user)<-[:OWNED_BY]-(medium:SocialMedia) | properties(medium) ] AS media, category, toString(COUNT(cats)) AS categoryCount
|
||||
RETURN user {.*, socialMedia: media, activeCategories: collect(category.id) } AS user, categoryCount
|
||||
`,
|
||||
{ id: user.id },
|
||||
)
|
||||
log(result)
|
||||
return result.records.map((record) => record.get('user'))
|
||||
const [categoryCount] = result.records.map((record) => record.get('categoryCount'))
|
||||
const [currentUser] = result.records.map((record) => record.get('user'))
|
||||
// frontend expects empty array when all categories are selected
|
||||
if (currentUser.activeCategories.length === parseInt(categoryCount))
|
||||
currentUser.activeCategories = []
|
||||
return currentUser
|
||||
})
|
||||
try {
|
||||
const [currentUser] = await currentUserTransactionPromise
|
||||
const currentUser = await currentUserTransactionPromise
|
||||
return currentUser
|
||||
} finally {
|
||||
session.close()
|
||||
|
||||
@ -189,9 +189,12 @@ describe('currentUser', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('returns all categories', async () => {
|
||||
const result = await query({ query: currentUserQuery, variables })
|
||||
expect(result.data.currentUser.activeCategories).toHaveLength(categories.length)
|
||||
it('returns empty array for all categories', async () => {
|
||||
await respondsWith({
|
||||
data: {
|
||||
currentUser: expect.objectContaining({ activeCategories: [] }),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe('with categories saved for current user', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user