First refactoring tests to new database structure

This commit is contained in:
Wolfgang Huß 2019-10-30 16:59:24 +01:00
parent 47d5cc89dd
commit 54be7782ba
13 changed files with 51 additions and 48 deletions

View File

@ -25,7 +25,7 @@ module.exports = {
target: 'User',
direction: 'in',
},
disabledBy: {
decidedByModerator: {
type: 'relationship',
relationship: 'DECIDED',
target: 'User',

View File

@ -17,7 +17,7 @@ module.exports = {
image: { type: 'string', allow: [null] },
deleted: { type: 'boolean', default: false },
disabled: { type: 'boolean', default: false },
disabledBy: {
decidedByModerator: {
type: 'relationship',
relationship: 'DECIDED',
target: 'User',

View File

@ -42,7 +42,7 @@ module.exports = {
},
},
friends: { type: 'relationship', relationship: 'FRIENDS', target: 'User', direction: 'both' },
disabledBy: {
decidedByModerator: {
type: 'relationship',
relationship: 'DECIDED',
target: 'User',

View File

@ -68,7 +68,7 @@ export default {
hasOne: {
author: '<-[:WROTE]-(related:User)',
post: '-[:COMMENTS]->(related:Post)',
disabledBy: '<-[:DECIDED]-(related:User)',
decidedByModerator: '<-[:DECIDED]-(related:User)',
},
}),
},

View File

@ -4,21 +4,21 @@ export default {
const { id: resourceId } = params
const { id: userId } = user
const cypher = `
MATCH (u:User {id: $userId})
MATCH (resource {id: $resourceId})
WHERE resource:User OR resource:Comment OR resource:Post
SET resource.disabled = true
MERGE (resource)<-[decision:DECIDED]-(u)
SET (
CASE
WHEN decision.createdAt IS NOT NULL
THEN decision END).updatedAt = toString(datetime())
SET (
CASE
WHEN decision.createdAt IS NULL
THEN decision END).createdAt = toString(datetime())
SET decision.disabled = true, decision.closed = false, decision.last = true
RETURN resource {.id}
MATCH (u:User {id: $userId})
MATCH (resource {id: $resourceId})
WHERE resource:User OR resource:Comment OR resource:Post
SET resource.disabled = true
MERGE (resource)<-[decision:DECIDED]-(u)
SET (
CASE
WHEN decision.createdAt IS NOT NULL
THEN decision END).updatedAt = toString(datetime())
SET (
CASE
WHEN decision.createdAt IS NULL
THEN decision END).createdAt = toString(datetime())
SET decision.disabled = true, decision.closed = false, decision.last = true
RETURN resource {.id}
`
const session = driver.session()
const res = await session.run(cypher, { resourceId, userId })
@ -32,14 +32,14 @@ export default {
enable: async (object, params, { user, driver }) => {
const { id: resourceId } = params
const cypher = `
MATCH (resource {id: $resourceId})<-[decision:DECIDED]-(:User)
SET resource.disabled = false
DELETE decision
RETURN resource {.id}
MATCH (resource {id: $resourceId})<-[decision:DECIDED]-(:User)
SET resource.disabled = false
SET decision.disabled = false, decision.updatedAt = toString(datetime())
RETURN resource {.id}
`
// Wolle
// SET decision.updatedAt = toString(datetime())
// SET decision.disabled = false
// DELETE decision
const session = driver.session()
const res = await session.run(cypher, { resourceId })
session.close()

View File

@ -26,7 +26,7 @@ const commentQuery = gql`
Comment(id: $id) {
id
disabled
disabledBy {
decidedByModerator {
id
}
}
@ -38,7 +38,7 @@ const postQuery = gql`
Post(id: $id) {
id
disabled
disabledBy {
decidedByModerator {
id
}
}
@ -144,11 +144,11 @@ describe('moderate resources', () => {
})
})
it('changes .disabledBy', async () => {
it('changes .decidedByModerator', async () => {
variables = { id: 'comment-id' }
const before = { data: { Comment: [{ id: 'comment-id', disabledBy: null }] } }
const before = { data: { Comment: [{ id: 'comment-id', decidedByModerator: null }] } }
const expected = {
data: { Comment: [{ id: 'comment-id', disabledBy: { id: 'moderator-id' } }] },
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
}
await expect(query({ query: commentQuery, variables })).resolves.toMatchObject(before)
await expect(mutate({ mutation: disableMutation, variables })).resolves.toMatchObject({
@ -185,11 +185,11 @@ describe('moderate resources', () => {
})
})
it('changes .disabledBy', async () => {
it('changes .decidedByModerator', async () => {
variables = { id: 'sample-post-id' }
const before = { data: { Post: [{ id: 'sample-post-id', disabledBy: null }] } }
const before = { data: { Post: [{ id: 'sample-post-id', decidedByModerator: null }] } }
const expected = {
data: { Post: [{ id: 'sample-post-id', disabledBy: { id: 'moderator-id' } }] },
data: { Post: [{ id: 'sample-post-id', decidedByModerator: { id: 'moderator-id' } }] },
}
await expect(query({ query: postQuery, variables })).resolves.toMatchObject(before)
@ -278,9 +278,9 @@ describe('moderate resources', () => {
})
})
it('changes .disabledBy', async () => {
it('changes .decidedByModerator', async () => {
const expected = {
data: { Comment: [{ id: 'comment-id', disabledBy: null }] },
data: { Comment: [{ id: 'comment-id', decidedByModerator: { id: 'moderator-id' } }] },
errors: undefined,
}
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({
@ -320,9 +320,9 @@ describe('moderate resources', () => {
})
})
it('changes .disabledBy', async () => {
it('changes .decidedByModerator', async () => {
const expected = {
data: { Post: [{ id: 'post-id', disabledBy: null }] },
data: { Post: [{ id: 'post-id', decidedByModerator: { id: 'moderator-id' } }] },
errors: undefined,
}
await expect(mutate({ mutation: enableMutation, variables })).resolves.toMatchObject({

View File

@ -306,7 +306,7 @@ export default {
},
hasOne: {
author: '<-[:WROTE]-(related:User)',
disabledBy: '<-[:DECIDED]-(related:User)',
decidedByModerator: '<-[:DECIDED]-(related:User)',
pinnedBy: '<-[:PINNED]-(related:User)',
},
count: {

View File

@ -198,7 +198,7 @@ export default {
},
hasOne: {
invitedBy: '<-[:INVITED]-(related:User)',
disabledBy: '<-[:DECIDED]-(related:User)',
decidedByModerator: '<-[:DECIDED]-(related:User)',
location: '-[:IS_IN]->(related:Location)',
},
hasMany: {

View File

@ -9,7 +9,7 @@ type Comment {
updatedAt: String
deleted: Boolean
disabled: Boolean
disabledBy: User @relation(name: "DECIDED", direction: "IN")
decidedByModerator: User @relation(name: "DECIDED", direction: "IN")
}
type Mutation {

View File

@ -47,7 +47,7 @@ type Post {
deleted: Boolean
disabled: Boolean
pinned: Boolean
disabledBy: User @relation(name: "DECIDED", direction: "IN")
decidedByModerator: User @relation(name: "DECIDED", direction: "IN")
createdAt: String
updatedAt: String
language: String

View File

@ -8,7 +8,7 @@ type User {
coverImg: String
deleted: Boolean
disabled: Boolean
disabledBy: User @relation(name: "DECIDED", direction: "IN")
decidedByModerator: User @relation(name: "DECIDED", direction: "IN")
role: UserGroup!
publicKey: String
invitedBy: User @relation(name: "INVITED", direction: "IN")

View File

@ -25,7 +25,7 @@ export const reportListQuery = () => {
name
disabled
deleted
disabledBy {
decidedByModerator {
id
slug
name
@ -56,7 +56,7 @@ export const reportListQuery = () => {
disabled
deleted
}
disabledBy {
decidedByModerator {
id
slug
name
@ -80,7 +80,7 @@ export const reportListQuery = () => {
contributionsCount
commentedCount
}
disabledBy {
decidedByModerator {
id
slug
name

View File

@ -29,7 +29,10 @@
<tr valign="top">
<td class="ds-table-col ds-table-head-col ds-table-head-col-border">
<!-- Icon -->
<ds-text :class="[!content.resource.disabledBy && 'no-decision']" color="soft">
<ds-text
:class="[!content.resource.decidedByModerator && 'no-decision']"
color="soft"
>
<ds-icon
v-if="content.type === 'Post'"
v-tooltip="{ content: $t('report.contribution.type'), placement: 'right' }"
@ -85,10 +88,10 @@
</td>
<td class="ds-table-col ds-table-head-col-border">
<!-- disabledBy -->
<div v-if="content.resource.disabledBy">
<div v-if="content.resource.decidedByModerator">
{{ $t('moderation.reports.disabledBy') }}
<br />
<hc-user :user="content.resource.disabledBy" :showAvatar="false" :trunc="30" />
<hc-user :user="content.resource.decidedByModerator" :showAvatar="false" :trunc="30" />
</div>
<span v-else class="no-decision">{{ $t('moderation.reports.noDecision') }}</span>
</td>