mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
tests
This commit is contained in:
parent
1bb0b7fce9
commit
8e5f5fefb3
@ -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',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user