mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Write and refactor backend test which are supposed to fail at first
Implemented the new properties in the GraphQL schema.
This commit is contained in:
parent
0517e38873
commit
6ad9dc27e9
@ -7,7 +7,7 @@ const factory = Factory()
|
||||
const instance = neode()
|
||||
|
||||
describe('report', () => {
|
||||
let mutation
|
||||
let reportMutation
|
||||
let headers
|
||||
let returnedObject
|
||||
let variables
|
||||
@ -16,9 +16,11 @@ describe('report', () => {
|
||||
const categoryIds = ['cat9']
|
||||
|
||||
beforeEach(async () => {
|
||||
returnedObject = '{ description }'
|
||||
returnedObject = '{ id }'
|
||||
variables = {
|
||||
id: 'whatever',
|
||||
reasonCategory: 'reason-category-dummy',
|
||||
description: 'Violates code of conduct !!!',
|
||||
}
|
||||
headers = {}
|
||||
user = await factory.create('User', {
|
||||
@ -45,54 +47,69 @@ describe('report', () => {
|
||||
|
||||
let client
|
||||
const action = () => {
|
||||
mutation = `
|
||||
mutation($id: ID!) {
|
||||
report(
|
||||
id: $id,
|
||||
description: "Violates code of conduct"
|
||||
) ${returnedObject}
|
||||
// because of the template `${returnedObject}` the 'gql' tag from 'jest/helpers' is not working here
|
||||
reportMutation = `
|
||||
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
|
||||
report( id: $id, reasonCategory: $reasonCategory, description: $description) ${returnedObject}
|
||||
}
|
||||
`
|
||||
client = new GraphQLClient(host, {
|
||||
headers,
|
||||
})
|
||||
return client.request(mutation, variables)
|
||||
return client.request(reportMutation, variables)
|
||||
}
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
await expect(action()).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticated', () => {
|
||||
beforeEach(async () => {
|
||||
headers = await login({
|
||||
email: 'test@example.org',
|
||||
password: '1234',
|
||||
describe('authenticated', () => {
|
||||
beforeEach(async () => {
|
||||
headers = await login({
|
||||
email: 'test@example.org',
|
||||
password: '1234',
|
||||
})
|
||||
})
|
||||
|
||||
describe('invalid resource id', () => {
|
||||
it('returns null', async () => {
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: null,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('invalid resource id', () => {
|
||||
it('returns null', async () => {
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: null,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('valid resource id', () => {
|
||||
describe('valid resource id', () => {
|
||||
describe('reported resource is a user', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
id: 'u2',
|
||||
}
|
||||
})
|
||||
/*
|
||||
it('creates a report', async () => {
|
||||
await expect(action()).resolves.toEqual({
|
||||
type: null,
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
it('returns type "User"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'User',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns resource in user attribute', async () => {
|
||||
returnedObject = '{ user { name } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
user: {
|
||||
name: 'abusive-user',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns the submitter', async () => {
|
||||
returnedObject = '{ submitter { email } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
@ -104,138 +121,145 @@ describe('report', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('reported resource is a user', () => {
|
||||
it('returns type "User"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'User',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns resource in user attribute', async () => {
|
||||
returnedObject = '{ user { name } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
user: {
|
||||
name: 'abusive-user',
|
||||
},
|
||||
},
|
||||
})
|
||||
it('returns the reason category', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
reasonCategory: 'my-category',
|
||||
}
|
||||
returnedObject = '{ reasonCategory }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
reasonCategory: 'my-category',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
describe('reported resource is a post', () => {
|
||||
beforeEach(async () => {
|
||||
await factory.create('Post', {
|
||||
author: user,
|
||||
id: 'p23',
|
||||
title: 'Matt and Robert having a pair-programming',
|
||||
categoryIds,
|
||||
})
|
||||
variables = {
|
||||
id: 'p23',
|
||||
}
|
||||
it('returns the reason description', async () => {
|
||||
variables = {
|
||||
...variables,
|
||||
description: 'My reason!',
|
||||
}
|
||||
returnedObject = '{ description }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
description: 'My reason!',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('returns type "Post"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'Post',
|
||||
},
|
||||
})
|
||||
describe('reported resource is a post', () => {
|
||||
beforeEach(async () => {
|
||||
await factory.create('Post', {
|
||||
author: user,
|
||||
id: 'p23',
|
||||
title: 'Matt and Robert having a pair-programming',
|
||||
categoryIds,
|
||||
})
|
||||
variables = {
|
||||
...variables,
|
||||
id: 'p23',
|
||||
}
|
||||
})
|
||||
|
||||
it('returns resource in post attribute', async () => {
|
||||
returnedObject = '{ post { title } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
post: {
|
||||
title: 'Matt and Robert having a pair-programming',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null in user attribute', async () => {
|
||||
returnedObject = '{ user { name } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
user: null,
|
||||
},
|
||||
})
|
||||
it('returns type "Post"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'Post',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den p23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
it('returns resource in post attribute', async () => {
|
||||
returnedObject = '{ post { title } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
post: {
|
||||
title: 'Matt and Robert having a pair-programming',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null in user attribute', async () => {
|
||||
returnedObject = '{ user { name } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
user: null,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den p23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
At this point I would check the p23 again, but this time there must be an error message. */
|
||||
|
||||
describe('reported resource is a comment', () => {
|
||||
beforeEach(async () => {
|
||||
createPostVariables = {
|
||||
id: 'p1',
|
||||
title: 'post to comment on',
|
||||
content: 'please comment on me',
|
||||
categoryIds,
|
||||
}
|
||||
await factory.create('Post', { ...createPostVariables, author: user })
|
||||
await factory.create('Comment', {
|
||||
author: user,
|
||||
postId: 'p1',
|
||||
id: 'c34',
|
||||
content: 'Robert getting tired.',
|
||||
})
|
||||
variables = {
|
||||
id: 'c34',
|
||||
}
|
||||
describe('reported resource is a comment', () => {
|
||||
beforeEach(async () => {
|
||||
createPostVariables = {
|
||||
id: 'p1',
|
||||
title: 'post to comment on',
|
||||
content: 'please comment on me',
|
||||
categoryIds,
|
||||
}
|
||||
await factory.create('Post', { ...createPostVariables, author: user })
|
||||
await factory.create('Comment', {
|
||||
author: user,
|
||||
postId: 'p1',
|
||||
id: 'c34',
|
||||
content: 'Robert getting tired.',
|
||||
})
|
||||
variables = {
|
||||
...variables,
|
||||
id: 'c34',
|
||||
}
|
||||
})
|
||||
|
||||
it('returns type "Comment"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'Comment',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('returns resource in comment attribute', async () => {
|
||||
returnedObject = '{ comment { content } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
comment: {
|
||||
content: 'Robert getting tired.',
|
||||
},
|
||||
},
|
||||
})
|
||||
it('returns type "Comment"', async () => {
|
||||
returnedObject = '{ type }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
type: 'Comment',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den c34 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
it('returns resource in comment attribute', async () => {
|
||||
returnedObject = '{ comment { content } }'
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: {
|
||||
comment: {
|
||||
content: 'Robert getting tired.',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den c34 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
At this point I would check the c34 again, but this time there must be an error message. */
|
||||
|
||||
describe('reported resource is a tag', () => {
|
||||
beforeEach(async () => {
|
||||
await factory.create('Tag', {
|
||||
id: 't23',
|
||||
})
|
||||
variables = {
|
||||
id: 't23',
|
||||
}
|
||||
})
|
||||
|
||||
it('returns null', async () => {
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: null,
|
||||
})
|
||||
describe('reported resource is a tag', () => {
|
||||
beforeEach(async () => {
|
||||
await factory.create('Tag', {
|
||||
id: 't23',
|
||||
})
|
||||
variables = {
|
||||
...variables,
|
||||
id: 't23',
|
||||
}
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den t23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
At this point I would check the t23 again, but this time there must be an error message. */
|
||||
it('returns null', async () => {
|
||||
await expect(action()).resolves.toEqual({
|
||||
report: null,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/* An der Stelle würde ich den t23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
||||
At this point I would check the t23 again, but this time there must be an error message. */
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -24,7 +24,7 @@ type Mutation {
|
||||
changePassword(oldPassword: String!, newPassword: String!): String!
|
||||
requestPasswordReset(email: String!): Boolean!
|
||||
resetPassword(email: String!, nonce: String!, newPassword: String!): Boolean!
|
||||
report(id: ID!, description: String): Report
|
||||
report(id: ID!, reasonCategory: String!, description: String!): Report
|
||||
disable(id: ID!): ID
|
||||
enable(id: ID!): ID
|
||||
# Shout the given Type and ID
|
||||
|
||||
@ -93,10 +93,10 @@ export default {
|
||||
'other',
|
||||
]
|
||||
let reasonCategoryOptions = []
|
||||
valuesReasonCategoryOptions.forEach((categoryId, index) => {
|
||||
valuesReasonCategoryOptions.forEach((reasonCategory, index) => {
|
||||
reasonCategoryOptions[index] = {
|
||||
label: this.$t('report.reason.category.options.' + categoryId),
|
||||
value: categoryId,
|
||||
label: this.$t('report.reason.category.options.' + reasonCategory),
|
||||
value: reasonCategory,
|
||||
}
|
||||
})
|
||||
|
||||
@ -165,8 +165,8 @@ export default {
|
||||
},
|
||||
async confirm() {
|
||||
const { reasonCategory, reasonAddText } = this.form
|
||||
console.log('reasonCategory: ', reasonCategory)
|
||||
console.log('reasonAddText: ', reasonAddText)
|
||||
// Wolle console.log('reasonCategory: ', reasonCategory.value)
|
||||
// Wolle console.log('reasonAddText: ', reasonAddText)
|
||||
|
||||
this.loading = true
|
||||
// TODO: Use the "modalData" structure introduced in "ConfirmModal" and refactor this here. Be aware that all the Jest tests have to be refactored as well !!!
|
||||
@ -174,13 +174,17 @@ export default {
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: gql`
|
||||
mutation($id: ID!) {
|
||||
report(id: $id) {
|
||||
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
|
||||
report(id: $id, reasonCategory: $reasonCategory, description: $description) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id: this.id },
|
||||
variables: {
|
||||
id: this.id,
|
||||
reasonCategory: reasonCategory.value,
|
||||
description: reasonAddText,
|
||||
},
|
||||
})
|
||||
.then(({ _data }) => {
|
||||
this.success = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user