mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
inviteCodes: tests are working as expected, fixed factory
This commit is contained in:
parent
f20e17dcc1
commit
c6ff0723ee
@ -206,7 +206,7 @@ const emailDefaults = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Factory.define('emailAddress')
|
Factory.define('emailAddress')
|
||||||
.attr(emailDefaults)
|
.attrs(emailDefaults)
|
||||||
.after((buildObject, options) => {
|
.after((buildObject, options) => {
|
||||||
return neode.create('EmailAddress', buildObject)
|
return neode.create('EmailAddress', buildObject)
|
||||||
})
|
})
|
||||||
@ -218,13 +218,13 @@ Factory.define('unverifiedEmailAddress')
|
|||||||
})
|
})
|
||||||
|
|
||||||
const inviteCodeDefaults = {
|
const inviteCodeDefaults = {
|
||||||
code: generateInvieCode(),
|
code: () => generateInvieCode(),
|
||||||
createdAt: () => new Date().toISOString(),
|
createdAt: () => new Date().toISOString(),
|
||||||
expiresAt: () => null,
|
expiresAt: () => null,
|
||||||
}
|
}
|
||||||
|
|
||||||
Factory.define('inviteCode')
|
Factory.define('inviteCode')
|
||||||
.attr(inviteCodeDefaults)
|
.attrs(inviteCodeDefaults)
|
||||||
.option('generatedById', null)
|
.option('generatedById', null)
|
||||||
.option('generatedBy', ['generatedById'], (generatedById) => {
|
.option('generatedBy', ['generatedById'], (generatedById) => {
|
||||||
if (generatedById) return neode.find('User', generatedById)
|
if (generatedById) return neode.find('User', generatedById)
|
||||||
|
|||||||
@ -147,7 +147,7 @@ describe('inviteCodes', () => {
|
|||||||
expect(inviteCodes).toHaveLength(2)
|
expect(inviteCodes).toHaveLength(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not returns the created invite codes of other users when queried', async () => {
|
it('does not return the created invite codes of other users when queried', async () => {
|
||||||
await Factory.build('inviteCode')
|
await Factory.build('inviteCode')
|
||||||
const response = await query({ query: myInviteCodesQuery })
|
const response = await query({ query: myInviteCodesQuery })
|
||||||
inviteCodes = response.data.MyInviteCodes
|
inviteCodes = response.data.MyInviteCodes
|
||||||
@ -156,27 +156,36 @@ describe('inviteCodes', () => {
|
|||||||
|
|
||||||
it('validates an invite code without expiresAt', async () => {
|
it('validates an invite code without expiresAt', async () => {
|
||||||
const unExpiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt === null)[0].code
|
const unExpiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt === null)[0].code
|
||||||
expect(
|
const result = await query({
|
||||||
query({ query: isValidInviteCodeQuery, variables: { code: unExpiringInviteCode } }),
|
query: isValidInviteCodeQuery,
|
||||||
).resolves.toBeTruthy()
|
variables: { code: unExpiringInviteCode },
|
||||||
|
})
|
||||||
|
expect(result.data.isValidInviteCode).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('validates an invite code with expiresAt in the future', async () => {
|
it('validates an invite code with expiresAt in the future', async () => {
|
||||||
const expiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt !== null)[0].code
|
const expiringInviteCode = inviteCodes.filter((ic) => ic.expiresAt !== null)[0].code
|
||||||
expect(
|
const result = await query({
|
||||||
query({ query: isValidInviteCodeQuery, variables: { code: expiringInviteCode } }),
|
query: isValidInviteCodeQuery,
|
||||||
).resolves.toBeTruthy()
|
variables: { code: expiringInviteCode },
|
||||||
|
})
|
||||||
|
expect(result.data.isValidInviteCode).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it.skip('does not validate an invite code which expired in the past', async () => {
|
it('does not validate an invite code which expired in the past', async () => {
|
||||||
const lastWeek = new Date()
|
const lastWeek = new Date()
|
||||||
lastWeek.setDate(lastWeek.getDate() - 7)
|
lastWeek.setDate(lastWeek.getDate() - 7)
|
||||||
const code = await Factory.build('inviteCode', {
|
const inviteCode = await Factory.build('inviteCode', {
|
||||||
expiresAt: lastWeek.toISOString(),
|
expiresAt: lastWeek.toISOString(),
|
||||||
})
|
})
|
||||||
expect(
|
const code = inviteCode.get('code')
|
||||||
query({ query: isValidInviteCodeQuery, variables: { code: code.code } }),
|
const result = await query({ query: isValidInviteCodeQuery, variables: { code } })
|
||||||
).resolves.toBeFalsy()
|
expect(result.data.isValidInviteCode).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not validate an invite code which does not exits', async () => {
|
||||||
|
const result = await query({ query: isValidInviteCodeQuery, variables: { code: 'AAA' } })
|
||||||
|
expect(result.data.isValidInviteCode).toBeFalsy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user