-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from conceptadev/feature/add-org-intivitation
Feature/add org intivitation
- Loading branch information
Showing
52 changed files
with
741 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,12 @@ import { INestApplication } from '@nestjs/common'; | |
import { UserFactory } from '@concepta/nestjs-user/src/seeding'; | ||
import { ConfigService, ConfigType } from '@nestjs/config'; | ||
import { OtpService } from '@concepta/nestjs-otp'; | ||
import { OtpInterface, UserInterface } from '@concepta/ts-common'; | ||
import { | ||
INVITATION_MODULE_CATEGORY_ORG_KEY, | ||
INVITATION_MODULE_CATEGORY_USER_KEY, | ||
OtpInterface, | ||
UserInterface, | ||
} from '@concepta/ts-common'; | ||
import { EmailService } from '@concepta/nestjs-email'; | ||
import { SeedingSource } from '@concepta/typeorm-seeding'; | ||
import { getDataSourceToken } from '@nestjs/typeorm'; | ||
|
@@ -17,19 +22,19 @@ import { invitationDefaultConfig } from '../config/invitation-default.config'; | |
import { InvitationFactory } from '../invitation.factory'; | ||
import { InvitationEntityInterface } from '../interfaces/invitation.entity.interface'; | ||
import { InvitationSettingsInterface } from '../interfaces/invitation-settings.interface'; | ||
|
||
import { AppModuleFixture } from '../__fixtures__/app.module.fixture'; | ||
import { InvitationEntityFixture } from '../__fixtures__/invitation/entities/invitation.entity.fixture'; | ||
import { UserEntityFixture } from '../__fixtures__/user/entities/user-entity.fixture'; | ||
|
||
describe('InvitationController (e2e)', () => { | ||
const category = 'invitation'; | ||
const userCategory = INVITATION_MODULE_CATEGORY_USER_KEY; | ||
const orgCategory = INVITATION_MODULE_CATEGORY_ORG_KEY; | ||
const payload = { moreData: 'foo' }; | ||
|
||
let app: INestApplication; | ||
let invitationFactory: InvitationFactory; | ||
let seedingSource: SeedingSource; | ||
let user: UserEntityFixture; | ||
let invitation: InvitationEntityInterface; | ||
let otpService: OtpService; | ||
let configService: ConfigService; | ||
let config: ConfigType<typeof invitationDefaultConfig>; | ||
|
@@ -62,33 +67,84 @@ describe('InvitationController (e2e)', () => { | |
seedingSource, | ||
}); | ||
|
||
const invitationFactory = new InvitationFactory({ | ||
invitationFactory = new InvitationFactory({ | ||
entity: InvitationEntityFixture, | ||
seedingSource, | ||
}); | ||
|
||
user = await userFactory.create(); | ||
invitation = await invitationFactory.create({ category, user }); | ||
}); | ||
|
||
afterEach(async () => { | ||
jest.clearAllMocks(); | ||
return app ? await app.close() : undefined; | ||
}); | ||
|
||
describe('Type: org', () => { | ||
let invitation: InvitationEntityInterface; | ||
|
||
beforeEach(async () => { | ||
invitation = await invitationFactory.create({ | ||
category: orgCategory, | ||
user, | ||
}); | ||
}); | ||
|
||
it('POST invitation', async () => { | ||
await createInvite(app, { | ||
email: user.email, | ||
category: orgCategory, | ||
payload, | ||
}); | ||
}); | ||
|
||
it('PATCH invitation-acceptance', async () => { | ||
const { code } = invitation; | ||
|
||
const otp = await createOtp(config, otpService, user, orgCategory); | ||
|
||
const { passcode } = otp; | ||
|
||
await supertest(app.getHttpServer()) | ||
.patch(`/invitation-acceptance/${code}`) | ||
.send({ | ||
passcode, | ||
payload: { newPassword: 'hOdv2A2h%' }, | ||
} as InvitationAcceptInviteDto) | ||
.expect(200); | ||
}); | ||
}); | ||
|
||
describe('Type: user', () => { | ||
let invitation: InvitationEntityInterface; | ||
|
||
beforeEach(async () => { | ||
invitation = await invitationFactory.create({ | ||
category: userCategory, | ||
user, | ||
}); | ||
}); | ||
|
||
it('POST invitation', async () => { | ||
await createInvite({ email: user.email, category, payload }); | ||
await createInvite(app, { | ||
email: user.email, | ||
category: userCategory, | ||
payload, | ||
}); | ||
}); | ||
|
||
it('POST invitation (create new user)', async () => { | ||
await createInvite({ email: '[email protected]', category, payload }); | ||
await createInvite(app, { | ||
email: '[email protected]', | ||
category: userCategory, | ||
payload, | ||
}); | ||
}); | ||
|
||
it('POST invitation reattempt', async () => { | ||
const invitationDto = await createInvite({ | ||
const invitationDto = await createInvite(app, { | ||
email: '[email protected]', | ||
category, | ||
category: userCategory, | ||
payload, | ||
}); | ||
|
||
|
@@ -100,7 +156,7 @@ describe('InvitationController (e2e)', () => { | |
it('PATCH invitation-acceptance', async () => { | ||
const { code } = invitation; | ||
|
||
const otp = await createOtp(config, otpService, user, category); | ||
const otp = await createOtp(config, otpService, user, userCategory); | ||
|
||
const { passcode } = otp; | ||
|
||
|
@@ -116,7 +172,7 @@ describe('InvitationController (e2e)', () => { | |
it('GET invitation-acceptance', async () => { | ||
const { code } = invitation; | ||
|
||
const otp = await createOtp(config, otpService, user, category); | ||
const otp = await createOtp(config, otpService, user, userCategory); | ||
|
||
const { passcode } = otp; | ||
|
||
|
@@ -128,12 +184,12 @@ describe('InvitationController (e2e)', () => { | |
it('GET invitation', async () => { | ||
const invitationCreateDto = { | ||
email: user.email, | ||
category, | ||
category: userCategory, | ||
payload, | ||
} as InvitationCreateDto; | ||
const invite1 = await createInvite(invitationCreateDto); | ||
const invite2 = await createInvite(invitationCreateDto); | ||
const invite3 = await createInvite(invitationCreateDto); | ||
const invite1 = await createInvite(app, invitationCreateDto); | ||
const invite2 = await createInvite(app, invitationCreateDto); | ||
const invite3 = await createInvite(app, invitationCreateDto); | ||
|
||
const response = await supertest(app.getHttpServer()) | ||
.get(`/invitation?s={"email": "${invitationCreateDto.email}"}`) | ||
|
@@ -149,9 +205,9 @@ describe('InvitationController (e2e)', () => { | |
}); | ||
|
||
it('GET invitation/:id', async () => { | ||
const invitation = await createInvite({ | ||
const invitation = await createInvite(app, { | ||
email: user.email, | ||
category, | ||
category: userCategory, | ||
payload, | ||
}); | ||
|
||
|
@@ -165,9 +221,9 @@ describe('InvitationController (e2e)', () => { | |
}); | ||
|
||
it('DELETE invitation/:id', async () => { | ||
const invitation = await createInvite({ | ||
const invitation = await createInvite(app, { | ||
email: user.email, | ||
category, | ||
category: userCategory, | ||
payload, | ||
}); | ||
|
||
|
@@ -179,20 +235,21 @@ describe('InvitationController (e2e)', () => { | |
.get(`/invitation/${invitation.id}`) | ||
.expect(404); | ||
}); | ||
|
||
const createInvite = async ( | ||
invitationCreateDto: InvitationCreateDto, | ||
): Promise<InvitationDto> => { | ||
const response = await supertest(app.getHttpServer()) | ||
.post('/invitation') | ||
.send(invitationCreateDto) | ||
.expect(201); | ||
|
||
return response.body as InvitationDto; | ||
}; | ||
}); | ||
}); | ||
|
||
const createInvite = async ( | ||
app: INestApplication, | ||
invitationCreateDto: InvitationCreateDto, | ||
): Promise<InvitationDto> => { | ||
const response = await supertest(app.getHttpServer()) | ||
.post('/invitation') | ||
.send(invitationCreateDto) | ||
.expect(201); | ||
|
||
return response.body as InvitationDto; | ||
}; | ||
|
||
const createOtp = async ( | ||
config: ConfigType<typeof invitationDefaultConfig>, | ||
otpService: OtpService, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.