diff --git a/backend/src/models/User.js b/backend/src/models/User.js index a02ace625..773b83c02 100644 --- a/backend/src/models/User.js +++ b/backend/src/models/User.js @@ -113,4 +113,4 @@ module.exports = { target: 'Location', direction: 'out', }, -} +}; diff --git a/backend/src/schema/resolvers/follow.spec.js b/backend/src/schema/resolvers/follow.spec.js index 7b801d377..56336a2c6 100644 --- a/backend/src/schema/resolvers/follow.spec.js +++ b/backend/src/schema/resolvers/follow.spec.js @@ -126,61 +126,69 @@ describe('follow', () => { variables, }), ).resolves.toMatchObject({ - data: { followUser: expectedUser }, + data: {followUser: expectedUser}, errors: undefined, }) + // Test to make sure FOLLOWS relationship has "createdAt" date. + let 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({ - data: { followUser: null }, - errors: undefined, - }) - const expectedUser = { - followedBy: [], - followedByCurrentUser: false, - } - await expect( - query({ - query: userQuery, - variables: { id: user1.id }, - }), - ).resolves.toMatchObject({ - data: { - User: [expectedUser], - }, - errors: undefined, +test('I can`t follow myself', async () => { + variables.id = user1.id + await expect(mutate({ mutation: mutationFollowUser, variables })).resolves.toMatchObject({ + data: { followUser: null }, + errors: undefined, + }) + + const expectedUser = { + followedBy: [], + followedByCurrentUser: false, + } + await expect( + query({ + query: userQuery, + variables: { id: user1.id }, + }), + ).resolves.toMatchObject({ + data: { + User: [expectedUser], + }, + errors: undefined, + }) +}) +}) +describe('unfollow user', () => { + beforeEach(async () => { + variables = { id: user2.id } + await mutate({ mutation: mutationFollowUser, variables }) + }) + + describe('unauthenticated follow', () => { + test('throws authorization error', async () => { + authenticatedUser = null + await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({ + data: { unfollowUser: null }, + errors: [{ message: 'Not Authorised!' }], }) }) }) - describe('unfollow user', () => { - beforeEach(async () => { - variables = { id: user2.id } - await mutate({ mutation: mutationFollowUser, variables }) - }) - describe('unauthenticated follow', () => { - test('throws authorization error', async () => { - authenticatedUser = null - await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({ - data: { unfollowUser: null }, - errors: [{ message: 'Not Authorised!' }], - }) - }) - }) - - test('I can unfollow a user', async () => { - const expectedUser = { - name: user2.name, - followedBy: [], - followedByCurrentUser: false, - } - await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({ - data: { unfollowUser: expectedUser }, - errors: undefined, - }) + test('I can unfollow a user', async () => { + const expectedUser = { + name: user2.name, + followedBy: [], + followedByCurrentUser: false, + } + await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({ + data: { unfollowUser: expectedUser }, + errors: undefined, }) }) }) +}) diff --git a/backend/src/schema/resolvers/shout.spec.js b/backend/src/schema/resolvers/shout.spec.js index 63617541e..ee153404c 100644 --- a/backend/src/schema/resolvers/shout.spec.js +++ b/backend/src/schema/resolvers/shout.spec.js @@ -30,6 +30,10 @@ const queryPost = gql` } ` + + + + describe('shout and unshout posts', () => { let currentUser, postAuthor beforeAll(() => { @@ -100,6 +104,14 @@ describe('shout and unshout posts', () => { data: { Post: [{ id: 'another-user-post-id', shoutedBy: [{ id: 'current-user-id' }] }] }, errors: undefined, }) + // Test to make sure SHOUT relationship has "createdAt" date. + let 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 () => {