mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactor 'createGroupMutation' to a function that returns GQL
This commit is contained in:
parent
dcfb361793
commit
7d9e42806c
@ -2,56 +2,58 @@ 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]
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
CreateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
groupType: $groupType
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
locationName: $locationName
|
||||
export const createGroupMutation = () => {
|
||||
return gql`
|
||||
mutation (
|
||||
$id: ID
|
||||
$name: String!
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String!
|
||||
$groupType: GroupType!
|
||||
$actionRadius: GroupActionRadius!
|
||||
$categoryIds: [ID]
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
CreateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
groupType: $groupType
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
locationName: $locationName
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
name
|
||||
icon
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
}
|
||||
locationName
|
||||
location {
|
||||
name
|
||||
nameDE
|
||||
nameEN
|
||||
}
|
||||
myRole
|
||||
}
|
||||
locationName
|
||||
location {
|
||||
name
|
||||
nameDE
|
||||
nameEN
|
||||
}
|
||||
myRole
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const updateGroupMutation = gql`
|
||||
mutation (
|
||||
|
||||
@ -305,7 +305,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
authenticatedUser = await peterLustig.toJson()
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'g0',
|
||||
name: 'Investigative Journalism',
|
||||
@ -363,7 +363,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
authenticatedUser = await jennyRostock.toJson()
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'g1',
|
||||
name: 'School For Citizens',
|
||||
@ -443,7 +443,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
authenticatedUser = await bobDerBaumeister.toJson()
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'g2',
|
||||
name: 'Yoga Practice',
|
||||
|
||||
@ -79,7 +79,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('generates a slug based on name', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
@ -99,7 +99,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('generates a slug based on given slug', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
slug: 'the-group',
|
||||
@ -118,7 +118,7 @@ describe('slugifyMiddleware', () => {
|
||||
describe('if slug exists', () => {
|
||||
beforeEach(async () => {
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
name: 'Pre-Existing Group',
|
||||
@ -131,7 +131,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('chooses another slug', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
name: 'Pre-Existing Group',
|
||||
@ -152,7 +152,7 @@ describe('slugifyMiddleware', () => {
|
||||
try {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
name: 'Pre-Existing Group',
|
||||
@ -194,7 +194,7 @@ describe('slugifyMiddleware', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
createGroupResult = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
name: 'The Best Group',
|
||||
slug: 'the-best-group',
|
||||
@ -265,7 +265,7 @@ describe('slugifyMiddleware', () => {
|
||||
describe('if new slug exists in another group', () => {
|
||||
beforeEach(async () => {
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
name: 'Pre-Existing Group',
|
||||
slug: 'pre-existing-group',
|
||||
|
||||
@ -156,7 +156,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
|
||||
// public-group
|
||||
authenticatedUser = await usualMemberUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'public-group',
|
||||
name: 'The Best Group',
|
||||
@ -184,7 +184,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
|
||||
// closed-group
|
||||
authenticatedUser = await ownerMemberUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'closed-group',
|
||||
name: 'Uninteresting Group',
|
||||
@ -198,7 +198,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
|
||||
// hidden-group
|
||||
authenticatedUser = await adminMemberUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'hidden-group',
|
||||
name: 'Investigative Journalism Group',
|
||||
@ -283,7 +283,7 @@ describe('in mode', () => {
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
const { errors } = await mutate({ mutation: createGroupMutation, variables })
|
||||
const { errors } = await mutate({ mutation: createGroupMutation(), variables })
|
||||
expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
|
||||
})
|
||||
})
|
||||
@ -294,49 +294,49 @@ describe('in mode', () => {
|
||||
})
|
||||
|
||||
it('creates a group', async () => {
|
||||
await expect(mutate({ mutation: createGroupMutation, variables })).resolves.toMatchObject(
|
||||
{
|
||||
data: {
|
||||
CreateGroup: {
|
||||
name: 'The Best Group',
|
||||
slug: 'the-group',
|
||||
about: 'We will change the world!',
|
||||
description: 'Some description' + descriptionAdditional100,
|
||||
groupType: 'public',
|
||||
actionRadius: 'regional',
|
||||
locationName: 'Hamburg, Germany',
|
||||
location: expect.objectContaining({
|
||||
name: 'Hamburg',
|
||||
nameDE: 'Hamburg',
|
||||
nameEN: 'Hamburg',
|
||||
}),
|
||||
},
|
||||
await expect(
|
||||
mutate({ mutation: createGroupMutation(), variables }),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreateGroup: {
|
||||
name: 'The Best Group',
|
||||
slug: 'the-group',
|
||||
about: 'We will change the world!',
|
||||
description: 'Some description' + descriptionAdditional100,
|
||||
groupType: 'public',
|
||||
actionRadius: 'regional',
|
||||
locationName: 'Hamburg, Germany',
|
||||
location: expect.objectContaining({
|
||||
name: 'Hamburg',
|
||||
nameDE: 'Hamburg',
|
||||
nameEN: 'Hamburg',
|
||||
}),
|
||||
},
|
||||
errors: undefined,
|
||||
},
|
||||
)
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('assigns the authenticated user as owner', async () => {
|
||||
await expect(mutate({ mutation: createGroupMutation, variables })).resolves.toMatchObject(
|
||||
{
|
||||
data: {
|
||||
CreateGroup: {
|
||||
name: 'The Best Group',
|
||||
myRole: 'owner',
|
||||
},
|
||||
await expect(
|
||||
mutate({ mutation: createGroupMutation(), variables }),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
CreateGroup: {
|
||||
name: 'The Best Group',
|
||||
myRole: 'owner',
|
||||
},
|
||||
errors: undefined,
|
||||
},
|
||||
)
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('has "disabled" and "deleted" default to "false"', async () => {
|
||||
await expect(mutate({ mutation: createGroupMutation, variables })).resolves.toMatchObject(
|
||||
{
|
||||
data: { CreateGroup: { disabled: false, deleted: false } },
|
||||
},
|
||||
)
|
||||
await expect(
|
||||
mutate({ mutation: createGroupMutation(), variables }),
|
||||
).resolves.toMatchObject({
|
||||
data: { CreateGroup: { disabled: false, deleted: false } },
|
||||
})
|
||||
})
|
||||
|
||||
describe('description', () => {
|
||||
@ -344,7 +344,7 @@ describe('in mode', () => {
|
||||
describe('less then 100 chars', () => {
|
||||
it('throws error: "Description too short!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
description:
|
||||
@ -367,7 +367,7 @@ describe('in mode', () => {
|
||||
it('has new categories', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
...variables,
|
||||
categoryIds: ['cat4', 'cat27'],
|
||||
@ -392,7 +392,7 @@ describe('in mode', () => {
|
||||
describe('by "categoryIds: null"', () => {
|
||||
it('throws error: "Too view categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: { ...variables, categoryIds: null },
|
||||
})
|
||||
expect(errors[0]).toHaveProperty('message', 'Too view categories!')
|
||||
@ -402,7 +402,7 @@ describe('in mode', () => {
|
||||
describe('by "categoryIds: []"', () => {
|
||||
it('throws error: "Too view categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: { ...variables, categoryIds: [] },
|
||||
})
|
||||
expect(errors[0]).toHaveProperty('message', 'Too view categories!')
|
||||
@ -413,7 +413,7 @@ describe('in mode', () => {
|
||||
describe('four', () => {
|
||||
it('throws error: "Too many categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: { ...variables, categoryIds: ['cat9', 'cat4', 'cat15', 'cat27'] },
|
||||
})
|
||||
expect(errors[0]).toHaveProperty('message', 'Too many categories!')
|
||||
@ -470,7 +470,7 @@ describe('in mode', () => {
|
||||
)
|
||||
authenticatedUser = await otherUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'others-group',
|
||||
name: 'Uninteresting Group',
|
||||
@ -483,7 +483,7 @@ describe('in mode', () => {
|
||||
})
|
||||
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'hidden-group',
|
||||
name: 'Investigative Journalism Group',
|
||||
@ -495,7 +495,7 @@ describe('in mode', () => {
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'second-hidden-group',
|
||||
name: 'Second Investigative Journalism Group',
|
||||
@ -515,7 +515,7 @@ describe('in mode', () => {
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'third-hidden-group',
|
||||
name: 'Third Investigative Journalism Group',
|
||||
@ -536,7 +536,7 @@ describe('in mode', () => {
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
name: 'The Best Group',
|
||||
@ -857,7 +857,7 @@ describe('in mode', () => {
|
||||
// public-group
|
||||
authenticatedUser = await ownerOfClosedGroupUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'closed-group',
|
||||
name: 'Uninteresting Group',
|
||||
@ -870,7 +870,7 @@ describe('in mode', () => {
|
||||
})
|
||||
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'hidden-group',
|
||||
name: 'Investigative Journalism Group',
|
||||
@ -883,7 +883,7 @@ describe('in mode', () => {
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'public-group',
|
||||
name: 'The Best Group',
|
||||
@ -1108,7 +1108,7 @@ describe('in mode', () => {
|
||||
// public-group
|
||||
authenticatedUser = await user.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'public-group',
|
||||
name: 'The Best Group',
|
||||
@ -1136,7 +1136,7 @@ describe('in mode', () => {
|
||||
// closed-group
|
||||
authenticatedUser = await ownerOfClosedGroupUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'closed-group',
|
||||
name: 'Uninteresting Group',
|
||||
@ -1165,7 +1165,7 @@ describe('in mode', () => {
|
||||
// hidden-group
|
||||
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'hidden-group',
|
||||
name: 'Investigative Journalism Group',
|
||||
@ -2648,7 +2648,7 @@ describe('in mode', () => {
|
||||
)
|
||||
authenticatedUser = await noMemberUser.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'others-group',
|
||||
name: 'Uninteresting Group',
|
||||
@ -2661,7 +2661,7 @@ describe('in mode', () => {
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
await mutate({
|
||||
mutation: createGroupMutation,
|
||||
mutation: createGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
name: 'The Best Group',
|
||||
|
||||
@ -2,51 +2,53 @@ 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]
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
CreateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
groupType: $groupType
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
locationName: $locationName
|
||||
export const createGroupMutation = () => {
|
||||
return gql`
|
||||
mutation (
|
||||
$id: ID
|
||||
$name: String!
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String!
|
||||
$groupType: GroupType!
|
||||
$actionRadius: GroupActionRadius!
|
||||
$categoryIds: [ID]
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
CreateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
groupType: $groupType
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
locationName: $locationName
|
||||
) {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
}
|
||||
locationName # test this as result
|
||||
myRole
|
||||
}
|
||||
locationName # test this as result
|
||||
myRole
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const updateGroupMutation = gql`
|
||||
mutation (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user