mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
inviteCodes: explaination added, test for lower case
This commit is contained in:
parent
c6ff0723ee
commit
a98170487b
@ -1,5 +1,8 @@
|
||||
export default function generateInviteCode() {
|
||||
// 6 random numbers in [ 0, 35 ] are 36 possible numbers (10 [0-9] + 26 [A-Z])
|
||||
return Array.from({ length: 6 }, (n = Math.floor(Math.random() * 36)) => {
|
||||
// n > 9: it is a letter (ASCII 65 is A) -> 10 + 55 = 65
|
||||
// else: it is a number (ASCII 48 is 0) -> 0 + 48 = 48
|
||||
return String.fromCharCode(n > 9 ? n + 55 : n + 48)
|
||||
}).join('')
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ export default {
|
||||
const session = context.driver.session()
|
||||
const readTxResultPromise = session.readTransaction(async (txc) => {
|
||||
const result = await txc.run(
|
||||
`MATCH (ic:InviteCode { code: $code })
|
||||
`MATCH (ic:InviteCode { code: toUpper($code) })
|
||||
RETURN
|
||||
CASE
|
||||
WHEN ic.expiresAt IS NULL THEN true
|
||||
|
||||
@ -163,6 +163,15 @@ describe('inviteCodes', () => {
|
||||
expect(result.data.isValidInviteCode).toBeTruthy()
|
||||
})
|
||||
|
||||
it('validates an invite code in lower case', async () => {
|
||||
const unExpiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt === null)[0].code
|
||||
const result = await query({
|
||||
query: isValidInviteCodeQuery,
|
||||
variables: { code: unExpiringInviteCode.toLowerCase() },
|
||||
})
|
||||
expect(result.data.isValidInviteCode).toBeTruthy()
|
||||
})
|
||||
|
||||
it('validates an invite code with expiresAt in the future', async () => {
|
||||
const expiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt !== null)[0].code
|
||||
const result = await query({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user