Added tests for SHOUT and FOLLOW relationships to make sure they have "createdAt" date.

This commit is contained in:
Kapil Jain 2019-10-16 22:47:02 -04:00
parent f73ff995e1
commit 6b72772bbb
3 changed files with 67 additions and 47 deletions

View File

@ -113,4 +113,4 @@ module.exports = {
target: 'Location', target: 'Location',
direction: 'out', direction: 'out',
}, },
} };

View File

@ -126,61 +126,69 @@ describe('follow', () => {
variables, variables,
}), }),
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { followUser: expectedUser }, data: {followUser: expectedUser},
errors: undefined, 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 = { test('I can`t follow myself', async () => {
followedBy: [], variables.id = user1.id
followedByCurrentUser: false, await expect(mutate({ mutation: mutationFollowUser, variables })).resolves.toMatchObject({
} data: { followUser: null },
await expect( errors: undefined,
query({ })
query: userQuery,
variables: { id: user1.id }, const expectedUser = {
}), followedBy: [],
).resolves.toMatchObject({ followedByCurrentUser: false,
data: { }
User: [expectedUser], await expect(
}, query({
errors: undefined, 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('I can unfollow a user', async () => {
test('throws authorization error', async () => { const expectedUser = {
authenticatedUser = null name: user2.name,
await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({ followedBy: [],
data: { unfollowUser: null }, followedByCurrentUser: false,
errors: [{ message: 'Not Authorised!' }], }
}) 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,
})
}) })
}) })
}) })
})

View File

@ -30,6 +30,10 @@ const queryPost = gql`
} }
` `
describe('shout and unshout posts', () => { describe('shout and unshout posts', () => {
let currentUser, postAuthor let currentUser, postAuthor
beforeAll(() => { beforeAll(() => {
@ -100,6 +104,14 @@ describe('shout and unshout posts', () => {
data: { Post: [{ id: 'another-user-post-id', shoutedBy: [{ id: 'current-user-id' }] }] }, data: { Post: [{ id: 'another-user-post-id', shoutedBy: [{ id: 'current-user-id' }] }] },
errors: undefined, 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 () => { it('can not shout my own post', async () => {