From f86fc7507c1cf1f487f7ecce418076e153cf43de Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Fri, 8 Mar 2019 16:49:43 +0100 Subject: [PATCH] Fixed shout and follow seeding --- src/seed/factories/index.js | 26 ++++++++++++++++ src/seed/seed-db.js | 59 +++++++++++++++++++++++++++---------- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/seed/factories/index.js b/src/seed/factories/index.js index 68dd99200..2629ce8b6 100644 --- a/src/seed/factories/index.js +++ b/src/seed/factories/index.js @@ -90,6 +90,32 @@ export default function Factory (options = {}) { this.lastResponse = await this.graphQLClient.request(mutation, variables) return this }, + async shout (properties) { + const { id, type } = properties + const mutation = ` + mutation { + shout( + id: "${id}", + type: ${type} + ) + } + ` + this.lastResponse = await this.graphQLClient.request(mutation) + return this + }, + async follow (properties) { + const { id, type } = properties + const mutation = ` + mutation { + follow( + id: "${id}", + type: ${type} + ) + } + ` + this.lastResponse = await this.graphQLClient.request(mutation) + return this + }, async cleanDatabase () { this.lastResponse = await cleanDatabase({ driver: this.neo4jDriver }) return this diff --git a/src/seed/seed-db.js b/src/seed/seed-db.js index 310089ef7..51a456126 100644 --- a/src/seed/seed-db.js +++ b/src/seed/seed-db.js @@ -23,6 +23,15 @@ import Factory from './factories' f.create('User', { id: 'u7', name: 'Dagobert', role: 'user', email: 'dagobert@example.org' }) ]) + const [ asAdmin, asModerator, asUser, asTick, asTrick, asTrack ] = await Promise.all([ + Factory().authenticateAs({ email: 'admin@example.org', password: '1234' }), + Factory().authenticateAs({ email: 'moderator@example.org', password: '1234' }), + Factory().authenticateAs({ email: 'user@example.org', password: '1234' }), + Factory().authenticateAs({ email: 'tick@example.org', password: '1234' }), + Factory().authenticateAs({ email: 'trick@example.org', password: '1234' }), + Factory().authenticateAs({ email: 'track@example.org', password: '1234' }) + ]) + await Promise.all([ f.relate('User', 'Badges', { from: 'b6', to: 'u1' }), f.relate('User', 'Badges', { from: 'b5', to: 'u2' }), @@ -30,12 +39,6 @@ import Factory from './factories' f.relate('User', 'Badges', { from: 'b3', to: 'u4' }), f.relate('User', 'Badges', { from: 'b2', to: 'u5' }), f.relate('User', 'Badges', { from: 'b1', to: 'u6' }), - f.relate('User', 'Following', { from: 'u1', to: 'u2' }), - f.relate('User', 'Following', { from: 'u2', to: 'u3' }), - f.relate('User', 'Following', { from: 'u3', to: 'u4' }), - f.relate('User', 'Following', { from: 'u4', to: 'u5' }), - f.relate('User', 'Following', { from: 'u5', to: 'u6' }), - f.relate('User', 'Following', { from: 'u6', to: 'u7' }), f.relate('User', 'Friends', { from: 'u1', to: 'u2' }), f.relate('User', 'Friends', { from: 'u1', to: 'u3' }), f.relate('User', 'Friends', { from: 'u2', to: 'u3' }), @@ -44,6 +47,21 @@ import Factory from './factories' f.relate('User', 'Blacklisted', { from: 'u7', to: 'u6' }) ]) + await Promise.all([ + asAdmin + .follow({ id: 'u3', type: 'User' }), + asModerator + .follow({ id: 'u4', type: 'User' }), + asUser + .follow({ id: 'u4', type: 'User' }), + asTick + .follow({ id: 'u6', type: 'User' }), + asTrick + .follow({ id: 'u4', type: 'User' }), + asTrack + .follow({ id: 'u3', type: 'User' }) + ]) + await Promise.all([ f.create('Category', { id: 'cat1', name: 'Just For Fun', slug: 'justforfun', icon: 'smile' }), f.create('Category', { id: 'cat2', name: 'Happyness & Values', slug: 'happyness-values', icon: 'heart-o' }), @@ -70,15 +88,6 @@ import Factory from './factories' f.create('Tag', { id: 't4', name: 'Freiheit' }) ]) - const [ asAdmin, asModerator, asUser, asTick, asTrick, asTrack ] = await Promise.all([ - Factory().authenticateAs({ email: 'admin@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'moderator@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'user@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'tick@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'trick@example.org', password: '1234' }), - Factory().authenticateAs({ email: 'track@example.org', password: '1234' }) - ]) - await Promise.all([ asAdmin.create('Post', { id: 'p0' }), asModerator.create('Post', { id: 'p1' }), @@ -151,6 +160,26 @@ import Factory from './factories' f.relate('User', 'Shouted', { from: 'u3', to: 'p4' }), f.relate('User', 'Shouted', { from: 'u4', to: 'p1' }) ]) + await Promise.all([ + asAdmin + .shout({ id: 'p2', type: 'Post' }), + asAdmin + .shout({ id: 'p6', type: 'Post' }), + asModerator + .shout({ id: 'p0', type: 'Post' }), + asModerator + .shout({ id: 'p6', type: 'Post' }), + asUser + .shout({ id: 'p6', type: 'Post' }), + asUser + .shout({ id: 'p7', type: 'Post' }), + asTick + .shout({ id: 'p8', type: 'Post' }), + asTick + .shout({ id: 'p9', type: 'Post' }), + asTrack + .shout({ id: 'p10', type: 'Post' }) + ]) await Promise.all([ f.create('Comment', { id: 'c1' }),