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()
|
const instance = neode()
|
||||||
|
|
||||||
describe('report', () => {
|
describe('report', () => {
|
||||||
let mutation
|
let reportMutation
|
||||||
let headers
|
let headers
|
||||||
let returnedObject
|
let returnedObject
|
||||||
let variables
|
let variables
|
||||||
@ -16,9 +16,11 @@ describe('report', () => {
|
|||||||
const categoryIds = ['cat9']
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
returnedObject = '{ description }'
|
returnedObject = '{ id }'
|
||||||
variables = {
|
variables = {
|
||||||
id: 'whatever',
|
id: 'whatever',
|
||||||
|
reasonCategory: 'reason-category-dummy',
|
||||||
|
description: 'Violates code of conduct !!!',
|
||||||
}
|
}
|
||||||
headers = {}
|
headers = {}
|
||||||
user = await factory.create('User', {
|
user = await factory.create('User', {
|
||||||
@ -45,54 +47,69 @@ describe('report', () => {
|
|||||||
|
|
||||||
let client
|
let client
|
||||||
const action = () => {
|
const action = () => {
|
||||||
mutation = `
|
// because of the template `${returnedObject}` the 'gql' tag from 'jest/helpers' is not working here
|
||||||
mutation($id: ID!) {
|
reportMutation = `
|
||||||
report(
|
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
|
||||||
id: $id,
|
report( id: $id, reasonCategory: $reasonCategory, description: $description) ${returnedObject}
|
||||||
description: "Violates code of conduct"
|
|
||||||
) ${returnedObject}
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
client = new GraphQLClient(host, {
|
client = new GraphQLClient(host, {
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
return client.request(mutation, variables)
|
return client.request(reportMutation, variables)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
await expect(action()).rejects.toThrow('Not Authorised')
|
await expect(action()).rejects.toThrow('Not Authorised')
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
headers = await login({
|
headers = await login({
|
||||||
email: 'test@example.org',
|
email: 'test@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('invalid resource id', () => {
|
||||||
|
it('returns null', async () => {
|
||||||
|
await expect(action()).resolves.toEqual({
|
||||||
|
report: null,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('invalid resource id', () => {
|
describe('valid resource id', () => {
|
||||||
it('returns null', async () => {
|
describe('reported resource is a user', () => {
|
||||||
await expect(action()).resolves.toEqual({
|
|
||||||
report: null,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('valid resource id', () => {
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = {
|
variables = {
|
||||||
|
...variables,
|
||||||
id: 'u2',
|
id: 'u2',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
/*
|
|
||||||
it('creates a report', async () => {
|
it('returns type "User"', async () => {
|
||||||
await expect(action()).resolves.toEqual({
|
returnedObject = '{ type }'
|
||||||
type: null,
|
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 () => {
|
it('returns the submitter', async () => {
|
||||||
returnedObject = '{ submitter { email } }'
|
returnedObject = '{ submitter { email } }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
@ -104,138 +121,145 @@ describe('report', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('reported resource is a user', () => {
|
it('returns the reason category', async () => {
|
||||||
it('returns type "User"', async () => {
|
variables = {
|
||||||
returnedObject = '{ type }'
|
...variables,
|
||||||
await expect(action()).resolves.toEqual({
|
reasonCategory: 'my-category',
|
||||||
report: {
|
}
|
||||||
type: 'User',
|
returnedObject = '{ reasonCategory }'
|
||||||
},
|
await expect(action()).resolves.toEqual({
|
||||||
})
|
report: {
|
||||||
})
|
reasonCategory: 'my-category',
|
||||||
|
},
|
||||||
it('returns resource in user attribute', async () => {
|
|
||||||
returnedObject = '{ user { name } }'
|
|
||||||
await expect(action()).resolves.toEqual({
|
|
||||||
report: {
|
|
||||||
user: {
|
|
||||||
name: 'abusive-user',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('reported resource is a post', () => {
|
it('returns the reason description', async () => {
|
||||||
beforeEach(async () => {
|
variables = {
|
||||||
await factory.create('Post', {
|
...variables,
|
||||||
author: user,
|
description: 'My reason!',
|
||||||
id: 'p23',
|
}
|
||||||
title: 'Matt and Robert having a pair-programming',
|
returnedObject = '{ description }'
|
||||||
categoryIds,
|
await expect(action()).resolves.toEqual({
|
||||||
})
|
report: {
|
||||||
variables = {
|
description: 'My reason!',
|
||||||
id: 'p23',
|
},
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('returns type "Post"', async () => {
|
describe('reported resource is a post', () => {
|
||||||
returnedObject = '{ type }'
|
beforeEach(async () => {
|
||||||
await expect(action()).resolves.toEqual({
|
await factory.create('Post', {
|
||||||
report: {
|
author: user,
|
||||||
type: 'Post',
|
id: 'p23',
|
||||||
},
|
title: 'Matt and Robert having a pair-programming',
|
||||||
})
|
categoryIds,
|
||||||
})
|
})
|
||||||
|
variables = {
|
||||||
|
...variables,
|
||||||
|
id: 'p23',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('returns resource in post attribute', async () => {
|
it('returns type "Post"', async () => {
|
||||||
returnedObject = '{ post { title } }'
|
returnedObject = '{ type }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: {
|
report: {
|
||||||
post: {
|
type: '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.
|
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. */
|
At this point I would check the p23 again, but this time there must be an error message. */
|
||||||
|
|
||||||
describe('reported resource is a comment', () => {
|
describe('reported resource is a comment', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
createPostVariables = {
|
createPostVariables = {
|
||||||
id: 'p1',
|
id: 'p1',
|
||||||
title: 'post to comment on',
|
title: 'post to comment on',
|
||||||
content: 'please comment on me',
|
content: 'please comment on me',
|
||||||
categoryIds,
|
categoryIds,
|
||||||
}
|
}
|
||||||
await factory.create('Post', { ...createPostVariables, author: user })
|
await factory.create('Post', { ...createPostVariables, author: user })
|
||||||
await factory.create('Comment', {
|
await factory.create('Comment', {
|
||||||
author: user,
|
author: user,
|
||||||
postId: 'p1',
|
postId: 'p1',
|
||||||
id: 'c34',
|
id: 'c34',
|
||||||
content: 'Robert getting tired.',
|
content: 'Robert getting tired.',
|
||||||
})
|
|
||||||
variables = {
|
|
||||||
id: 'c34',
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
variables = {
|
||||||
|
...variables,
|
||||||
|
id: 'c34',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('returns type "Comment"', async () => {
|
it('returns type "Comment"', async () => {
|
||||||
returnedObject = '{ type }'
|
returnedObject = '{ type }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: {
|
report: {
|
||||||
type: 'Comment',
|
type: 'Comment',
|
||||||
},
|
},
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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.
|
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. */
|
At this point I would check the c34 again, but this time there must be an error message. */
|
||||||
|
|
||||||
describe('reported resource is a tag', () => {
|
describe('reported resource is a tag', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await factory.create('Tag', {
|
await factory.create('Tag', {
|
||||||
id: 't23',
|
id: 't23',
|
||||||
})
|
|
||||||
variables = {
|
|
||||||
id: 't23',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
it('returns null', async () => {
|
|
||||||
await expect(action()).resolves.toEqual({
|
|
||||||
report: null,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
variables = {
|
||||||
|
...variables,
|
||||||
|
id: 't23',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/* An der Stelle würde ich den t23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
|
it('returns null', async () => {
|
||||||
At this point I would check the t23 again, but this time there must be an error message. */
|
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!
|
changePassword(oldPassword: String!, newPassword: String!): String!
|
||||||
requestPasswordReset(email: String!): Boolean!
|
requestPasswordReset(email: String!): Boolean!
|
||||||
resetPassword(email: String!, nonce: String!, newPassword: 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
|
disable(id: ID!): ID
|
||||||
enable(id: ID!): ID
|
enable(id: ID!): ID
|
||||||
# Shout the given Type and ID
|
# Shout the given Type and ID
|
||||||
|
|||||||
@ -93,10 +93,10 @@ export default {
|
|||||||
'other',
|
'other',
|
||||||
]
|
]
|
||||||
let reasonCategoryOptions = []
|
let reasonCategoryOptions = []
|
||||||
valuesReasonCategoryOptions.forEach((categoryId, index) => {
|
valuesReasonCategoryOptions.forEach((reasonCategory, index) => {
|
||||||
reasonCategoryOptions[index] = {
|
reasonCategoryOptions[index] = {
|
||||||
label: this.$t('report.reason.category.options.' + categoryId),
|
label: this.$t('report.reason.category.options.' + reasonCategory),
|
||||||
value: categoryId,
|
value: reasonCategory,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -165,8 +165,8 @@ export default {
|
|||||||
},
|
},
|
||||||
async confirm() {
|
async confirm() {
|
||||||
const { reasonCategory, reasonAddText } = this.form
|
const { reasonCategory, reasonAddText } = this.form
|
||||||
console.log('reasonCategory: ', reasonCategory)
|
// Wolle console.log('reasonCategory: ', reasonCategory.value)
|
||||||
console.log('reasonAddText: ', reasonAddText)
|
// Wolle console.log('reasonAddText: ', reasonAddText)
|
||||||
|
|
||||||
this.loading = true
|
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 !!!
|
// 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
|
this.$apollo
|
||||||
.mutate({
|
.mutate({
|
||||||
mutation: gql`
|
mutation: gql`
|
||||||
mutation($id: ID!) {
|
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
|
||||||
report(id: $id) {
|
report(id: $id, reasonCategory: $reasonCategory, description: $description) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
variables: { id: this.id },
|
variables: {
|
||||||
|
id: this.id,
|
||||||
|
reasonCategory: reasonCategory.value,
|
||||||
|
description: reasonAddText,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.then(({ _data }) => {
|
.then(({ _data }) => {
|
||||||
this.success = true
|
this.success = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user