mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactor 'joinGroupMutation' to a function that returns GQL
This commit is contained in:
parent
6df10e5588
commit
1c040e1549
@ -109,16 +109,18 @@ export const updateGroupMutation = () => {
|
||||
`
|
||||
}
|
||||
|
||||
export const joinGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
myRoleInGroup
|
||||
export const joinGroupMutation = () => {
|
||||
return gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
myRoleInGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const leaveGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
|
||||
@ -320,21 +320,21 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
])
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g0',
|
||||
userId: 'u2',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g0',
|
||||
userId: 'u4',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g0',
|
||||
userId: 'u6',
|
||||
@ -378,35 +378,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
])
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g1',
|
||||
userId: 'u1',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g1',
|
||||
userId: 'u2',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g1',
|
||||
userId: 'u5',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g1',
|
||||
userId: 'u6',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g1',
|
||||
userId: 'u7',
|
||||
@ -457,35 +457,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
])
|
||||
await Promise.all([
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g2',
|
||||
userId: 'u3',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g2',
|
||||
userId: 'u4',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g2',
|
||||
userId: 'u5',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g2',
|
||||
userId: 'u6',
|
||||
},
|
||||
}),
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'g2',
|
||||
userId: 'u7',
|
||||
|
||||
@ -168,14 +168,14 @@ const seedComplexScenarioAndClearAuthentication = async () => {
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'owner-of-closed-group',
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'owner-of-hidden-group',
|
||||
@ -815,7 +815,7 @@ describe('in mode', () => {
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'not-existing-group',
|
||||
userId: 'current-user',
|
||||
@ -901,7 +901,7 @@ describe('in mode', () => {
|
||||
it('has "usual" as membership role', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'owner-of-closed-group',
|
||||
@ -924,7 +924,7 @@ describe('in mode', () => {
|
||||
it('has still "owner" as membership role', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'current-user',
|
||||
@ -949,7 +949,7 @@ describe('in mode', () => {
|
||||
it('has "pending" as membership role', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: 'current-user',
|
||||
@ -972,7 +972,7 @@ describe('in mode', () => {
|
||||
it('has still "owner" as membership role', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: 'owner-of-closed-group',
|
||||
@ -996,7 +996,7 @@ describe('in mode', () => {
|
||||
describe('joined by "owner-of-closed-group"', () => {
|
||||
it('throws authorization error', async () => {
|
||||
const { errors } = await query({
|
||||
query: joinGroupMutation,
|
||||
query: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'hidden-group',
|
||||
userId: 'owner-of-closed-group',
|
||||
@ -1011,7 +1011,7 @@ describe('in mode', () => {
|
||||
it('has still "owner" as membership role', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'hidden-group',
|
||||
userId: 'owner-of-hidden-group',
|
||||
@ -1120,14 +1120,14 @@ describe('in mode', () => {
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'owner-of-closed-group',
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'public-group',
|
||||
userId: 'owner-of-hidden-group',
|
||||
@ -1148,7 +1148,7 @@ describe('in mode', () => {
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
mutation: joinGroupMutation,
|
||||
mutation: joinGroupMutation(),
|
||||
variables: {
|
||||
groupId: 'closed-group',
|
||||
userId: 'current-user',
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -100,16 +100,18 @@ export const updateGroupMutation = () => {
|
||||
`
|
||||
}
|
||||
|
||||
export const joinGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
myRoleInGroup
|
||||
export const joinGroupMutation = () => {
|
||||
return gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
myRoleInGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
export const leaveGroupMutation = gql`
|
||||
mutation ($groupId: ID!, $userId: ID!) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user