mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Refactor 'updateGroupMutation' to a function that returns GQL
- Add and refactor some tests for the user resolvers. - Refactor minor in general.
This commit is contained in:
parent
7d9e42806c
commit
6df10e5588
@ -55,57 +55,59 @@ export const createGroupMutation = () => {
|
||||
`
|
||||
}
|
||||
|
||||
export const updateGroupMutation = gql`
|
||||
mutation (
|
||||
$id: ID!
|
||||
$name: String
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String
|
||||
$actionRadius: GroupActionRadius
|
||||
$categoryIds: [ID]
|
||||
$avatar: ImageInput
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
UpdateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
avatar: $avatar
|
||||
locationName: $locationName
|
||||
export const updateGroupMutation = () => {
|
||||
return gql`
|
||||
mutation (
|
||||
$id: ID!
|
||||
$name: String
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String
|
||||
$actionRadius: GroupActionRadius
|
||||
$categoryIds: [ID]
|
||||
$avatar: ImageInput
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
UpdateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
avatar: $avatar
|
||||
locationName: $locationName
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
name
|
||||
icon
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
}
|
||||
# avatar # test this as result
|
||||
locationName
|
||||
location {
|
||||
name
|
||||
nameDE
|
||||
nameEN
|
||||
}
|
||||
myRole
|
||||
}
|
||||
# avatar # test this as result
|
||||
locationName
|
||||
location {
|
||||
name
|
||||
nameDE
|
||||
nameEN
|
||||
}
|
||||
myRole
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const joinGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
|
||||
@ -51,6 +51,7 @@ beforeEach(async () => {
|
||||
await Factory.build('category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
slug: 'democracy-politics',
|
||||
icon: 'university',
|
||||
})
|
||||
authenticatedUser = await admin.toJson()
|
||||
@ -93,6 +94,7 @@ describe('slugifyMiddleware', () => {
|
||||
actionRadius: 'national',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
@ -111,6 +113,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'the-group',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -144,6 +147,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'pre-existing-group-1',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
@ -213,7 +217,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('has the new slug', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: createGroupResult.data.CreateGroup.id,
|
||||
name: 'My Best Group',
|
||||
@ -231,6 +235,7 @@ describe('slugifyMiddleware', () => {
|
||||
myRole: 'owner',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -239,7 +244,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('has the new slug', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: createGroupResult.data.CreateGroup.id,
|
||||
slug: 'my-best-group',
|
||||
@ -257,6 +262,7 @@ describe('slugifyMiddleware', () => {
|
||||
myRole: 'owner',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -282,7 +288,7 @@ describe('slugifyMiddleware', () => {
|
||||
it('has unique slug "*-1"', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: createGroupResult.data.CreateGroup.id,
|
||||
name: 'Pre-Existing Group',
|
||||
@ -300,6 +306,7 @@ describe('slugifyMiddleware', () => {
|
||||
myRole: 'owner',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -309,7 +316,7 @@ describe('slugifyMiddleware', () => {
|
||||
try {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: createGroupResult.data.CreateGroup.id,
|
||||
slug: 'pre-existing-group',
|
||||
@ -368,6 +375,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'i-am-a-brand-new-post',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
@ -386,6 +394,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'the-post',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -422,6 +431,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'pre-existing-post-1',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
@ -504,6 +514,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'i-am-a-user',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
@ -522,6 +533,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'the-user',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -546,6 +558,7 @@ describe('slugifyMiddleware', () => {
|
||||
slug: 'i-am-a-user-1',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -86,6 +86,7 @@ export default {
|
||||
CreateGroup: async (_parent, params, context, _resolveInfo) => {
|
||||
const { categoryIds } = params
|
||||
delete params.categoryIds
|
||||
params.locationName = params.locationName === '' ? null : params.locationName
|
||||
if (CONFIG.CATEGORIES_ACTIVE && (!categoryIds || categoryIds.length < CATEGORIES_MIN)) {
|
||||
throw new UserInputError('Too view categories!')
|
||||
}
|
||||
@ -137,6 +138,7 @@ export default {
|
||||
})
|
||||
try {
|
||||
const group = await writeTxResultPromise
|
||||
// TODO: put in a middleware, see "UpdateGroup", "UpdateUser"
|
||||
await createOrUpdateLocations('Group', params.id, params.locationName, session)
|
||||
return group
|
||||
} catch (error) {
|
||||
@ -212,10 +214,8 @@ export default {
|
||||
})
|
||||
try {
|
||||
const group = await writeTxResultPromise
|
||||
// TODO: put in a middleware, see "UpdateUser"
|
||||
if (params.locationName !== undefined) {
|
||||
await createOrUpdateLocations('Group', params.id, params.locationName, session)
|
||||
}
|
||||
// TODO: put in a middleware, see "CreateGroup", "UpdateUser"
|
||||
await createOrUpdateLocations('Group', params.id, params.locationName, session)
|
||||
return group
|
||||
} catch (error) {
|
||||
if (error.code === 'Neo.ClientError.Schema.ConstraintValidationFailed')
|
||||
|
||||
@ -2610,7 +2610,7 @@ describe('in mode', () => {
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
const { errors } = await mutate({
|
||||
query: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
slug: 'my-best-group',
|
||||
@ -2693,7 +2693,7 @@ describe('in mode', () => {
|
||||
it('has updated the settings', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
name: 'The New Group For Our Country',
|
||||
@ -2726,7 +2726,7 @@ describe('in mode', () => {
|
||||
it('has left locaton unchanged as "Berlin"', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
},
|
||||
@ -2753,7 +2753,7 @@ describe('in mode', () => {
|
||||
it('has updated the location to unset location', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
locationName: null,
|
||||
@ -2777,7 +2777,7 @@ describe('in mode', () => {
|
||||
it('has updated the location to "Paris"', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
locationName: 'Paris, France',
|
||||
@ -2805,7 +2805,7 @@ describe('in mode', () => {
|
||||
it('has updated the location to "Hamburg"', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
locationName: 'Hamburg, Germany',
|
||||
@ -2833,7 +2833,7 @@ describe('in mode', () => {
|
||||
it('has updated the location to unset', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
locationName: '', // empty string '' sets it to null
|
||||
@ -2859,7 +2859,7 @@ describe('in mode', () => {
|
||||
describe('less then 100 chars', () => {
|
||||
it('throws error: "Description too short!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
description:
|
||||
@ -2882,7 +2882,7 @@ describe('in mode', () => {
|
||||
it('has new categories', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
categoryIds: ['cat4', 'cat27'],
|
||||
@ -2908,7 +2908,7 @@ describe('in mode', () => {
|
||||
describe('by "categoryIds: []"', () => {
|
||||
it('throws error: "Too view categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
categoryIds: [],
|
||||
@ -2922,7 +2922,7 @@ describe('in mode', () => {
|
||||
describe('four', () => {
|
||||
it('throws error: "Too many categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
categoryIds: ['cat9', 'cat4', 'cat15', 'cat27'],
|
||||
@ -2938,7 +2938,7 @@ describe('in mode', () => {
|
||||
it('throws authorization error', async () => {
|
||||
authenticatedUser = await usualMemberUser.toJson()
|
||||
const { errors } = await mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
name: 'The New Group For Our Country',
|
||||
@ -2956,7 +2956,7 @@ describe('in mode', () => {
|
||||
it('throws authorization error', async () => {
|
||||
authenticatedUser = await noMemberUser.toJson()
|
||||
const { errors } = await mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables: {
|
||||
id: 'my-group',
|
||||
name: 'The New Group For Our Country',
|
||||
|
||||
@ -170,10 +170,8 @@ export default {
|
||||
})
|
||||
try {
|
||||
const user = await writeTxResultPromise
|
||||
// TODO: put in a middleware, see "CreateGroup, UpdateGroup"
|
||||
if (params.locationName !== undefined) {
|
||||
await createOrUpdateLocations('User', params.id, params.locationName, session)
|
||||
}
|
||||
// TODO: put in a middleware, see "CreateGroup", "UpdateGroup"
|
||||
await createOrUpdateLocations('User', params.id, params.locationName, session)
|
||||
return user
|
||||
} catch (error) {
|
||||
throw new UserInputError(error.message)
|
||||
|
||||
@ -174,6 +174,11 @@ describe('UpdateUser', () => {
|
||||
termsAndConditionsAgreedVersion
|
||||
termsAndConditionsAgreedAt
|
||||
locationName
|
||||
location {
|
||||
name
|
||||
nameDE
|
||||
nameEN
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -289,11 +294,39 @@ describe('UpdateUser', () => {
|
||||
expect(errors[0]).toHaveProperty('message', 'Invalid version format!')
|
||||
})
|
||||
|
||||
it('supports updating location', async () => {
|
||||
variables = { ...variables, locationName: 'Hamburg, New Jersey, United States' }
|
||||
await expect(mutate({ mutation: updateUserMutation, variables })).resolves.toMatchObject({
|
||||
data: { UpdateUser: { locationName: 'Hamburg, New Jersey, United States' } },
|
||||
errors: undefined,
|
||||
describe('supports updating location', () => {
|
||||
describe('change location to "Hamburg, New Jersey, United States"', () => {
|
||||
it('has updated location to "Hamburg, New Jersey, United States"', async () => {
|
||||
variables = { ...variables, locationName: 'Hamburg, New Jersey, United States' }
|
||||
await expect(mutate({ mutation: updateUserMutation, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
UpdateUser: {
|
||||
locationName: 'Hamburg, New Jersey, United States',
|
||||
location: expect.objectContaining({
|
||||
name: 'Hamburg',
|
||||
nameDE: 'Hamburg',
|
||||
nameEN: 'Hamburg',
|
||||
}),
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('change location to unset location', () => {
|
||||
it('has updated location to unset location', async () => {
|
||||
variables = { ...variables, locationName: '' }
|
||||
await expect(mutate({ mutation: updateUserMutation, variables })).resolves.toMatchObject({
|
||||
data: {
|
||||
UpdateUser: {
|
||||
locationName: null,
|
||||
location: null,
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -62,6 +62,8 @@ const createLocation = async (session, mapboxData) => {
|
||||
}
|
||||
|
||||
export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, session) => {
|
||||
if (locationName === undefined) return
|
||||
|
||||
let locationId
|
||||
|
||||
if (locationName !== null) {
|
||||
|
||||
@ -29,7 +29,7 @@ export default {
|
||||
},
|
||||
props: {
|
||||
profile: { type: Object, required: true },
|
||||
updateMutation: { type: Object, required: true },
|
||||
updateMutation: { type: Function, required: true },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -69,7 +69,7 @@ export default {
|
||||
const avatarUpload = file[0]
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: this.updateMutation,
|
||||
mutation: this.updateMutation(),
|
||||
variables: {
|
||||
avatar: {
|
||||
upload: avatarUpload,
|
||||
|
||||
@ -50,53 +50,55 @@ export const createGroupMutation = () => {
|
||||
`
|
||||
}
|
||||
|
||||
export const updateGroupMutation = gql`
|
||||
mutation (
|
||||
$id: ID!
|
||||
$name: String
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String
|
||||
$actionRadius: GroupActionRadius
|
||||
$categoryIds: [ID]
|
||||
$avatar: ImageInput
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
UpdateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
avatar: $avatar
|
||||
locationName: $locationName
|
||||
export const updateGroupMutation = () => {
|
||||
return gql`
|
||||
mutation (
|
||||
$id: ID!
|
||||
$name: String
|
||||
$slug: String
|
||||
$about: String
|
||||
$description: String
|
||||
$actionRadius: GroupActionRadius
|
||||
$categoryIds: [ID]
|
||||
$avatar: ImageInput
|
||||
$locationName: String # empty string '' sets it to null
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
descriptionExcerpt
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
UpdateGroup(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
about: $about
|
||||
description: $description
|
||||
actionRadius: $actionRadius
|
||||
categoryIds: $categoryIds
|
||||
avatar: $avatar
|
||||
locationName: $locationName
|
||||
) {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
slug
|
||||
createdAt
|
||||
updatedAt
|
||||
disabled
|
||||
deleted
|
||||
about
|
||||
description
|
||||
descriptionExcerpt
|
||||
groupType
|
||||
actionRadius
|
||||
categories {
|
||||
id
|
||||
slug
|
||||
name
|
||||
icon
|
||||
}
|
||||
# avatar # test this as result
|
||||
locationName # test this as result
|
||||
myRole
|
||||
}
|
||||
# avatar # test this as result
|
||||
locationName # test this as result
|
||||
myRole
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const joinGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
|
||||
@ -27,7 +27,7 @@ export default {
|
||||
const variables = { id, name, about, description, groupType, actionRadius, categoryIds }
|
||||
try {
|
||||
await this.$apollo.mutate({
|
||||
mutation: updateGroupMutation,
|
||||
mutation: updateGroupMutation(),
|
||||
variables,
|
||||
})
|
||||
this.$toast.success(this.$t('group.group-updated'))
|
||||
|
||||
@ -237,7 +237,7 @@ export default {
|
||||
followedByCountStartValue: 0,
|
||||
followedByCount: followListVisibleCount,
|
||||
followingCount: followListVisibleCount,
|
||||
updateUserMutation: updateUserMutation(),
|
||||
updateUserMutation,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user