Merge pull request #1853 from Human-Connection/219-add-createDate-follow-shout

Added createdAt date for follow and shout
This commit is contained in:
mattwr18 2019-10-21 10:13:20 +02:00 committed by GitHub
commit 3163f6c9b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13248 additions and 1 deletions

13206
backend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -28,12 +28,18 @@ module.exports = {
relationship: 'FOLLOWS',
target: 'User',
direction: 'out',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
},
},
followedBy: {
type: 'relationship',
relationship: 'FOLLOWS',
target: 'User',
direction: 'in',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
},
},
friends: { type: 'relationship', relationship: 'FRIENDS', target: 'User', direction: 'both' },
disabledBy: {
@ -98,6 +104,9 @@ module.exports = {
relationship: 'SHOUTED',
target: 'Post',
direction: 'out',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
},
},
isIn: {
type: 'relationship',

View File

@ -131,6 +131,21 @@ describe('follow', () => {
})
})
test('adds `createdAt` to `FOLLOW` relationship', async () => {
await mutate({
mutation: mutationFollowUser,
variables,
})
const relation = await neode.cypher(
'MATCH (user:User {id: {id}})-[relationship:FOLLOWS]->(followed:User) WHERE relationship.createdAt IS NOT NULL RETURN relationship',
{ id: 'u1' },
)
const relationshipProperties = relation.records.map(
record => record.get('relationship').properties.createdAt,
)
expect(relationshipProperties[0]).toEqual(expect.any(String))
})
test('I can`t follow myself', async () => {
variables.id = user1.id
await expect(mutate({ mutation: mutationFollowUser, variables })).resolves.toMatchObject({
@ -155,6 +170,7 @@ describe('follow', () => {
})
})
})
describe('unfollow user', () => {
beforeEach(async () => {
variables = { id: user2.id }

View File

@ -7,7 +7,7 @@ export default {
const transactionRes = await session.run(
`MATCH (node {id: $id})<-[:WROTE]-(userWritten:User), (user:User {id: $userId})
WHERE $type IN labels(node) AND NOT userWritten.id = $userId
MERGE (user)-[relation:SHOUTED]->(node)
MERGE (user)-[relation:SHOUTED{createdAt:toString(datetime())}]->(node)
RETURN COUNT(relation) > 0 as isShouted`,
{
id,

View File

@ -102,6 +102,22 @@ describe('shout and unshout posts', () => {
})
})
it('adds `createdAt` to `SHOUT` relationship', async () => {
variables = { id: 'another-user-post-id' }
await mutate({ mutation: mutationShoutPost, variables })
const relation = await instance.cypher(
'MATCH (user:User {id: $userId1})-[relationship:SHOUTED]->(node {id: $userId2}) WHERE relationship.createdAt IS NOT NULL RETURN relationship',
{
userId1: 'current-user-id',
userId2: 'another-user-post-id',
},
)
const relationshipProperties = relation.records.map(
record => record.get('relationship').properties.createdAt,
)
expect(relationshipProperties[0]).toEqual(expect.any(String))
})
it('can not shout my own post', async () => {
variables = { id: 'current-user-post-id' }
await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({