fix(backend): invite codes - hotfix 1 (#8508)

* hotfix invite codes

* fix tests & ensure correct behaviour
This commit is contained in:
Ulf Gebhardt 2025-05-09 00:57:55 +02:00 committed by GitHub
parent fbec8288b2
commit 989d5ff781
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 53 deletions

View File

@ -31,6 +31,10 @@ export const Group = gql`
nameEN nameEN
} }
myRole myRole
inviteCodes {
code
redeemedByCount
}
} }
} }
` `

View File

@ -1027,12 +1027,12 @@ describe('redeemInviteCode', () => {
data: { data: {
currentUser: { currentUser: {
following: [], following: [],
inviteCodes: expect.arrayContaining([ inviteCodes: [
{ {
code: 'CODE33', code: 'CODE33',
redeemedByCount: 0, redeemedByCount: 0,
}, },
]), ],
}, },
}, },
errors: undefined, errors: undefined,
@ -1061,20 +1061,18 @@ describe('redeemInviteCode', () => {
errors: undefined, errors: undefined,
}) })
authenticatedUser = await invitingUser.toJson() authenticatedUser = await invitingUser.toJson()
await expect(query({ query: currentUser })).resolves.toMatchObject({ await expect(query({ query: Group })).resolves.toMatchObject({
data: { data: {
currentUser: { Group: expect.arrayContaining([
expect.objectContaining({
inviteCodes: expect.arrayContaining([ inviteCodes: expect.arrayContaining([
{ {
code: 'GRPPBL', code: 'GRPPBL',
redeemedByCount: 1, redeemedByCount: 1,
}, },
{
code: 'GRPHDN',
redeemedByCount: 0,
},
]), ]),
}, }),
]),
}, },
errors: undefined, errors: undefined,
}) })
@ -1111,20 +1109,18 @@ describe('redeemInviteCode', () => {
}, },
errors: undefined, errors: undefined,
}) })
await expect(query({ query: currentUser })).resolves.toMatchObject({ await expect(query({ query: Group })).resolves.toMatchObject({
data: { data: {
currentUser: { Group: expect.arrayContaining([
expect.objectContaining({
inviteCodes: expect.arrayContaining([ inviteCodes: expect.arrayContaining([
{
code: 'GRPPBL',
redeemedByCount: 0,
},
{ {
code: 'GRPHDN', code: 'GRPHDN',
redeemedByCount: 1, redeemedByCount: 1,
}, },
]), ]),
}, }),
]),
}, },
errors: undefined, errors: undefined,
}) })
@ -1149,12 +1145,12 @@ describe('redeemInviteCode', () => {
data: { data: {
currentUser: { currentUser: {
following: [], following: [],
inviteCodes: expect.arrayContaining([ inviteCodes: [
{ {
code: 'CODE33', code: 'CODE33',
redeemedByCount: 0, redeemedByCount: 0,
}, },
]), ],
}, },
}, },
errors: undefined, errors: undefined,
@ -1182,21 +1178,18 @@ describe('redeemInviteCode', () => {
}, },
errors: undefined, errors: undefined,
}) })
await expect(query({ query: currentUser })).resolves.toMatchObject({ await expect(query({ query: Group })).resolves.toMatchObject({
data: { data: {
currentUser: { Group: expect.arrayContaining([
following: [], expect.objectContaining({
inviteCodes: expect.arrayContaining([ inviteCodes: expect.arrayContaining([
{ {
code: 'GRPPBL', code: 'GRPPBL',
redeemedByCount: 0, redeemedByCount: 0,
}, },
{
code: 'GRPHDN',
redeemedByCount: 0,
},
]), ]),
}, }),
]),
}, },
errors: undefined, errors: undefined,
}) })

View File

@ -151,7 +151,7 @@ export default {
await context.database.query({ await context.database.query({
query: ` query: `
MATCH (inviteCode:InviteCode)<-[:GENERATED]-(user:User {id: $user.id}) 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()) AND (inviteCode.expiresAt IS NULL OR inviteCode.expiresAt >= datetime())
RETURN toString(count(inviteCode)) as count RETURN toString(count(inviteCode)) as count
`, `,

View File

@ -469,21 +469,17 @@ export default {
}, },
User: { User: {
inviteCodes: async (_parent, _args, context: Context, _resolveInfo) => { inviteCodes: async (_parent, _args, context: Context, _resolveInfo) => {
const {
user: { id: userId },
} = context
return ( return (
await context.database.query({ await context.database.query({
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) WHERE NOT (inviteCodes)-[:INVITES_TO]->(:Group)
RETURN inviteCodes {.*} RETURN inviteCodes {.*}
ORDER BY inviteCodes.createdAt ASC ORDER BY inviteCodes.createdAt ASC
`, `,
variables: { userId }, variables: { user: context.user },
}) })
).records ).records.map((record) => record.get('inviteCodes'))
}, },
emailNotificationSettings: async (parent, _params, _context, _resolveInfo) => { emailNotificationSettings: async (parent, _params, _context, _resolveInfo) => {
return [ return [
@ -686,7 +682,6 @@ export default {
shouted: '-[:SHOUTED]->(related:Post)', shouted: '-[:SHOUTED]->(related:Post)',
categories: '-[:CATEGORIZED]->(related:Category)', categories: '-[:CATEGORIZED]->(related:Category)',
badgeTrophies: '<-[:REWARDED]-(related:Badge)', badgeTrophies: '<-[:REWARDED]-(related:Badge)',
inviteCodes: '-[:GENERATED]->(related:InviteCode)',
}, },
}), }),
}, },