fix(backend): create message mutation

This commit is contained in:
Moriz Wahl 2023-06-20 16:05:19 +02:00
parent 5567ae475a
commit bbfaba83ee
2 changed files with 23 additions and 8 deletions

View File

@ -209,9 +209,17 @@ describe('Message', () => {
mutation: createMessageMutation(),
variables: {
roomId,
content: 'Another nice message to other chatting user',
content: 'A nice response message to chatting user',
}
})
authenticatedUser = await chattingUser.toJson()
await mutate({
mutation: createMessageMutation(),
variables: {
roomId,
content: 'And another nice message to other chatting user',
}
})
})
it('returns the messages', async () => {
@ -233,11 +241,18 @@ describe('Message', () => {
},
{
id: expect.any(String),
content: 'Another nice message to other chatting user',
content: 'A nice response message to chatting user',
author: {
id: 'other-chatting-user',
},
}
},
{
id: expect.any(String),
content: 'And another nice message to other chatting user',
author: {
id: 'chatting-user',
},
}
],
},
})

View File

@ -24,11 +24,11 @@ export default {
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createMessageCypher = `
MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId })
MERGE (currentUser)-[:CREATED]->(message:Message)-[:INSIDE]->(room)
ON CREATE SET
message.createdAt = toString(datetime()),
message.id = apoc.create.uuid(),
message.content = $content
CREATE (currentUser)-[:CREATED]->(message:Message {
createdAt: toString(datetime()),
id: apoc.create.uuid(),
content: $content
})-[:INSIDE]->(room)
RETURN message { .* }
`
const createMessageTxResponse = await transaction.run(