mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Refactor mutations without Resource type
This commit is contained in:
parent
1377455cda
commit
4596041186
@ -22,10 +22,9 @@ beforeEach(async () => {
|
||||
await moderatorFactory.authenticateAs({ email: 'moderator@example.org', password: '1234' })
|
||||
const disableMutation = `
|
||||
mutation {
|
||||
disable(resource: {
|
||||
disable(
|
||||
id: "p2"
|
||||
type: contribution
|
||||
})
|
||||
)
|
||||
}
|
||||
`
|
||||
await moderatorFactory.mutate(disableMutation)
|
||||
|
||||
@ -1,30 +1,38 @@
|
||||
export default {
|
||||
Mutation: {
|
||||
disable: async (object, params, { user, driver }) => {
|
||||
const { resource: { id } } = params
|
||||
const { id } = params
|
||||
const { id: userId } = user
|
||||
const cypher = `
|
||||
MATCH (u:User {id: $userId})
|
||||
MATCH (r {id: $id})
|
||||
SET r.disabled = true
|
||||
MERGE (r)<-[:DISABLED]-(u)
|
||||
MATCH (resource {id: $id})
|
||||
SET resource.disabled = true
|
||||
MERGE (resource)<-[:DISABLED]-(u)
|
||||
RETURN resource {.id}
|
||||
`
|
||||
const session = driver.session()
|
||||
const res = await session.run(cypher, { id, userId })
|
||||
const [resource] = res.records.map((record) => {
|
||||
return record.get('resource')
|
||||
})
|
||||
session.close()
|
||||
return Boolean(res)
|
||||
return resource.id
|
||||
},
|
||||
enable: async (object, params, { user, driver }) => {
|
||||
const { resource: { id } } = params
|
||||
const { id } = params
|
||||
const cypher = `
|
||||
MATCH (r {id: $id})<-[d:DISABLED]-()
|
||||
SET r.disabled = false
|
||||
MATCH (resource {id: $id})<-[d:DISABLED]-()
|
||||
SET resource.disabled = false
|
||||
DELETE d
|
||||
RETURN resource {.id}
|
||||
`
|
||||
const session = driver.session()
|
||||
const res = await session.run(cypher, { id })
|
||||
const [resource] = res.records.map((record) => {
|
||||
return record.get('resource')
|
||||
})
|
||||
session.close()
|
||||
return Boolean(res)
|
||||
return resource.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@ afterEach(async () => {
|
||||
|
||||
describe('disable', () => {
|
||||
const mutation = `
|
||||
mutation($id: ID!, $type: ResourceEnum!) {
|
||||
disable(resource: { id: $id, type: $type }) { id type }
|
||||
mutation($id: ID!) {
|
||||
disable(id: $id)
|
||||
}
|
||||
`
|
||||
let variables
|
||||
@ -45,8 +45,7 @@ describe('disable', () => {
|
||||
beforeEach(() => {
|
||||
// our defaul set of variables
|
||||
variables = {
|
||||
id: 'blabla',
|
||||
type: 'contribution'
|
||||
id: 'blabla'
|
||||
}
|
||||
})
|
||||
|
||||
@ -85,8 +84,7 @@ describe('disable', () => {
|
||||
describe('on a comment', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 'c47',
|
||||
type: 'comment'
|
||||
id: 'c47'
|
||||
}
|
||||
|
||||
setup.createResource = async () => {
|
||||
@ -103,8 +101,8 @@ describe('disable', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('returns disabled Resource', async () => {
|
||||
const expected = { disable: { id: 'c47', type: 'comment' } }
|
||||
it('returns disabled resource id', async () => {
|
||||
const expected = { disable: 'c47' }
|
||||
await runSetup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
@ -141,8 +139,7 @@ describe('disable', () => {
|
||||
describe('on a post', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 'p9',
|
||||
type: 'contribution'
|
||||
id: 'p9'
|
||||
}
|
||||
|
||||
setup.createResource = async () => {
|
||||
@ -154,8 +151,8 @@ describe('disable', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('returns disabled Resource', async () => {
|
||||
const expected = { disable: { id: 'p9', type: 'contribution' } }
|
||||
it('returns disabled resource id', async () => {
|
||||
const expected = { disable: 'p9' }
|
||||
await runSetup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
@ -194,8 +191,8 @@ describe('disable', () => {
|
||||
|
||||
describe('enable', () => {
|
||||
const mutation = `
|
||||
mutation($id: ID!, $type: ResourceEnum!) {
|
||||
enable(resource: { id: $id, type: $type }) { id type }
|
||||
mutation($id: ID!) {
|
||||
enable(id: $id)
|
||||
}
|
||||
`
|
||||
let variables
|
||||
@ -207,8 +204,7 @@ describe('enable', () => {
|
||||
beforeEach(() => {
|
||||
// our defaul set of variables
|
||||
variables = {
|
||||
id: 'blabla',
|
||||
type: 'contribution'
|
||||
id: 'blabla'
|
||||
}
|
||||
})
|
||||
|
||||
@ -242,8 +238,7 @@ describe('enable', () => {
|
||||
describe('on a comment', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 'c456',
|
||||
type: 'comment'
|
||||
id: 'c456'
|
||||
}
|
||||
|
||||
setup.createResource = async () => {
|
||||
@ -260,18 +255,15 @@ describe('enable', () => {
|
||||
|
||||
const disableMutation = `
|
||||
mutation {
|
||||
disable(resource: {
|
||||
id: "c456"
|
||||
type: comment
|
||||
})
|
||||
disable(id: "c456")
|
||||
}
|
||||
`
|
||||
await factory.mutate(disableMutation) // that's we want to delete
|
||||
}
|
||||
})
|
||||
|
||||
it('returns disabled Resource', async () => {
|
||||
const expected = { enable: { id: 'c456', type: 'comment' } }
|
||||
it('returns disabled resource id', async () => {
|
||||
const expected = { enable: 'c456' }
|
||||
await runSetup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
@ -308,8 +300,7 @@ describe('enable', () => {
|
||||
describe('on a post', () => {
|
||||
beforeEach(async () => {
|
||||
variables = {
|
||||
id: 'p9',
|
||||
type: 'contribution'
|
||||
id: 'p9'
|
||||
}
|
||||
|
||||
setup.createResource = async () => {
|
||||
@ -321,18 +312,15 @@ describe('enable', () => {
|
||||
|
||||
const disableMutation = `
|
||||
mutation {
|
||||
disable(resource: {
|
||||
id: "p9"
|
||||
type: contribution
|
||||
})
|
||||
disable(id: "p9")
|
||||
}
|
||||
`
|
||||
await factory.mutate(disableMutation) // that's we want to delete
|
||||
}
|
||||
})
|
||||
|
||||
it('returns disabled Resource', async () => {
|
||||
const expected = { enable: { id: 'p9', type: 'contribution' } }
|
||||
it('returns disabled resource id', async () => {
|
||||
const expected = { enable: 'p9' }
|
||||
await runSetup()
|
||||
await expect(action()).resolves.toEqual(expected)
|
||||
})
|
||||
|
||||
@ -6,9 +6,9 @@ type Query {
|
||||
type Mutation {
|
||||
login(email: String!, password: String!): String!
|
||||
signup(email: String!, password: String!): Boolean!
|
||||
report(resource: Resource!, description: String): Report
|
||||
disable(resource: Resource!): ResourcePayload!
|
||||
enable(resource: Resource!): ResourcePayload!
|
||||
report(id: ID!, description: String): Report
|
||||
disable(id: ID!): ID!
|
||||
enable(id: ID!): ID!
|
||||
}
|
||||
|
||||
type Statistics {
|
||||
@ -27,22 +27,6 @@ scalar Date
|
||||
scalar Time
|
||||
scalar DateTime
|
||||
|
||||
input Resource {
|
||||
id: ID!,
|
||||
type: ResourceEnum!
|
||||
}
|
||||
|
||||
type ResourcePayload {
|
||||
id: ID!,
|
||||
type: ResourceEnum!
|
||||
}
|
||||
|
||||
enum ResourceEnum {
|
||||
contribution
|
||||
comment
|
||||
user
|
||||
}
|
||||
|
||||
enum VisibilityEnum {
|
||||
public
|
||||
friends
|
||||
@ -178,7 +162,6 @@ type Report {
|
||||
id: ID!
|
||||
reporter: User @relation(name: "REPORTED", direction: "IN")
|
||||
description: String
|
||||
type: ResourceEnum!
|
||||
createdAt: String
|
||||
comment: Comment @relation(name: "REPORTED", direction: "OUT")
|
||||
contribution: Post @relation(name: "REPORTED", direction: "OUT")
|
||||
|
||||
@ -98,14 +98,7 @@ import Factory from './factories'
|
||||
asTick.create('Post', { id: 'p15' })
|
||||
])
|
||||
|
||||
const disableMutation = `
|
||||
mutation {
|
||||
disable(resource: {
|
||||
id: "p11"
|
||||
type: contribution
|
||||
})
|
||||
}
|
||||
`
|
||||
const disableMutation = 'mutation { disable( id: "p11") }'
|
||||
await asModerator.mutate(disableMutation)
|
||||
|
||||
await Promise.all([
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user