Merge branch 'master' into remove-activity-pub

This commit is contained in:
Ulf Gebhardt 2023-06-21 06:55:22 +02:00 committed by GitHub
commit 4d91b3f5b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 13 deletions

View File

@ -9,6 +9,7 @@ export const createRoomMutation = () => {
userId: $userId userId: $userId
) { ) {
id id
roomId
} }
} }
` `
@ -19,8 +20,15 @@ export const roomQuery = () => {
query { query {
Room { Room {
id id
roomId
roomName
users { users {
_id
id id
name
avatar {
url
}
} }
} }
} }

View File

@ -209,9 +209,17 @@ describe('Message', () => {
mutation: createMessageMutation(), mutation: createMessageMutation(),
variables: { variables: {
roomId, 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 () => { it('returns the messages', async () => {
@ -233,11 +241,18 @@ describe('Message', () => {
}, },
{ {
id: expect.any(String), id: expect.any(String),
content: 'Another nice message to other chatting user', content: 'A nice response message to chatting user',
author: { author: {
id: 'other-chatting-user', 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 writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createMessageCypher = ` const createMessageCypher = `
MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId }) MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId })
MERGE (currentUser)-[:CREATED]->(message:Message)-[:INSIDE]->(room) CREATE (currentUser)-[:CREATED]->(message:Message {
ON CREATE SET createdAt: toString(datetime()),
message.createdAt = toString(datetime()), id: apoc.create.uuid(),
message.id = apoc.create.uuid(), content: $content
message.content = $content })-[:INSIDE]->(room)
RETURN message { .* } RETURN message { .* }
` `
const createMessageTxResponse = await transaction.run( const createMessageTxResponse = await transaction.run(

View File

@ -102,11 +102,12 @@ describe('Room', () => {
}, },
}) })
roomId = result.data.CreateRoom.id roomId = result.data.CreateRoom.id
await expect(result).toMatchObject({ expect(result).toMatchObject({
errors: undefined, errors: undefined,
data: { data: {
CreateRoom: { CreateRoom: {
id: expect.any(String), id: expect.any(String),
roomId: result.data.CreateRoom.id,
}, },
}, },
}) })
@ -153,18 +154,31 @@ describe('Room', () => {
}) })
it('returns the room', async () => { it('returns the room', async () => {
await expect(query({ query: roomQuery() })).resolves.toMatchObject({ const result = await query({ query: roomQuery() })
expect(result).toMatchObject({
errors: undefined, errors: undefined,
data: { data: {
Room: [ Room: [
{ {
id: expect.any(String), id: expect.any(String),
roomId: result.data.Room[0].id,
roomName: 'Other Chatting User',
users: expect.arrayContaining([ users: expect.arrayContaining([
{ {
_id: 'chatting-user',
id: 'chatting-user', id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
}, },
{ {
_id: 'other-chatting-user',
id: 'other-chatting-user', id: 'other-chatting-user',
name: 'Other Chatting User',
avatar: {
url: expect.any(String),
},
}, },
]), ]),
}, },
@ -180,18 +194,31 @@ describe('Room', () => {
}) })
it('returns the room', async () => { it('returns the room', async () => {
await expect(query({ query: roomQuery() })).resolves.toMatchObject({ const result = await query({ query: roomQuery() })
expect(result).toMatchObject({
errors: undefined, errors: undefined,
data: { data: {
Room: [ Room: [
{ {
id: expect.any(String), id: expect.any(String),
roomId: result.data.Room[0].id,
roomName: 'Chatting User',
users: expect.arrayContaining([ users: expect.arrayContaining([
{ {
_id: 'chatting-user',
id: 'chatting-user', id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
}, },
{ {
_id: 'other-chatting-user',
id: 'other-chatting-user', id: 'other-chatting-user',
name: 'Other Chatting User',
avatar: {
url: expect.any(String),
},
}, },
]), ]),
}, },

View File

@ -8,7 +8,18 @@ export default {
params.filter.users_some = { params.filter.users_some = {
id: context.user.id, id: context.user.id,
} }
return neo4jgraphql(object, params, context, resolveInfo) const resolved = await neo4jgraphql(object, params, context, resolveInfo)
if (resolved) {
resolved.forEach((room) => {
if (room.users) {
room.roomName = room.users.filter((user) => user.id !== context.user.id)[0].name
room.users.forEach((user) => {
user._id = user.id
})
}
})
}
return resolved
}, },
}, },
Mutation: { Mutation: {
@ -37,6 +48,9 @@ export default {
}) })
try { try {
const room = await writeTxResultPromise const room = await writeTxResultPromise
if (room) {
room.roomId = room.id
}
return room return room
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)

View File

@ -10,7 +10,10 @@ type Room {
createdAt: String createdAt: String
updatedAt: String updatedAt: String
users: [User]! @relation(name: "CHATS_IN", direction: "IN") users: [User]! @relation(name: "CHATS_IN", direction: "IN")
roomId: String! @cypher(statement: "RETURN this.id")
roomName: String! ## @cypher(statement: "MATCH (this)<-[:CHATS_IN]-(user:User) WHERE NOT user.id = $cypherParams.currentUserId RETURN user[0].name")
} }
type Mutation { type Mutation {