mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
fix(backend): invite codes - hotfix 1 (#8508)
* hotfix invite codes * fix tests & ensure correct behaviour
This commit is contained in:
parent
fbec8288b2
commit
989d5ff781
@ -31,6 +31,10 @@ export const Group = gql`
|
||||
nameEN
|
||||
}
|
||||
myRole
|
||||
inviteCodes {
|
||||
code
|
||||
redeemedByCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@ -1027,12 +1027,12 @@ describe('redeemInviteCode', () => {
|
||||
data: {
|
||||
currentUser: {
|
||||
following: [],
|
||||
inviteCodes: expect.arrayContaining([
|
||||
inviteCodes: [
|
||||
{
|
||||
code: 'CODE33',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
@ -1061,20 +1061,18 @@ describe('redeemInviteCode', () => {
|
||||
errors: undefined,
|
||||
})
|
||||
authenticatedUser = await invitingUser.toJson()
|
||||
await expect(query({ query: currentUser })).resolves.toMatchObject({
|
||||
await expect(query({ query: Group })).resolves.toMatchObject({
|
||||
data: {
|
||||
currentUser: {
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPPBL',
|
||||
redeemedByCount: 1,
|
||||
},
|
||||
{
|
||||
code: 'GRPHDN',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
]),
|
||||
},
|
||||
Group: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPPBL',
|
||||
redeemedByCount: 1,
|
||||
},
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
@ -1111,20 +1109,18 @@ describe('redeemInviteCode', () => {
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
await expect(query({ query: currentUser })).resolves.toMatchObject({
|
||||
await expect(query({ query: Group })).resolves.toMatchObject({
|
||||
data: {
|
||||
currentUser: {
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPPBL',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
{
|
||||
code: 'GRPHDN',
|
||||
redeemedByCount: 1,
|
||||
},
|
||||
]),
|
||||
},
|
||||
Group: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPHDN',
|
||||
redeemedByCount: 1,
|
||||
},
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
@ -1149,12 +1145,12 @@ describe('redeemInviteCode', () => {
|
||||
data: {
|
||||
currentUser: {
|
||||
following: [],
|
||||
inviteCodes: expect.arrayContaining([
|
||||
inviteCodes: [
|
||||
{
|
||||
code: 'CODE33',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
@ -1182,21 +1178,18 @@ describe('redeemInviteCode', () => {
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
await expect(query({ query: currentUser })).resolves.toMatchObject({
|
||||
await expect(query({ query: Group })).resolves.toMatchObject({
|
||||
data: {
|
||||
currentUser: {
|
||||
following: [],
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPPBL',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
{
|
||||
code: 'GRPHDN',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
]),
|
||||
},
|
||||
Group: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
inviteCodes: expect.arrayContaining([
|
||||
{
|
||||
code: 'GRPPBL',
|
||||
redeemedByCount: 0,
|
||||
},
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
|
||||
@ -151,7 +151,7 @@ export default {
|
||||
await context.database.query({
|
||||
query: `
|
||||
MATCH (inviteCode:InviteCode)<-[:GENERATED]-(user:User {id: $user.id})
|
||||
WHERE NOT (inviteCode)-[:INVITES_TO]-(:Group)
|
||||
WHERE NOT (inviteCode)-[:INVITES_TO]->(:Group)
|
||||
AND (inviteCode.expiresAt IS NULL OR inviteCode.expiresAt >= datetime())
|
||||
RETURN toString(count(inviteCode)) as count
|
||||
`,
|
||||
|
||||
@ -469,21 +469,17 @@ export default {
|
||||
},
|
||||
User: {
|
||||
inviteCodes: async (_parent, _args, context: Context, _resolveInfo) => {
|
||||
const {
|
||||
user: { id: userId },
|
||||
} = context
|
||||
|
||||
return (
|
||||
await context.database.query({
|
||||
query: `
|
||||
MATCH (user:User {id: $userId})-[:GENERATED]->(inviteCodes:InviteCode)
|
||||
MATCH (user:User {id: $user.id})-[:GENERATED]->(inviteCodes:InviteCode)
|
||||
WHERE NOT (inviteCodes)-[:INVITES_TO]->(:Group)
|
||||
RETURN inviteCodes {.*}
|
||||
ORDER BY inviteCodes.createdAt ASC
|
||||
`,
|
||||
variables: { userId },
|
||||
variables: { user: context.user },
|
||||
})
|
||||
).records
|
||||
).records.map((record) => record.get('inviteCodes'))
|
||||
},
|
||||
emailNotificationSettings: async (parent, _params, _context, _resolveInfo) => {
|
||||
return [
|
||||
@ -686,7 +682,6 @@ export default {
|
||||
shouted: '-[:SHOUTED]->(related:Post)',
|
||||
categories: '-[:CATEGORIZED]->(related:Category)',
|
||||
badgeTrophies: '<-[:REWARDED]-(related:Badge)',
|
||||
inviteCodes: '-[:GENERATED]->(related:InviteCode)',
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user