diff --git a/backend/src/db/graphql/authentications.ts b/backend/src/db/graphql/authentications.ts new file mode 100644 index 000000000..f05970650 --- /dev/null +++ b/backend/src/db/graphql/authentications.ts @@ -0,0 +1,29 @@ +import gql from 'graphql-tag' + +// ------ mutations + +export const signupVerificationMutation = gql` + mutation ( + $password: String! + $email: String! + $name: String! + $slug: String + $nonce: String! + $termsAndConditionsAgreedVersion: String! + ) { + SignupVerification( + email: $email + password: $password + name: $name + slug: $slug + nonce: $nonce + termsAndConditionsAgreedVersion: $termsAndConditionsAgreedVersion + ) { + slug + } + } +` + +// ------ queries + +// fill queries in here diff --git a/backend/src/db/graphql/groups.ts b/backend/src/db/graphql/groups.ts new file mode 100644 index 000000000..80b599658 --- /dev/null +++ b/backend/src/db/graphql/groups.ts @@ -0,0 +1,95 @@ +import gql from 'graphql-tag' + +// ------ mutations + +export const createGroupMutation = gql` + mutation ( + $id: ID, + $name: String!, + $slug: String, + $about: String, + $description: String!, + $groupType: GroupType!, + $actionRadius: GroupActionRadius!, + $categoryIds: [ID] + ) { + CreateGroup( + id: $id + name: $name + slug: $slug + about: $about + description: $description + groupType: $groupType + actionRadius: $actionRadius + categoryIds: $categoryIds + ) { + id + name + slug + createdAt + updatedAt + disabled + deleted + about + description + groupType + actionRadius + myRole + # Wolle: owner { + # name + # } + } + } +` + +// ------ queries + +export const groupQuery = gql` + query ( + $id: ID, + $name: String, + $slug: String, + $createdAt: String + $updatedAt: String + $about: String, + $description: String, + # $groupType: GroupType!, + # $actionRadius: GroupActionRadius!, + $categoryIds: [ID] + $locationName: String + $first: Int + $offset: Int + $orderBy: [_GroupOrdering] + $filter: _GroupFilter + ) { + Group( + id: $id + name: $name + slug: $slug + createdAt: $createdAt + updatedAt: $updatedAt + about: $about + description: $description + # groupType: $groupType + # actionRadius: $actionRadius + categoryIds: $categoryIds + locationName: $locationName + ) { + id + name + slug + createdAt + updatedAt + disabled + deleted + about + description + groupType + actionRadius + myRole + # Wolle: owner { + # name + # } + } + } +` diff --git a/backend/src/db/graphql/mutations.ts b/backend/src/db/graphql/mutations.ts deleted file mode 100644 index 4f07e0f1e..000000000 --- a/backend/src/db/graphql/mutations.ts +++ /dev/null @@ -1,69 +0,0 @@ -import gql from 'graphql-tag' - -export const createGroupMutation = gql` - mutation ( - $id: ID, - $name: String!, - $slug: String, - $about: String, - $description: String!, - $groupType: GroupType!, - $actionRadius: GroupActionRadius!, - $categoryIds: [ID] - ) { - CreateGroup( - id: $id - name: $name - slug: $slug - about: $about - description: $description - groupType: $groupType - actionRadius: $actionRadius - categoryIds: $categoryIds - ) { - id - name - slug - about - description - groupType - actionRadius - disabled - deleted - myRole - # Wolle: owner { - # name - # } - } - } -` - -export const createPostMutation = gql` - mutation ($title: String!, $content: String!, $categoryIds: [ID]!, $slug: String) { - CreatePost(title: $title, content: $content, categoryIds: $categoryIds, slug: $slug) { - slug - } - } -` - -export const signupVerificationMutation = gql` - mutation ( - $password: String! - $email: String! - $name: String! - $slug: String - $nonce: String! - $termsAndConditionsAgreedVersion: String! - ) { - SignupVerification( - email: $email - password: $password - name: $name - slug: $slug - nonce: $nonce - termsAndConditionsAgreedVersion: $termsAndConditionsAgreedVersion - ) { - slug - } - } -` diff --git a/backend/src/db/graphql/posts.ts b/backend/src/db/graphql/posts.ts new file mode 100644 index 000000000..3277af820 --- /dev/null +++ b/backend/src/db/graphql/posts.ts @@ -0,0 +1,15 @@ +import gql from 'graphql-tag' + +// ------ mutations + +export const createPostMutation = gql` + mutation ($title: String!, $content: String!, $categoryIds: [ID]!, $slug: String) { + CreatePost(title: $title, content: $content, categoryIds: $categoryIds, slug: $slug) { + slug + } + } +` + +// ------ queries + +// fill queries in here diff --git a/backend/src/middleware/slugifyMiddleware.spec.js b/backend/src/middleware/slugifyMiddleware.spec.js index af6ff25b0..3c18e70b0 100644 --- a/backend/src/middleware/slugifyMiddleware.spec.js +++ b/backend/src/middleware/slugifyMiddleware.spec.js @@ -2,11 +2,9 @@ import { getNeode, getDriver } from '../db/neo4j' import createServer from '../server' import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../db/factories' -import { - createPostMutation, - createGroupMutation, - signupVerificationMutation, -} from '../db/graphql/mutations' +import { createGroupMutation } from '../db/graphql/groups' +import { createPostMutation } from '../db/graphql/posts' +import { signupVerificationMutation } from '../db/graphql/authentications' let mutate let authenticatedUser diff --git a/backend/src/schema/resolvers/groups.spec.js b/backend/src/schema/resolvers/groups.spec.js index 17fc4b1da..8860f87f2 100644 --- a/backend/src/schema/resolvers/groups.spec.js +++ b/backend/src/schema/resolvers/groups.spec.js @@ -1,6 +1,6 @@ import { createTestClient } from 'apollo-server-testing' import Factory, { cleanDatabase } from '../../db/factories' -import { createGroupMutation } from '../../db/graphql/mutations' +import { createGroupMutation } from '../../db/graphql/groups' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' @@ -78,171 +78,164 @@ afterEach(async () => { await cleanDatabase() }) -// describe('Group', () => { -// describe('can be filtered', () => { -// let followedUser, happyPost, cryPost -// beforeEach(async () => { -// ;[followedUser] = await Promise.all([ -// Factory.build( -// 'user', -// { -// id: 'followed-by-me', -// name: 'Followed User', -// }, -// { -// email: 'followed@example.org', -// password: '1234', -// }, -// ), -// ]) -// ;[happyPost, cryPost] = await Promise.all([ -// Factory.build('post', { id: 'happy-post' }, { categoryIds: ['cat4'] }), -// Factory.build('post', { id: 'cry-post' }, { categoryIds: ['cat15'] }), -// Factory.build( -// 'post', -// { -// id: 'post-by-followed-user', -// }, -// { -// categoryIds: ['cat9'], -// author: followedUser, -// }, -// ), -// ]) -// }) - -// describe('no filter', () => { -// it('returns all posts', async () => { -// const postQueryNoFilters = gql` -// query Post($filter: _PostFilter) { -// Post(filter: $filter) { -// id -// } -// } -// ` -// const expected = [{ id: 'happy-post' }, { id: 'cry-post' }, { id: 'post-by-followed-user' }] -// variables = { filter: {} } -// await expect(query({ query: postQueryNoFilters, variables })).resolves.toMatchObject({ -// data: { -// Post: expect.arrayContaining(expected), -// }, -// }) -// }) -// }) - -// /* it('by categories', async () => { -// const postQueryFilteredByCategories = gql` -// query Post($filter: _PostFilter) { -// Post(filter: $filter) { -// id -// categories { -// id -// } -// } -// } -// ` -// const expected = { -// data: { -// Post: [ -// { -// id: 'post-by-followed-user', -// categories: [{ id: 'cat9' }], -// }, -// ], -// }, -// } -// variables = { ...variables, filter: { categories_some: { id_in: ['cat9'] } } } -// await expect( -// query({ query: postQueryFilteredByCategories, variables }), -// ).resolves.toMatchObject(expected) -// }) */ - -// describe('by emotions', () => { -// const postQueryFilteredByEmotions = gql` -// query Post($filter: _PostFilter) { -// Post(filter: $filter) { -// id -// emotions { -// emotion -// } -// } -// } -// ` - -// it('filters by single emotion', async () => { -// const expected = { -// data: { -// Post: [ -// { -// id: 'happy-post', -// emotions: [{ emotion: 'happy' }], -// }, -// ], -// }, -// } -// await user.relateTo(happyPost, 'emoted', { emotion: 'happy' }) -// variables = { ...variables, filter: { emotions_some: { emotion_in: ['happy'] } } } -// await expect( -// query({ query: postQueryFilteredByEmotions, variables }), -// ).resolves.toMatchObject(expected) -// }) - -// it('filters by multiple emotions', async () => { -// const expected = [ -// { -// id: 'happy-post', -// emotions: [{ emotion: 'happy' }], -// }, -// { -// id: 'cry-post', -// emotions: [{ emotion: 'cry' }], -// }, -// ] -// await user.relateTo(happyPost, 'emoted', { emotion: 'happy' }) -// await user.relateTo(cryPost, 'emoted', { emotion: 'cry' }) -// variables = { ...variables, filter: { emotions_some: { emotion_in: ['happy', 'cry'] } } } -// await expect( -// query({ query: postQueryFilteredByEmotions, variables }), -// ).resolves.toMatchObject({ -// data: { -// Post: expect.arrayContaining(expected), -// }, -// errors: undefined, -// }) -// }) -// }) - -// it('by followed-by', async () => { -// const postQueryFilteredByUsersFollowed = gql` -// query Post($filter: _PostFilter) { -// Post(filter: $filter) { -// id -// author { -// id -// name -// } -// } -// } -// ` - -// await user.relateTo(followedUser, 'following') -// variables = { filter: { author: { followedBy_some: { id: 'current-user' } } } } -// await expect( -// query({ query: postQueryFilteredByUsersFollowed, variables }), -// ).resolves.toMatchObject({ -// data: { -// Post: [ -// { -// id: 'post-by-followed-user', -// author: { id: 'followed-by-me', name: 'Followed User' }, -// }, -// ], -// }, -// errors: undefined, -// }) -// }) -// }) -// }) +describe('Group', () => { + // describe('can be filtered', () => { + // let followedUser, happyPost, cryPost + // beforeEach(async () => { + // ;[followedUser] = await Promise.all([ + // Factory.build( + // 'user', + // { + // id: 'followed-by-me', + // name: 'Followed User', + // }, + // { + // email: 'followed@example.org', + // password: '1234', + // }, + // ), + // ]) + // ;[happyPost, cryPost] = await Promise.all([ + // Factory.build('post', { id: 'happy-post' }, { categoryIds: ['cat4'] }), + // Factory.build('post', { id: 'cry-post' }, { categoryIds: ['cat15'] }), + // Factory.build( + // 'post', + // { + // id: 'post-by-followed-user', + // }, + // { + // categoryIds: ['cat9'], + // author: followedUser, + // }, + // ), + // ]) + // }) + // describe('no filter', () => { + // it('returns all posts', async () => { + // const postQueryNoFilters = gql` + // query Post($filter: _PostFilter) { + // Post(filter: $filter) { + // id + // } + // } + // ` + // const expected = [{ id: 'happy-post' }, { id: 'cry-post' }, { id: 'post-by-followed-user' }] + // variables = { filter: {} } + // await expect(query({ query: postQueryNoFilters, variables })).resolves.toMatchObject({ + // data: { + // Post: expect.arrayContaining(expected), + // }, + // }) + // }) + // }) + // /* it('by categories', async () => { + // const postQueryFilteredByCategories = gql` + // query Post($filter: _PostFilter) { + // Post(filter: $filter) { + // id + // categories { + // id + // } + // } + // } + // ` + // const expected = { + // data: { + // Post: [ + // { + // id: 'post-by-followed-user', + // categories: [{ id: 'cat9' }], + // }, + // ], + // }, + // } + // variables = { ...variables, filter: { categories_some: { id_in: ['cat9'] } } } + // await expect( + // query({ query: postQueryFilteredByCategories, variables }), + // ).resolves.toMatchObject(expected) + // }) */ + // describe('by emotions', () => { + // const postQueryFilteredByEmotions = gql` + // query Post($filter: _PostFilter) { + // Post(filter: $filter) { + // id + // emotions { + // emotion + // } + // } + // } + // ` + // it('filters by single emotion', async () => { + // const expected = { + // data: { + // Post: [ + // { + // id: 'happy-post', + // emotions: [{ emotion: 'happy' }], + // }, + // ], + // }, + // } + // await user.relateTo(happyPost, 'emoted', { emotion: 'happy' }) + // variables = { ...variables, filter: { emotions_some: { emotion_in: ['happy'] } } } + // await expect( + // query({ query: postQueryFilteredByEmotions, variables }), + // ).resolves.toMatchObject(expected) + // }) + // it('filters by multiple emotions', async () => { + // const expected = [ + // { + // id: 'happy-post', + // emotions: [{ emotion: 'happy' }], + // }, + // { + // id: 'cry-post', + // emotions: [{ emotion: 'cry' }], + // }, + // ] + // await user.relateTo(happyPost, 'emoted', { emotion: 'happy' }) + // await user.relateTo(cryPost, 'emoted', { emotion: 'cry' }) + // variables = { ...variables, filter: { emotions_some: { emotion_in: ['happy', 'cry'] } } } + // await expect( + // query({ query: postQueryFilteredByEmotions, variables }), + // ).resolves.toMatchObject({ + // data: { + // Post: expect.arrayContaining(expected), + // }, + // errors: undefined, + // }) + // }) + // }) + // it('by followed-by', async () => { + // const postQueryFilteredByUsersFollowed = gql` + // query Post($filter: _PostFilter) { + // Post(filter: $filter) { + // id + // author { + // id + // name + // } + // } + // } + // ` + // await user.relateTo(followedUser, 'following') + // variables = { filter: { author: { followedBy_some: { id: 'current-user' } } } } + // await expect( + // query({ query: postQueryFilteredByUsersFollowed, variables }), + // ).resolves.toMatchObject({ + // data: { + // Post: [ + // { + // id: 'post-by-followed-user', + // author: { id: 'followed-by-me', name: 'Followed User' }, + // }, + // ], + // }, + // errors: undefined, + // }) + // }) + // }) +}) describe('CreateGroup', () => { beforeEach(() => { diff --git a/backend/src/schema/types/type/Group.gql b/backend/src/schema/types/type/Group.gql index 72ac9b57a..cd15689ec 100644 --- a/backend/src/schema/types/type/Group.gql +++ b/backend/src/schema/types/type/Group.gql @@ -175,9 +175,9 @@ type Query { slug: String createdAt: String updatedAt: String - locationName: String about: String description: String + locationName: String first: Int offset: Int orderBy: [_GroupOrdering]