mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Get the backend tests with decide mutation to work #1
This commit is contained in:
parent
21e82d2ea5
commit
f826039777
@ -17,7 +17,7 @@ export default {
|
|||||||
CASE
|
CASE
|
||||||
WHEN decision.createdAt IS NULL
|
WHEN decision.createdAt IS NULL
|
||||||
THEN decision END).createdAt = toString(datetime())
|
THEN decision END).createdAt = toString(datetime())
|
||||||
SET decision.disabled = true, decision.closed = false, decision.last = true
|
SET decision.disable = true, decision.closed = false, decision.last = true
|
||||||
RETURN resource {.id}
|
RETURN resource {.id}
|
||||||
`
|
`
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
@ -34,7 +34,7 @@ export default {
|
|||||||
const cypher = `
|
const cypher = `
|
||||||
MATCH (resource {id: $resourceId})<-[decision:DECIDED]-(:User)
|
MATCH (resource {id: $resourceId})<-[decision:DECIDED]-(:User)
|
||||||
SET resource.disabled = false
|
SET resource.disabled = false
|
||||||
SET decision.disabled = false, decision.updatedAt = toString(datetime())
|
SET decision.disable = false, decision.updatedAt = toString(datetime())
|
||||||
RETURN resource {.id}
|
RETURN resource {.id}
|
||||||
`
|
`
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
@ -46,10 +46,13 @@ export default {
|
|||||||
if (!resource) return null
|
if (!resource) return null
|
||||||
return resource.id
|
return resource.id
|
||||||
},
|
},
|
||||||
decide: async (object, params, context, _resolveInfo) => {
|
decide: async (_object, params, context, _resolveInfo) => {
|
||||||
let createdRelationshipWithNestedAttributes = null
|
let createdRelationshipWithNestedAttributes = null
|
||||||
|
// Wolle console.log('params: ', params)
|
||||||
const { resourceId } = params
|
const { resourceId } = params
|
||||||
let { disabled, closed } = params
|
// Wolle console.log('resourceId: ', resourceId)
|
||||||
|
let { disable, closed } = params
|
||||||
|
// Wolle console.log('disable: ', disable)
|
||||||
const { user: moderator, driver } = context
|
const { user: moderator, driver } = context
|
||||||
|
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
@ -76,7 +79,7 @@ export default {
|
|||||||
const [existingDecisionTxResult] = await existingDecisionWriteTxResultPromise
|
const [existingDecisionTxResult] = await existingDecisionWriteTxResultPromise
|
||||||
if (!existingDecisionTxResult) {
|
if (!existingDecisionTxResult) {
|
||||||
// no open decision, then create one
|
// no open decision, then create one
|
||||||
if (disabled === undefined) disabled = false // default for creation
|
if (disable === undefined) disable = false // default for creation
|
||||||
if (closed === undefined) closed = false // default for creation
|
if (closed === undefined) closed = false // default for creation
|
||||||
cypherHeader = `
|
cypherHeader = `
|
||||||
MATCH (moderator:User {id: $moderatorId})
|
MATCH (moderator:User {id: $moderatorId})
|
||||||
@ -93,8 +96,8 @@ export default {
|
|||||||
`
|
`
|
||||||
} else {
|
} else {
|
||||||
// an open decision …
|
// an open decision …
|
||||||
if (disabled === undefined)
|
if (disable === undefined)
|
||||||
disabled = existingDecisionTxResult.decision.properties.disabled // default set to existing
|
disable = existingDecisionTxResult.decision.properties.disable // default set to existing
|
||||||
if (closed === undefined) closed = existingDecisionTxResult.decision.properties.closed // default set to existing
|
if (closed === undefined) closed = existingDecisionTxResult.decision.properties.closed // default set to existing
|
||||||
// current moderator is not the same as old
|
// current moderator is not the same as old
|
||||||
if (moderator.id !== existingDecisionTxResult.decisionModerator.id) {
|
if (moderator.id !== existingDecisionTxResult.decisionModerator.id) {
|
||||||
@ -127,16 +130,18 @@ export default {
|
|||||||
CASE
|
CASE
|
||||||
WHEN decision.createdAt IS NULL
|
WHEN decision.createdAt IS NULL
|
||||||
THEN decision END).createdAt = toString(datetime())
|
THEN decision END).createdAt = toString(datetime())
|
||||||
SET decision.disabled = $disabled, decision.closed = $closed
|
SET decision.disable = $disable, decision.closed = $closed
|
||||||
SET resource.disabled = $disabled
|
SET resource.disabled = $disable
|
||||||
RETURN decision, resource, moderator, labels(resource)[0] AS type
|
RETURN decision, resource, moderator, labels(resource)[0] AS type
|
||||||
`
|
`
|
||||||
|
// Wolle console.log('cypher: ', cypher)
|
||||||
|
// console.log('disable: ', disable)
|
||||||
|
|
||||||
const newDecisionWriteTxResultPromise = session.writeTransaction(async txc => {
|
const newDecisionWriteTxResultPromise = session.writeTransaction(async txc => {
|
||||||
const decisionRelationshipTransactionResponse = await txc.run(cypher, {
|
const decisionRelationshipTransactionResponse = await txc.run(cypher, {
|
||||||
resourceId,
|
resourceId,
|
||||||
moderatorId: moderator.id,
|
moderatorId: moderator.id,
|
||||||
disabled,
|
disable,
|
||||||
closed,
|
closed,
|
||||||
})
|
})
|
||||||
return decisionRelationshipTransactionResponse.records.map(record => ({
|
return decisionRelationshipTransactionResponse.records.map(record => ({
|
||||||
|
|||||||
@ -8,11 +8,18 @@ const factory = Factory()
|
|||||||
const neode = getNeode()
|
const neode = getNeode()
|
||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
|
|
||||||
let query, mutate, authenticatedUser, variables, moderator, nonModerator
|
let query,
|
||||||
|
mutate,
|
||||||
|
authenticatedUser,
|
||||||
|
disableVariables,
|
||||||
|
// enableVariables,
|
||||||
|
resourceVariables,
|
||||||
|
moderator,
|
||||||
|
nonModerator
|
||||||
|
|
||||||
const disableMutation = gql`
|
const decideMutation = gql`
|
||||||
mutation($id: ID!) {
|
mutation($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
|
||||||
decide(resourceId: $id, disabled: true, closed: false) {
|
decide(resourceId: $resourceId, disable: $disable, closed: $closed) {
|
||||||
post {
|
post {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
@ -69,7 +76,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = {}
|
resourceVariables = {
|
||||||
|
id: 'undefined-resource',
|
||||||
|
}
|
||||||
|
disableVariables = {
|
||||||
|
resourceId: 'undefined-resource',
|
||||||
|
disable: true,
|
||||||
|
closed: false,
|
||||||
|
}
|
||||||
|
// enableVariables = {
|
||||||
|
// resourceId: 'undefined-resource',
|
||||||
|
// disable: false,
|
||||||
|
// closed: false,
|
||||||
|
// }
|
||||||
authenticatedUser = null
|
authenticatedUser = null
|
||||||
moderator = await factory.create('User', {
|
moderator = await factory.create('User', {
|
||||||
id: 'moderator-id',
|
id: 'moderator-id',
|
||||||
@ -84,19 +103,17 @@ describe('moderate resources', () => {
|
|||||||
await factory.cleanDatabase()
|
await factory.cleanDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('disable', () => {
|
describe('decide to disable', () => {
|
||||||
beforeEach(() => {
|
|
||||||
variables = {
|
|
||||||
id: 'some-resource',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
describe('non moderator', () => {
|
describe('non moderator', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -108,8 +125,11 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
authenticatedUser = await nonModerator.toJson()
|
authenticatedUser = await nonModerator.toJson()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -122,14 +142,17 @@ describe('moderate resources', () => {
|
|||||||
|
|
||||||
describe('moderate a resource that is not a (Comment|Post|User) ', () => {
|
describe('moderate a resource that is not a (Comment|Post|User) ', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = {
|
disableVariables = {
|
||||||
id: 'sample-tag-id',
|
...disableVariables,
|
||||||
|
resourceId: 'sample-tag-id',
|
||||||
}
|
}
|
||||||
await factory.create('Tag', { id: 'sample-tag-id' })
|
await factory.create('Tag', { id: 'sample-tag-id' })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null', async () => {
|
it('returns null', async () => {
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: null },
|
data: { decide: null },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -137,63 +160,102 @@ describe('moderate resources', () => {
|
|||||||
|
|
||||||
describe('moderate a comment', () => {
|
describe('moderate a comment', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = {}
|
// Wolle variables = {}
|
||||||
await factory.create('Comment', {
|
await factory.create('Comment', {
|
||||||
id: 'comment-id',
|
id: 'comment-id',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns disabled resource id', async () => {
|
it('returns disabled resource id', async () => {
|
||||||
variables = { id: 'comment-id' }
|
disableVariables = {
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
...disableVariables,
|
||||||
|
resourceId: 'comment-id',
|
||||||
|
}
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { comment: { id: 'comment-id' } } },
|
data: { decide: { comment: { id: 'comment-id' } } },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('changes .decidedByModerator', async () => {
|
it('changes .decidedByModerator', async () => {
|
||||||
variables = { id: 'comment-id' }
|
resourceVariables = {
|
||||||
|
id: 'comment-id',
|
||||||
|
}
|
||||||
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'comment-id',
|
||||||
|
}
|
||||||
const before = { data: { Comment: [{ id: 'comment-id', decidedByModerator: null }] } }
|
const before = { data: { Comment: [{ id: 'comment-id', decidedByModerator: null }] } }
|
||||||
const expected = {
|
const expected = {
|
||||||
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
|
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
|
||||||
}
|
}
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(before)
|
await expect(
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(before)
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { comment: { id: 'comment-id' } } },
|
data: { decide: { comment: { id: 'comment-id' } } },
|
||||||
})
|
})
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates .disabled on comment', async () => {
|
it('updates .disabled on comment', async () => {
|
||||||
variables = { id: 'comment-id' }
|
resourceVariables = {
|
||||||
|
id: 'comment-id',
|
||||||
|
}
|
||||||
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'comment-id',
|
||||||
|
}
|
||||||
const before = { data: { Comment: [{ id: 'comment-id', disabled: false }] } }
|
const before = { data: { Comment: [{ id: 'comment-id', disabled: false }] } }
|
||||||
const expected = { data: { Comment: [{ id: 'comment-id', disabled: true }] } }
|
const expected = { data: { Comment: [{ id: 'comment-id', disabled: true }] } }
|
||||||
|
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(before)
|
await expect(
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(before)
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { comment: { id: 'comment-id' } } },
|
data: { decide: { comment: { id: 'comment-id' } } },
|
||||||
})
|
})
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('moderate a post', () => {
|
describe('moderate a post', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = {}
|
|
||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'sample-post-id',
|
id: 'sample-post-id',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns disabled resource id', async () => {
|
it('returns disabled resource id', async () => {
|
||||||
variables = { id: 'sample-post-id' }
|
disableVariables = {
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
...disableVariables,
|
||||||
|
resourceId: 'sample-post-id',
|
||||||
|
}
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { post: { id: 'sample-post-id' } } },
|
data: { decide: { post: { id: 'sample-post-id' } } },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('changes .decidedByModerator', async () => {
|
it('changes .decidedByModerator', async () => {
|
||||||
variables = { id: 'sample-post-id' }
|
resourceVariables = {
|
||||||
|
id: 'sample-post-id',
|
||||||
|
}
|
||||||
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'sample-post-id',
|
||||||
|
}
|
||||||
const before = { data: { Post: [{ id: 'sample-post-id', decidedByModerator: null }] } }
|
const before = { data: { Post: [{ id: 'sample-post-id', decidedByModerator: null }] } }
|
||||||
const expected = {
|
const expected = {
|
||||||
data: {
|
data: {
|
||||||
@ -201,23 +263,41 @@ describe('moderate resources', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(before)
|
await expect(
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
query({ query: postQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(before)
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { post: { id: 'sample-post-id' } } },
|
data: { decide: { post: { id: 'sample-post-id' } } },
|
||||||
})
|
})
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: postQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates .disabled on post', async () => {
|
it('updates .disabled on post', async () => {
|
||||||
|
resourceVariables = {
|
||||||
|
id: 'sample-post-id',
|
||||||
|
}
|
||||||
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'sample-post-id',
|
||||||
|
}
|
||||||
const before = { data: { Post: [{ id: 'sample-post-id', disabled: false }] } }
|
const before = { data: { Post: [{ id: 'sample-post-id', disabled: false }] } }
|
||||||
const expected = { data: { Post: [{ id: 'sample-post-id', disabled: true }] } }
|
const expected = { data: { Post: [{ id: 'sample-post-id', disabled: true }] } }
|
||||||
variables = { id: 'sample-post-id' }
|
|
||||||
|
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(before)
|
await expect(
|
||||||
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
|
query({ query: postQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(before)
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: decideMutation, variables: disableVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { decide: { post: { id: 'sample-post-id' } } },
|
data: { decide: { post: { id: 'sample-post-id' } } },
|
||||||
})
|
})
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: postQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -227,8 +307,10 @@ describe('moderate resources', () => {
|
|||||||
describe('enable', () => {
|
describe('enable', () => {
|
||||||
describe('unautenticated user', () => {
|
describe('unautenticated user', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
variables = { id: 'sample-post-id' }
|
resourceVariables = { id: 'sample-post-id' }
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: enableMutation, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -245,9 +327,12 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
authenticatedUser = await nonModerator.toJson()
|
authenticatedUser = await nonModerator.toJson()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
variables = { id: 'sample-post-id' }
|
resourceVariables = { id: 'sample-post-id' }
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: enableMutation, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -257,6 +342,7 @@ describe('moderate resources', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
authenticatedUser = await moderator.toJson()
|
authenticatedUser = await moderator.toJson()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('moderate a resource that is not a (Comment|Post|User) ', () => {
|
describe('moderate a resource that is not a (Comment|Post|User) ', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await Promise.all([factory.create('Tag', { id: 'sample-tag-id' })])
|
await Promise.all([factory.create('Tag', { id: 'sample-tag-id' })])
|
||||||
@ -273,15 +359,23 @@ describe('moderate resources', () => {
|
|||||||
|
|
||||||
describe('moderate a comment', () => {
|
describe('moderate a comment', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = { id: 'comment-id' }
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'comment-id',
|
||||||
|
}
|
||||||
|
resourceVariables = {
|
||||||
|
id: 'comment-id',
|
||||||
|
}
|
||||||
await factory.create('Comment', {
|
await factory.create('Comment', {
|
||||||
id: 'comment-id',
|
id: 'comment-id',
|
||||||
})
|
})
|
||||||
await mutate({ mutation: disableMutation, variables })
|
await mutate({ mutation: decideMutation, variables: disableVariables })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns enabled resource id', async () => {
|
it('returns enabled resource id', async () => {
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: enableMutation, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { enable: 'comment-id' },
|
data: { enable: 'comment-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
@ -292,11 +386,15 @@ describe('moderate resources', () => {
|
|||||||
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
|
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
}
|
}
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: enableMutation, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { enable: 'comment-id' },
|
data: { enable: 'comment-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates .disabled on comment', async () => {
|
it('updates .disabled on comment', async () => {
|
||||||
@ -305,25 +403,36 @@ describe('moderate resources', () => {
|
|||||||
errors: undefined,
|
errors: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(
|
||||||
|
mutate({ mutation: enableMutation, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
data: { enable: 'comment-id' },
|
data: { enable: 'comment-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(expected)
|
await expect(
|
||||||
|
query({ query: commentQuery, variables: resourceVariables }),
|
||||||
|
).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('moderate a post', () => {
|
describe('moderate a post', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = { id: 'post-id' }
|
resourceVariables = { id: 'post-id' }
|
||||||
|
disableVariables = {
|
||||||
|
...disableVariables,
|
||||||
|
resourceId: 'post-id',
|
||||||
|
}
|
||||||
|
resourceVariables = {
|
||||||
|
id: 'post-id',
|
||||||
|
}
|
||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'post-id',
|
id: 'post-id',
|
||||||
})
|
})
|
||||||
await mutate({ mutation: disableMutation, variables })
|
await mutate({ mutation: decideMutation, variables: disableVariables })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns enabled resource id', async () => {
|
it('returns enabled resource id', async () => {
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(mutate({ mutation: enableMutation, variables: resourceVariables })).resolves.toMatchObject({
|
||||||
data: { enable: 'post-id' },
|
data: { enable: 'post-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
@ -334,11 +443,11 @@ describe('moderate resources', () => {
|
|||||||
data: { Post: [{ id: 'post-id', decidedByModerator: { id: 'moderator-id' } }] },
|
data: { Post: [{ id: 'post-id', decidedByModerator: { id: 'moderator-id' } }] },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
}
|
}
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(mutate({ mutation: enableMutation, variables: resourceVariables })).resolves.toMatchObject({
|
||||||
data: { enable: 'post-id' },
|
data: { enable: 'post-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(expected)
|
await expect(query({ query: postQuery, variables: resourceVariables })).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates .disabled on post', async () => {
|
it('updates .disabled on post', async () => {
|
||||||
@ -347,11 +456,11 @@ describe('moderate resources', () => {
|
|||||||
errors: undefined,
|
errors: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
|
await expect(mutate({ mutation: enableMutation, variables: resourceVariables })).resolves.toMatchObject({
|
||||||
data: { enable: 'post-id' },
|
data: { enable: 'post-id' },
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
})
|
})
|
||||||
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(expected)
|
await expect(query({ query: postQuery, variables: resourceVariables })).resolves.toMatchObject(expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,7 +3,7 @@ type DECIDED {
|
|||||||
updatedAt: String
|
updatedAt: String
|
||||||
# reasonCategory: ReasonCategory
|
# reasonCategory: ReasonCategory
|
||||||
# reasonDescription: String
|
# reasonDescription: String
|
||||||
disabled: Boolean!
|
disable: Boolean!
|
||||||
closed: Boolean!
|
closed: Boolean!
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
@ -22,5 +22,5 @@ type DECIDED {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
decide(resourceId: ID!, disabled: Boolean, closed: Boolean): DECIDED
|
decide(resourceId: ID!, disable: Boolean, closed: Boolean): DECIDED
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,6 @@ echo "
|
|||||||
MATCH (moderator:User)-[disabled:DISABLED]->(resource)
|
MATCH (moderator:User)-[disabled:DISABLED]->(resource)
|
||||||
DELETE disabled
|
DELETE disabled
|
||||||
CREATE (moderator)-[decision:DECIDED]->(resource)
|
CREATE (moderator)-[decision:DECIDED]->(resource)
|
||||||
SET decision.createdAt = toString(datetime()), decision.disabled = true, decision.last = true, decision.closed = false
|
SET decision.createdAt = toString(datetime()), decision.disable = true, decision.last = true, decision.closed = false
|
||||||
RETURN decision;
|
RETURN decision;
|
||||||
" | cypher-shell
|
" | cypher-shell
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user