Follow Matts suggestions from his review

This commit is contained in:
Wolfgang Huß 2019-10-14 17:38:38 +02:00
parent fd27583c1d
commit cae897808b
4 changed files with 73 additions and 59 deletions

View File

@ -23,6 +23,7 @@ export default applyScalars(
'Location', 'Location',
'SocialMedia', 'SocialMedia',
'NOTIFIED', 'NOTIFIED',
'REPORTED',
], ],
// add 'User' here as soon as possible // add 'User' here as soon as possible
}, },

View File

@ -13,17 +13,36 @@ describe('report mutation', () => {
let reportMutation let reportMutation
let headers let headers
let client let client
let returnedObject
let variables let variables
let createPostVariables let createPostVariables
let user let user
const categoryIds = ['cat9'] const categoryIds = ['cat9']
const action = () => { const action = () => {
// because of the template `${returnedObject}` the 'gql' tag from 'jest/helpers' is not working here reportMutation = gql`
reportMutation = `
mutation($resourceId: ID!, $reasonCategory: String!, $reasonDescription: String!) { mutation($resourceId: ID!, $reasonCategory: String!, $reasonDescription: String!) {
report(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) ${returnedObject} report(
resourceId: $resourceId
reasonCategory: $reasonCategory
reasonDescription: $reasonDescription
) {
createdAt
reasonCategory
reasonDescription
type
submitter {
email
}
user {
name
}
post {
title
}
comment {
content
}
}
} }
` `
client = new GraphQLClient(host, { client = new GraphQLClient(host, {
@ -33,10 +52,9 @@ describe('report mutation', () => {
} }
beforeEach(async () => { beforeEach(async () => {
returnedObject = '{ createdAt }'
variables = { variables = {
resourceId: 'whatever', resourceId: 'whatever',
reasonCategory: 'reason-category-dummy', reasonCategory: 'other',
reasonDescription: 'Violates code of conduct !!!', reasonDescription: 'Violates code of conduct !!!',
} }
headers = {} headers = {}
@ -95,8 +113,7 @@ describe('report mutation', () => {
}) })
it('returns type "User"', async () => { it('returns type "User"', async () => {
returnedObject = '{ type }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
type: 'User', type: 'User',
}, },
@ -104,8 +121,7 @@ describe('report mutation', () => {
}) })
it('returns resource in user attribute', async () => { it('returns resource in user attribute', async () => {
returnedObject = '{ user { name } }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
user: { user: {
name: 'abusive-user', name: 'abusive-user',
@ -115,8 +131,7 @@ describe('report mutation', () => {
}) })
it('returns the submitter', async () => { it('returns the submitter', async () => {
returnedObject = '{ submitter { email } }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
submitter: { submitter: {
email: 'test@example.org', email: 'test@example.org',
@ -126,36 +141,41 @@ describe('report mutation', () => {
}) })
it('returns a date', async () => { it('returns a date', async () => {
returnedObject = '{ createdAt }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual( report: {
expect.objectContaining({ createdAt: expect.any(String),
report: { },
createdAt: expect.any(String), })
},
}),
)
}) })
it('returns the reason category', async () => { it('returns the reason category', async () => {
variables = { variables = {
...variables, ...variables,
reasonCategory: 'my-category', reasonCategory: 'criminal_behavior_violation_german_law',
} }
returnedObject = '{ reasonCategory }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
reasonCategory: 'my-category', reasonCategory: 'criminal_behavior_violation_german_law',
}, },
}) })
}) })
it('gives an error if the reason category is not in enum "ReasonCategory"', async () => {
variables = {
...variables,
reasonCategory: 'my_category',
}
await expect(action()).rejects.toThrow(
'Expected a value of type "ReasonCategory" but received: "my_category"',
)
})
it('returns the reason description', async () => { it('returns the reason description', async () => {
variables = { variables = {
...variables, ...variables,
reasonDescription: 'My reason!', reasonDescription: 'My reason!',
} }
returnedObject = '{ reasonDescription }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
reasonDescription: 'My reason!', reasonDescription: 'My reason!',
}, },
@ -167,8 +187,7 @@ describe('report mutation', () => {
...variables, ...variables,
reasonDescription: 'My reason <sanitize></sanitize>!', reasonDescription: 'My reason <sanitize></sanitize>!',
} }
returnedObject = '{ reasonDescription }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
reasonDescription: 'My reason !', reasonDescription: 'My reason !',
}, },
@ -191,8 +210,7 @@ describe('report mutation', () => {
}) })
it('returns type "Post"', async () => { it('returns type "Post"', async () => {
returnedObject = '{ type }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
type: 'Post', type: 'Post',
}, },
@ -200,8 +218,7 @@ describe('report mutation', () => {
}) })
it('returns resource in post attribute', async () => { it('returns resource in post attribute', async () => {
returnedObject = '{ post { title } }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
post: { post: {
title: 'Matt and Robert having a pair-programming', title: 'Matt and Robert having a pair-programming',
@ -211,8 +228,7 @@ describe('report mutation', () => {
}) })
it('returns null in user attribute', async () => { it('returns null in user attribute', async () => {
returnedObject = '{ user { name } }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
user: null, user: null,
}, },
@ -245,8 +261,7 @@ describe('report mutation', () => {
}) })
it('returns type "Comment"', async () => { it('returns type "Comment"', async () => {
returnedObject = '{ type }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
type: 'Comment', type: 'Comment',
}, },
@ -254,8 +269,7 @@ describe('report mutation', () => {
}) })
it('returns resource in comment attribute', async () => { it('returns resource in comment attribute', async () => {
returnedObject = '{ comment { content } }' await expect(action()).resolves.toMatchObject({
await expect(action()).resolves.toEqual({
report: { report: {
comment: { comment: {
content: 'Robert getting tired.', content: 'Robert getting tired.',
@ -280,7 +294,7 @@ describe('report mutation', () => {
}) })
it('returns null', async () => { it('returns null', async () => {
await expect(action()).resolves.toEqual({ await expect(action()).resolves.toMatchObject({
report: null, report: null,
}) })
}) })
@ -381,19 +395,19 @@ describe('reports query', () => {
author, author,
id: 'p1', id: 'p1',
categoryIds, categoryIds,
content: 'Not for you', content: 'Interesting Knowledge',
}), }),
factory.create('Post', { factory.create('Post', {
author: moderator, author: moderator,
id: 'p2', id: 'p2',
categoryIds, categoryIds,
content: 'Already seen post mention', content: 'More things to do …',
}), }),
factory.create('Post', { factory.create('Post', {
author: user, author: user,
id: 'p3', id: 'p3',
categoryIds, categoryIds,
content: 'You have been mentioned in a post', content: 'I am at school …',
}), }),
]) ])
await Promise.all([ await Promise.all([
@ -418,7 +432,7 @@ describe('reports query', () => {
mutation: reportMutation, mutation: reportMutation,
variables: { variables: {
resourceId: 'c1', resourceId: 'c1',
reasonCategory: 'discrimination-etc', reasonCategory: 'discrimination_etc',
reasonDescription: 'This post is bigoted', reasonDescription: 'This post is bigoted',
}, },
}), }),
@ -441,20 +455,18 @@ describe('reports query', () => {
describe('unauthenticated', () => { describe('unauthenticated', () => {
it('throws authorization error', async () => { it('throws authorization error', async () => {
authenticatedUser = null authenticatedUser = null
const { data, errors } = await query({ query: reportsQuery }) expect(query({ query: reportsQuery })).resolves.toMatchObject({
expect(data).toEqual({ data: { reports: null },
reports: null, errors: [{ message: 'Not Authorised!' }],
}) })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
}) })
it('role "user" gets no reports', async () => { it('role "user" gets no reports', async () => {
authenticatedUser = await user.toJson() authenticatedUser = await user.toJson()
const { data, errors } = await query({ query: reportsQuery }) expect(query({ query: reportsQuery })).resolves.toMatchObject({
expect(data).toEqual({ data: { reports: null },
reports: null, errors: [{ message: 'Not Authorised!' }],
}) })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
}) })
it('role "moderator" gets reports', async () => { it('role "moderator" gets reports', async () => {
@ -493,7 +505,7 @@ describe('reports query', () => {
}), }),
expect.objectContaining({ expect.objectContaining({
createdAt: expect.any(String), createdAt: expect.any(String),
reasonCategory: 'discrimination-etc', reasonCategory: 'discrimination_etc',
reasonDescription: 'This post is bigoted', reasonDescription: 'This post is bigoted',
submitter: expect.objectContaining({ submitter: expect.objectContaining({
id: 'user1', id: 'user1',

View File

@ -16,16 +16,16 @@ type REPORTED {
comment: Comment comment: Comment
} }
# list see "reportReasonCategoriesDatabaseList" in shared file "shared/moderation/report.js" # this list equals the strings of an array in file "webapp/components/Modal/ReportModal.vue"
enum ReasonCategory { enum ReasonCategory {
other other
discrimination-etc discrimination_etc
pornographic-content-links pornographic_content_links
glorific-trivia-of-cruel-inhuman-acts glorific_trivia_of_cruel_inhuman_acts
doxing doxing
intentional-intimidation-stalking-persecution intentional_intimidation_stalking_persecution
advert-products-services-commercial advert_products_services_commercial
criminal-behavior-violation-german-law criminal_behavior_violation_german_law
} }
# not yet supported # not yet supported

View File

@ -62,6 +62,7 @@ export default {
id: { type: String, required: true }, id: { type: String, required: true },
}, },
data() { data() {
// this list equals to enums in GraphQL schema file "backend/src/schema/types/type/REPORTED.gql"
let valuesReasonCategoryOptions = [ let valuesReasonCategoryOptions = [
'discrimination_etc', 'discrimination_etc',
'pornographic_content_links', 'pornographic_content_links',