mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
feat(backend): message properties
This commit is contained in:
parent
c66e958760
commit
6a3ec44f4d
@ -21,11 +21,13 @@ export const messageQuery = () => {
|
|||||||
return gql`
|
return gql`
|
||||||
query($roomId: ID!) {
|
query($roomId: ID!) {
|
||||||
Message(roomId: $roomId) {
|
Message(roomId: $roomId) {
|
||||||
|
_id
|
||||||
id
|
id
|
||||||
content
|
content
|
||||||
author {
|
senderId
|
||||||
id
|
username
|
||||||
}
|
avatar
|
||||||
|
date
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -184,20 +184,23 @@ describe('Message', () => {
|
|||||||
|
|
||||||
describe('room exists with authenticated user chatting', () => {
|
describe('room exists with authenticated user chatting', () => {
|
||||||
it('returns the messages', async () => {
|
it('returns the messages', async () => {
|
||||||
await expect(query({
|
const result = await query({
|
||||||
query: messageQuery(),
|
query: messageQuery(),
|
||||||
variables: {
|
variables: {
|
||||||
roomId,
|
roomId,
|
||||||
},
|
},
|
||||||
})).resolves.toMatchObject({
|
})
|
||||||
|
expect(result).toMatchObject({
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
data: {
|
data: {
|
||||||
Message: [{
|
Message: [{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
|
_id: result.data.Message[0].id,
|
||||||
content: 'Some nice message to other chatting user',
|
content: 'Some nice message to other chatting user',
|
||||||
author: {
|
senderId: 'chatting-user',
|
||||||
id: 'chatting-user',
|
username: 'Chatting User',
|
||||||
},
|
avatar: expect.any(String),
|
||||||
|
date: expect.any(String),
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -235,29 +238,32 @@ describe('Message', () => {
|
|||||||
{
|
{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
content: 'Some nice message to other chatting user',
|
content: 'Some nice message to other chatting user',
|
||||||
author: {
|
senderId: 'chatting-user',
|
||||||
id: 'chatting-user',
|
username: 'Chatting User',
|
||||||
},
|
avatar: expect.any(String),
|
||||||
|
date: expect.any(String),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
content: 'A nice response message to chatting user',
|
content: 'A nice response message to chatting user',
|
||||||
author: {
|
senderId: 'other-chatting-user',
|
||||||
id: 'other-chatting-user',
|
username: 'Other Chatting User',
|
||||||
},
|
avatar: expect.any(String),
|
||||||
|
date: expect.any(String),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
content: 'And another nice message to other chatting user',
|
content: 'And another nice message to other chatting user',
|
||||||
author: {
|
senderId: 'chatting-user',
|
||||||
id: 'chatting-user',
|
username: 'Chatting User',
|
||||||
},
|
avatar: expect.any(String),
|
||||||
}
|
date: expect.any(String),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('room exists, authenticated user not in room', () => {
|
describe('room exists, authenticated user not in room', () => {
|
||||||
|
|||||||
@ -13,7 +13,13 @@ export default {
|
|||||||
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((message) => {
|
||||||
|
message._id = message.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resolved
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
|
|||||||
@ -11,6 +11,11 @@ type Message {
|
|||||||
|
|
||||||
author: User! @relation(name: "CREATED", direction: "IN")
|
author: User! @relation(name: "CREATED", direction: "IN")
|
||||||
room: Room! @relation(name: "INSIDE", direction: "OUT")
|
room: Room! @relation(name: "INSIDE", direction: "OUT")
|
||||||
|
|
||||||
|
senderId: String! @cypher(statement: "MATCH (this)<-[:CREATED]-(user:User) RETURN user.id")
|
||||||
|
username: String! @cypher(statement: "MATCH (this)<-[:CREATED]-(user:User) RETURN user.name")
|
||||||
|
avatar: String @cypher(statement: "MATCH (this)<-[:CREATED]-(:User)-[:AVATAR_IMAGE]->(image:Image) RETURN image.url")
|
||||||
|
date: String! @cypher(statement: "RETURN this.createdAt")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user