Delete emails and social media, bugfix

The bugfix was missing '(' plus a wrong order for the social media
relationship called 'OWNED_BY'.
This commit is contained in:
roschaefer 2019-09-03 12:41:24 +02:00
parent 8c7e3708a4
commit bd885b1aac
7 changed files with 50 additions and 6 deletions

View File

@ -8,7 +8,7 @@ module.exports = {
type: 'relationship',
relationship: 'OWNED_BY',
target: 'User',
direction: 'in',
direction: 'out',
eager: true,
cascade: 'detach',
},

View File

@ -32,7 +32,7 @@ export default {
SocialMedia: Resolver('SocialMedia', {
idAttribute: 'url',
hasOne: {
ownedBy: '<-[:OWNED_BY]-(related:User)',
ownedBy: '-[:OWNED_BY]->(related:User)',
},
}),
}

View File

@ -129,6 +129,12 @@ export default {
SET user.deleted = true
SET user.name = 'UNAVAILABLE'
SET user.about = 'UNAVAILABLE'
WITH user
OPTIONAL MATCH (user)<-[:BELONGS_TO]-(email:EmailAddress)
DETACH DELETE email
WITH user
OPTIONAL MATCH (user)<-[:OWNED_BY]-(socialMedia:SocialMedia)
DETACH DELETE socialMedia
RETURN user`,
{ userId: context.user.id },
)
@ -185,7 +191,7 @@ export default {
followedBy: '<-[:FOLLOWS]-(related:User)',
following: '-[:FOLLOWS]->(related:User)',
friends: '-[:FRIENDS]-(related:User)',
socialMedia: '-[:OWNED_BY]->(related:SocialMedia',
socialMedia: '<-[:OWNED_BY]-(related:SocialMedia)',
contributions: '-[:WROTE]->(related:Post)',
comments: '-[:WROTE]->(related:Comment)',
shouted: '-[:SHOUTED]->(related:Post)',

View File

@ -50,8 +50,9 @@ describe('User', () => {
const variables = { email: 'any-email-address@example.org' }
it('is forbidden', async () => {
const { errors } = await query({ query: userQuery, variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorised!' }],
})
})
describe('as admin', () => {
@ -439,6 +440,27 @@ describe('DeleteUser', () => {
})
})
})
describe('connected `EmailAddress` nodes', () => {
it('will be removed completely', async () => {
await expect(neode.all('EmailAddress')).resolves.toHaveLength(2)
await mutate({ mutation: deleteUserMutation, variables })
await expect(neode.all('EmailAddress')).resolves.toHaveLength(1)
})
})
describe('connected `SocialMedia` nodes', () => {
beforeEach(async () => {
const socialMedia = await factory.create('SocialMedia')
await socialMedia.relateTo(user, 'ownedBy')
})
it('will be removed completely', async () => {
await expect(neode.all('SocialMedia')).resolves.toHaveLength(1)
await mutate({ mutation: deleteUserMutation, variables })
await expect(neode.all('SocialMedia')).resolves.toHaveLength(0)
})
})
})
})
})

View File

@ -17,7 +17,7 @@ type User {
location: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l")
locationName: String
about: String
socialMedia: [SocialMedia]! @relation(name: "OWNED_BY", direction: "OUT")
socialMedia: [SocialMedia]! @relation(name: "OWNED_BY", direction: "IN")
#createdAt: DateTime
#updatedAt: DateTime

View File

@ -6,6 +6,7 @@ import createPost from './posts.js'
import createComment from './comments.js'
import createCategory from './categories.js'
import createTag from './tags.js'
import createSocialMedia from './socialMedia.js'
export const seedServerHost = 'http://127.0.0.1:4001'
@ -26,6 +27,7 @@ const factories = {
Comment: createComment,
Category: createCategory,
Tag: createTag,
SocialMedia: createSocialMedia,
}
export const cleanDatabase = async (options = {}) => {

View File

@ -0,0 +1,14 @@
export default function create() {
return {
factory: async ({ args, neodeInstance }) => {
const defaults = {
url: 'https://mastodon.social/@Gargron',
}
args = {
...defaults,
...args,
}
return neodeInstance.create('SocialMedia', args)
},
}
}