message query is not working as expected

This commit is contained in:
Moriz Wahl 2023-06-15 16:26:55 +02:00
parent d2beca22c9
commit 610d538ca9
3 changed files with 135 additions and 2 deletions

View File

@ -36,6 +36,8 @@ afterAll(async () => {
describe('Message', () => {
let roomId: string
beforeAll(async () => {
;[chattingUser, otherChattingUser, notChattingUser] = await Promise.all([
Factory.build(
@ -88,6 +90,120 @@ describe('Message', () => {
})
})
})
describe('room exists', () => {
beforeAll(async () => {
const room = await mutate({
mutation: createRoomMutation(),
variables: {
userId: 'other-chatting-user',
},
})
roomId = room.data.CreateRoom.id
})
describe('user chats in room', () => {
it('returns the message', async () => {
await expect(mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'Some nice message to other chatting user',
} })).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: {
id: expect.any(String),
content: 'Some nice message to other chatting user',
},
},
})
})
})
describe('user does not chat in room', () => {
beforeAll(async () => {
authenticatedUser = await notChattingUser.toJson()
})
it('returns null', async () => {
await expect(mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'I have no access to this room!',
} })).resolves.toMatchObject({
errors: undefined,
data: {
CreateMessage: null,
},
})
})
})
})
})
})
describe('message query', () => {
describe('unauthenticated', () => {
beforeAll(() => {
authenticatedUser = null
})
it('throws authorization error', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId: 'some-id' }
})).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
})
describe('authenticated', () => {
beforeAll(async () => {
authenticatedUser = await otherChattingUser.toJson()
})
describe('room does not exists', () => {
it('returns null', async () => {
await expect(query({
query: messageQuery(),
variables: {
roomId: 'some-id'
},
})).resolves.toMatchObject({
errors: undefined,
data: {
Message: [],
},
})
})
})
describe('room exists with authenticated user chatting', () => {
it('returns null', async () => {
console.log(roomId)
await expect(query({
query: messageQuery(),
variables: {
roomId,
},
})).resolves.toMatchObject({
errors: undefined,
data: {
Message: [{
id: expect.any(String),
content: 'Some nice message to other chatting user',
author: {
id: 'chatting-user',
},
}],
},
})
})
})
})
})
})

View File

@ -1,15 +1,22 @@
import { v4 as uuid } from 'uuid'
import { neo4jgraphql } from 'neo4j-graphql-js'
import Resolver from './helpers/Resolver'
export default {
Query: {
Message: async (object, params, context, resolveInfo) => {
if (!params.filter) params.filter = {}
Message: async (object, params, context, resolveInfo) => {
console.log('message query', params)
const { roomId } = params
// if (!params.filter) params.filter = {}
/*
params.filter.room = {
id_in: [roomId],
users_some: {
id: context.user.id,
},
}
*/
console.log(params.filter)
return neo4jgraphql(object, params, context, resolveInfo)
},
},
@ -47,4 +54,12 @@ export default {
}
},
},
Message: {
...Resolver('Message', {
hasOne: {
author: '<-[:CREATED]-(related:User)',
room: '-[:INSIDE]->(related:Room)',
}
}),
}
}

View File

@ -1,6 +1,8 @@
input _RoomFilter {
AND: [_RoomFilter!]
OR: [_RoomFilter!]
id: ID
id_in: [ID!]
users_some: _UserFilter
}