Refactor 'leaveGroupMutation' to a function that returns GQL

This commit is contained in:
Wolfgang Huß 2022-09-18 17:15:29 +02:00
parent 1c040e1549
commit 14824c8b33
4 changed files with 32 additions and 28 deletions

View File

@ -122,16 +122,18 @@ export const joinGroupMutation = () => {
`
}
export const leaveGroupMutation = gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
export const leaveGroupMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
}
`
`
}
export const changeGroupMemberRoleMutation = gql`
mutation ($groupId: ID!, $userId: ID!, $roleInGroup: GroupMemberRole!) {

View File

@ -2411,7 +2411,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
groupId: 'not-existing-group',
userId: 'current-user',
@ -2450,7 +2450,7 @@ describe('in mode', () => {
authenticatedUser = await pendingMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'pending-member-user',
@ -2477,7 +2477,7 @@ describe('in mode', () => {
authenticatedUser = await usualMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'usual-member-user',
@ -2504,7 +2504,7 @@ describe('in mode', () => {
authenticatedUser = await adminMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'admin-member-user',
@ -2528,7 +2528,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await ownerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'owner-member-user',
@ -2542,7 +2542,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await secondOwnerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'second-owner-member-user',
@ -2556,7 +2556,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await noMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'none-member-user',
@ -2570,7 +2570,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await ownerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'usual-member-user',
@ -2584,7 +2584,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await usualMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation,
mutation: leaveGroupMutation(),
variables: {
...variables,
userId: 'admin-member-user',

View File

@ -108,7 +108,7 @@ export default {
},
async joinLeave() {
const join = !this.isMember
const mutation = join ? joinGroupMutation() : leaveGroupMutation
const mutation = join ? joinGroupMutation() : leaveGroupMutation()
this.hovered = false
this.$emit('prepare', join)

View File

@ -113,16 +113,18 @@ export const joinGroupMutation = () => {
`
}
export const leaveGroupMutation = gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
export const leaveGroupMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
}
`
`
}
export const changeGroupMemberRoleMutation = gql`
mutation ($groupId: ID!, $userId: ID!, $roleInGroup: GroupMemberRole!) {