This commit is contained in:
Ulf Gebhardt 2025-04-02 00:20:55 +02:00
parent 1bb0b7fce9
commit 8e5f5fefb3
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -63,6 +63,12 @@ const saveCategorySettings = gql`
}
`
const updateOnlineStatus = gql`
mutation ($status: OnlineStatus!) {
updateOnlineStatus(status: $status)
}
`
beforeAll(async () => {
await cleanDatabase()
@ -722,3 +728,79 @@ describe('save category settings', () => {
})
})
})
describe('updateOnlineStatus', () => {
beforeEach(async () => {
user = await Factory.build('user', {
id: 'user',
role: 'user',
})
variables = {
status: 'online',
}
})
describe('not authenticated', () => {
beforeEach(async () => {
authenticatedUser = undefined
})
it('throws an error', async () => {
await expect(mutate({ mutation: updateOnlineStatus, variables })).resolves.toEqual(
expect.objectContaining({
errors: [
expect.objectContaining({
message: 'Not Authorized!',
}),
],
}),
)
})
})
describe('authenticated', () => {
beforeEach(async () => {
authenticatedUser = await user.toJson()
})
describe('set online', () => {
it('returns true and saves the user in the database as online', async () => {
await expect(mutate({ mutation: updateOnlineStatus, variables })).resolves.toEqual(
expect.objectContaining({
data: { updateOnlineStatus: true },
}),
)
const cypher = 'MATCH (u:User {id: $id}) RETURN u'
const result = await neode.cypher(cypher, { id: authenticatedUser.id })
const dbUser = neode.hydrateFirst(result, 'u', neode.model('User'))
await expect(dbUser.toJson()).resolves.toMatchObject({
lastOnlineStatus: 'online',
})
})
})
describe('set away', () => {
beforeEach(() => {
variables = {
status: 'away',
}
})
it('returns true and saves the user in the database as away', async () => {
await expect(mutate({ mutation: updateOnlineStatus, variables })).resolves.toEqual(
expect.objectContaining({
data: { updateOnlineStatus: true },
}),
)
const cypher = 'MATCH (u:User {id: $id}) RETURN u'
const result = await neode.cypher(cypher, { id: authenticatedUser.id })
const dbUser = neode.hydrateFirst(result, 'u', neode.model('User'))
await expect(dbUser.toJson()).resolves.toMatchObject({
lastOnlineStatus: 'away',
})
})
})
})
})