Refactor tests with Post model

This commit is contained in:
Robert Schäfer 2019-08-09 00:49:40 +02:00 committed by roschaefer
parent bc4bffdc52
commit cc1f932803
3 changed files with 83 additions and 39 deletions

View File

@ -48,12 +48,6 @@ module.exports = {
target: 'Badge', target: 'Badge',
direction: 'in', direction: 'in',
}, },
blocked: {
type: 'relationship',
relationship: 'BLOCKED',
target: 'User',
direction: 'out',
},
invitedBy: { type: 'relationship', relationship: 'INVITED', target: 'User', direction: 'in' }, invitedBy: { type: 'relationship', relationship: 'INVITED', target: 'User', direction: 'in' },
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
updatedAt: { updatedAt: {
@ -77,4 +71,10 @@ module.exports = {
eager: true, eager: true,
cascade: true, cascade: true,
}, },
blocked: {
type: 'relationship',
relationship: 'BLOCKED',
target: 'User',
direction: 'out',
},
} }

View File

@ -10,17 +10,18 @@ const instance = neode()
let currentUser let currentUser
let blockedUser let blockedUser
let authenticatedUser
let server let server
beforeEach(() => { beforeEach(() => {
currentUser = undefined authenticatedUser = undefined
;({ server } = createServer({ ;({ server } = createServer({
context: () => { context: () => {
return { return {
user: currentUser, user: authenticatedUser,
driver, driver,
cypherParams: { cypherParams: {
currentUserId: currentUser ? currentUser.id : null, currentUserId: authenticatedUser ? authenticatedUser.id : null,
}, },
} }
}, },
@ -62,7 +63,7 @@ describe('blockedUsers', () => {
id: 'u2', id: 'u2',
}) })
await currentUser.relateTo(blockedUser, 'blocked') await currentUser.relateTo(blockedUser, 'blocked')
currentUser = await currentUser.toJson() authenticatedUser = await currentUser.toJson()
}) })
it('returns a list of blocked users', async () => { it('returns a list of blocked users', async () => {
@ -115,7 +116,7 @@ describe('block', () => {
name: 'Current User', name: 'Current User',
id: 'u1', id: 'u1',
}) })
currentUser = await currentUser.toJson() authenticatedUser = await currentUser.toJson()
}) })
describe('block yourself', () => { describe('block yourself', () => {
@ -151,17 +152,8 @@ describe('block', () => {
}) })
it('unfollows the user', async () => { it('unfollows the user', async () => {
const user = await instance.find('User', currentUser.id) await currentUser.relateTo(blockedUser, 'following')
await user.relateTo(blockedUser, 'following') const queryUser = gql` query { User(id: "u2") { id isBlocked followedByCurrentUser } }`
const queryUser = gql`
query {
User(id: "u2") {
id
isBlocked
followedByCurrentUser
}
}
`
const { query } = createTestClient(server) const { query } = createTestClient(server)
await expect(query({ query: queryUser })).resolves.toEqual( await expect(query({ query: queryUser })).resolves.toEqual(
expect.objectContaining({ expect.objectContaining({
@ -176,12 +168,69 @@ describe('block', () => {
) )
}) })
describe('blocked user writes a post', () => { describe('given both the current user and the to-be-blocked user write a post', () => {
it.todo('disappears in the newsfeed of the current user') let postQuery
beforeEach(async () => {
const post1 = await instance.create('Post', {
id: 'p12',
title: 'A post written by the current user',
})
const post2 = await instance.create('Post', {
id: 'p23',
title: 'A post written by the blocked user',
})
await Promise.all([
post1.relateTo(currentUser, 'author'),
post2.relateTo(blockedUser, 'author')
])
postQuery = gql`query { Post(orderBy: createdAt_asc) { id title author { id name } } }`
}) })
describe('current user writes a post', () => { const bothPostsAreInTheNewsfeed = async () => {
it.todo('disappears in the newsfeed of the blocked user') const { query } = createTestClient(server)
await expect(query({ query: postQuery })).resolves.toEqual(
expect.objectContaining({
data: {
Post: [
{
id: 'p12',
title: 'A post written by the current user',
author: {
name: 'Current User',
id: 'u1',
}
},
{
id: 'p23',
title: 'A post written by the blocked user',
author: {
name: 'Blocked User',
id: 'u2',
}
},
],
},
}),
)
}
describe('from the perspective of the current user', () => {
it('both posts are in the newsfeed', bothPostsAreInTheNewsfeed)
describe('but if the current user blocks the other user', () => {
beforeEach(async () => { })
it.todo("the blocked user's post won't show up in the newsfeed of the current user")
})
})
describe('from the perspective of the blocked user', () => {
it('both posts are in the newsfeed', bothPostsAreInTheNewsfeed)
describe('but if the current user blocks the other user', () => {
it.todo("the current user's post won't show up in the newsfeed of the blocked user")
})
})
}) })
}) })
}) })
@ -218,7 +267,7 @@ describe('unblock', () => {
name: 'Current User', name: 'Current User',
id: 'u1', id: 'u1',
}) })
currentUser = await currentUser.toJson() authenticatedUser = await currentUser.toJson()
}) })
describe('unblock yourself', () => { describe('unblock yourself', () => {
@ -238,16 +287,11 @@ describe('unblock', () => {
}) })
describe('given another user', () => { describe('given another user', () => {
let user, blockedUser
beforeEach(async () => { beforeEach(async () => {
;[user, blockedUser] = await Promise.all([ blockedUser = await instance.create('User', {
instance.find('User', 'u1'),
instance.create('User', {
name: 'Blocked User', name: 'Blocked User',
id: 'u2', id: 'u2',
}), })
])
}) })
describe('unblocking a not yet blocked user', () => { describe('unblocking a not yet blocked user', () => {
@ -262,7 +306,7 @@ describe('unblock', () => {
describe('given a blocked user', () => { describe('given a blocked user', () => {
beforeEach(async () => { beforeEach(async () => {
await user.relateTo(blockedUser, 'blocked') await currentUser.relateTo(blockedUser, 'blocked')
}) })
it('unblocks a user', async () => { it('unblocks a user', async () => {

View File

@ -203,7 +203,7 @@
"name": "Name", "name": "Name",
"slug": "Slug" "slug": "Slug"
}, },
"empty": "So far, you did not block anybody.", "empty": "So far, you have not blocked anybody.",
"how-to": "You can block other users on their profile page via the content menu.", "how-to": "You can block other users on their profile page via the content menu.",
"block": "Block User", "block": "Block User",
"unblock": "Unblock User" "unblock": "Unblock User"