mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Implement 'Group' query, second step
This commit is contained in:
parent
94411648fd
commit
867b78dfa3
29
backend/src/db/graphql/authentications.ts
Normal file
29
backend/src/db/graphql/authentications.ts
Normal file
@ -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
|
||||
95
backend/src/db/graphql/groups.ts
Normal file
95
backend/src/db/graphql/groups.ts
Normal file
@ -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
|
||||
# }
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
`
|
||||
15
backend/src/db/graphql/posts.ts
Normal file
15
backend/src/db/graphql/posts.ts
Normal file
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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(() => {
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user