|
| 1 | +import { bootstrap } from "@/app"; |
| 2 | +import { AppModule } from "@/app.module"; |
| 3 | +import { PrismaModule } from "@/modules/prisma/prisma.module"; |
| 4 | +import { TokensModule } from "@/modules/tokens/tokens.module"; |
| 5 | +import { UsersModule } from "@/modules/users/users.module"; |
| 6 | +import { INestApplication } from "@nestjs/common"; |
| 7 | +import { NestExpressApplication } from "@nestjs/platform-express"; |
| 8 | +import { Test } from "@nestjs/testing"; |
| 9 | +import { User } from "@prisma/client"; |
| 10 | +import * as request from "supertest"; |
| 11 | +import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.fixture"; |
| 12 | +import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture"; |
| 13 | +import { withApiAuth } from "test/utils/withApiAuth"; |
| 14 | + |
| 15 | +import { SUCCESS_STATUS } from "@calcom/platform-constants"; |
| 16 | +import { ApiSuccessResponse } from "@calcom/platform-types"; |
| 17 | +import { Team } from "@calcom/prisma/client"; |
| 18 | + |
| 19 | +describe("Organizations Team Endpoints", () => { |
| 20 | + describe("User Authentication", () => { |
| 21 | + let app: INestApplication; |
| 22 | + |
| 23 | + let userRepositoryFixture: UserRepositoryFixture; |
| 24 | + let organizationsRepositoryFixture: TeamRepositoryFixture; |
| 25 | + let org: Team; |
| 26 | + |
| 27 | + const userEmail = "org-teams-controller-e2e@api.com"; |
| 28 | + let user: User; |
| 29 | + |
| 30 | + beforeAll(async () => { |
| 31 | + const moduleRef = await withApiAuth( |
| 32 | + userEmail, |
| 33 | + Test.createTestingModule({ |
| 34 | + imports: [AppModule, PrismaModule, UsersModule, TokensModule], |
| 35 | + }) |
| 36 | + ).compile(); |
| 37 | + |
| 38 | + userRepositoryFixture = new UserRepositoryFixture(moduleRef); |
| 39 | + organizationsRepositoryFixture = new TeamRepositoryFixture(moduleRef); |
| 40 | + |
| 41 | + user = await userRepositoryFixture.create({ |
| 42 | + email: userEmail, |
| 43 | + username: userEmail, |
| 44 | + }); |
| 45 | + |
| 46 | + org = await organizationsRepositoryFixture.create({ |
| 47 | + name: "Test Organization", |
| 48 | + isOrganization: true, |
| 49 | + }); |
| 50 | + |
| 51 | + app = moduleRef.createNestApplication(); |
| 52 | + bootstrap(app as NestExpressApplication); |
| 53 | + |
| 54 | + await app.init(); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should be defined", () => { |
| 58 | + expect(userRepositoryFixture).toBeDefined(); |
| 59 | + expect(organizationsRepositoryFixture).toBeDefined(); |
| 60 | + expect(user).toBeDefined(); |
| 61 | + expect(org).toBeDefined(); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should get all the teams of the org", async () => { |
| 65 | + return request(app.getHttpServer()) |
| 66 | + .get(`/v2/organizations/${org.id}/teams`) |
| 67 | + .expect(200) |
| 68 | + .then((response) => { |
| 69 | + const responseBody: ApiSuccessResponse<Team[]> = response.body; |
| 70 | + expect(responseBody.status).toEqual(SUCCESS_STATUS); |
| 71 | + expect(responseBody.data).toEqual([]); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + afterAll(async () => { |
| 76 | + await userRepositoryFixture.deleteByEmail(user.email); |
| 77 | + await organizationsRepositoryFixture.delete(org.id); |
| 78 | + await app.close(); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments