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,7 +109,8 @@ export const updateGroupMutation = () => {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const joinGroupMutation = gql`
|
export const joinGroupMutation = () => {
|
||||||
|
return gql`
|
||||||
mutation ($groupId: ID!, $userId: ID!) {
|
mutation ($groupId: ID!, $userId: ID!) {
|
||||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||||
id
|
id
|
||||||
@ -118,7 +119,8 @@ export const joinGroupMutation = gql`
|
|||||||
myRoleInGroup
|
myRoleInGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
}
|
||||||
|
|
||||||
export const leaveGroupMutation = gql`
|
export const leaveGroupMutation = gql`
|
||||||
mutation ($groupId: ID!, $userId: ID!) {
|
mutation ($groupId: ID!, $userId: ID!) {
|
||||||
|
|||||||
@ -320,21 +320,21 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
])
|
])
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g0',
|
groupId: 'g0',
|
||||||
userId: 'u2',
|
userId: 'u2',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g0',
|
groupId: 'g0',
|
||||||
userId: 'u4',
|
userId: 'u4',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g0',
|
groupId: 'g0',
|
||||||
userId: 'u6',
|
userId: 'u6',
|
||||||
@ -378,35 +378,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
])
|
])
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g1',
|
groupId: 'g1',
|
||||||
userId: 'u1',
|
userId: 'u1',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g1',
|
groupId: 'g1',
|
||||||
userId: 'u2',
|
userId: 'u2',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g1',
|
groupId: 'g1',
|
||||||
userId: 'u5',
|
userId: 'u5',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g1',
|
groupId: 'g1',
|
||||||
userId: 'u6',
|
userId: 'u6',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g1',
|
groupId: 'g1',
|
||||||
userId: 'u7',
|
userId: 'u7',
|
||||||
@ -457,35 +457,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
])
|
])
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g2',
|
groupId: 'g2',
|
||||||
userId: 'u3',
|
userId: 'u3',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g2',
|
groupId: 'g2',
|
||||||
userId: 'u4',
|
userId: 'u4',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g2',
|
groupId: 'g2',
|
||||||
userId: 'u5',
|
userId: 'u5',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g2',
|
groupId: 'g2',
|
||||||
userId: 'u6',
|
userId: 'u6',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'g2',
|
groupId: 'g2',
|
||||||
userId: 'u7',
|
userId: 'u7',
|
||||||
|
|||||||
@ -168,14 +168,14 @@ const seedComplexScenarioAndClearAuthentication = async () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'owner-of-closed-group',
|
userId: 'owner-of-closed-group',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'owner-of-hidden-group',
|
userId: 'owner-of-hidden-group',
|
||||||
@ -815,7 +815,7 @@ describe('in mode', () => {
|
|||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
const { errors } = await mutate({
|
const { errors } = await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'not-existing-group',
|
groupId: 'not-existing-group',
|
||||||
userId: 'current-user',
|
userId: 'current-user',
|
||||||
@ -901,7 +901,7 @@ describe('in mode', () => {
|
|||||||
it('has "usual" as membership role', async () => {
|
it('has "usual" as membership role', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'owner-of-closed-group',
|
userId: 'owner-of-closed-group',
|
||||||
@ -924,7 +924,7 @@ describe('in mode', () => {
|
|||||||
it('has still "owner" as membership role', async () => {
|
it('has still "owner" as membership role', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'current-user',
|
userId: 'current-user',
|
||||||
@ -949,7 +949,7 @@ describe('in mode', () => {
|
|||||||
it('has "pending" as membership role', async () => {
|
it('has "pending" as membership role', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'closed-group',
|
groupId: 'closed-group',
|
||||||
userId: 'current-user',
|
userId: 'current-user',
|
||||||
@ -972,7 +972,7 @@ describe('in mode', () => {
|
|||||||
it('has still "owner" as membership role', async () => {
|
it('has still "owner" as membership role', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'closed-group',
|
groupId: 'closed-group',
|
||||||
userId: 'owner-of-closed-group',
|
userId: 'owner-of-closed-group',
|
||||||
@ -996,7 +996,7 @@ describe('in mode', () => {
|
|||||||
describe('joined by "owner-of-closed-group"', () => {
|
describe('joined by "owner-of-closed-group"', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
const { errors } = await query({
|
const { errors } = await query({
|
||||||
query: joinGroupMutation,
|
query: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'hidden-group',
|
groupId: 'hidden-group',
|
||||||
userId: 'owner-of-closed-group',
|
userId: 'owner-of-closed-group',
|
||||||
@ -1011,7 +1011,7 @@ describe('in mode', () => {
|
|||||||
it('has still "owner" as membership role', async () => {
|
it('has still "owner" as membership role', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'hidden-group',
|
groupId: 'hidden-group',
|
||||||
userId: 'owner-of-hidden-group',
|
userId: 'owner-of-hidden-group',
|
||||||
@ -1120,14 +1120,14 @@ describe('in mode', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'owner-of-closed-group',
|
userId: 'owner-of-closed-group',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'public-group',
|
groupId: 'public-group',
|
||||||
userId: 'owner-of-hidden-group',
|
userId: 'owner-of-hidden-group',
|
||||||
@ -1148,7 +1148,7 @@ describe('in mode', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: joinGroupMutation,
|
mutation: joinGroupMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
groupId: 'closed-group',
|
groupId: 'closed-group',
|
||||||
userId: 'current-user',
|
userId: 'current-user',
|
||||||
|
|||||||
@ -108,7 +108,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async joinLeave() {
|
async joinLeave() {
|
||||||
const join = !this.isMember
|
const join = !this.isMember
|
||||||
const mutation = join ? joinGroupMutation : leaveGroupMutation
|
const mutation = join ? joinGroupMutation() : leaveGroupMutation
|
||||||
|
|
||||||
this.hovered = false
|
this.hovered = false
|
||||||
this.$emit('prepare', join)
|
this.$emit('prepare', join)
|
||||||
|
|||||||
@ -100,7 +100,8 @@ export const updateGroupMutation = () => {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const joinGroupMutation = gql`
|
export const joinGroupMutation = () => {
|
||||||
|
return gql`
|
||||||
mutation ($groupId: ID!, $userId: ID!) {
|
mutation ($groupId: ID!, $userId: ID!) {
|
||||||
JoinGroup(groupId: $groupId, userId: $userId) {
|
JoinGroup(groupId: $groupId, userId: $userId) {
|
||||||
id
|
id
|
||||||
@ -109,7 +110,8 @@ export const joinGroupMutation = gql`
|
|||||||
myRoleInGroup
|
myRoleInGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
}
|
||||||
|
|
||||||
export const leaveGroupMutation = gql`
|
export const leaveGroupMutation = gql`
|
||||||
mutation ($groupId: ID!, $userId: ID!) {
|
mutation ($groupId: ID!, $userId: ID!) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user