Skip to content

Commit 84301a6

Browse files
authored
Merge pull request #215 from chingu-x/feat-add-absolute-paths-to-units
refactor: added absolute import paths to unit tests
2 parents 2c80c5b + 1fd300c commit 84301a6

File tree

78 files changed

+274
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+274
-239
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ Another example [here](https://co-pilot.dev/changelog)
1818
### Changed
1919

2020
- Update PostgreSQL image to timescale/timescaledb-ha:pg16 to match railway postgres image ([#210](https://github.com/chingu-x/chingu-dashboard-be/pull/210))
21+
- refactored e2e tests to use absolute import paths ([#207](https://github.com/chingu-x/chingu-dashboard-be/pull/207))
2122
- Updated seed data of user voyage roles and added new users([#206](https://github.com/chingu-x/chingu-dashboard-be/pull/206))
2223
- Refactored e2e tests to use absolute import paths ([#207](https://github.com/chingu-x/chingu-dashboard-be/pull/207))
2324
- Update solo project model ([#213](https://github.com/chingu-x/chingu-dashboard-be/pull/213))
2425
- Update readme to include more instructions for using the test database ([#213](https://github.com/chingu-x/chingu-dashboard-be/pull/213))
26+
- refactored unit tests to use absolute import paths ([#215](https://github.com/chingu-x/chingu-dashboard-be/pull/215))
2527

2628
### Fixed
2729

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,21 @@
113113
"json",
114114
"ts"
115115
],
116-
"rootDir": "src",
117-
"testRegex": ".*\\.spec|.jest\\.ts$",
116+
"moduleDirectories": [
117+
"node_modules",
118+
"src"
119+
],
120+
"rootDir": ".",
121+
"moduleNameMapper": {
122+
"@/(.*)": "<rootDir>/src/$1",
123+
"@Prisma/(.*)": "<rootDir>/prisma/$1"
124+
},
125+
"modulePaths": [
126+
"<rootDir>"
127+
],
128+
"testRegex": [
129+
".*\\.spec|.jest\\.ts$"
130+
],
118131
"transform": {
119132
"^.+\\.(t|j)s$": "ts-jest"
120133
},
@@ -124,11 +137,11 @@
124137
"coverageDirectory": "../coverage",
125138
"testEnvironment": "node",
126139
"setupFilesAfterEnv": [
127-
"<rootDir>/prisma/singleton.ts"
140+
"<rootDir>/src/prisma/singleton.ts"
128141
]
129142
},
130143
"prisma": {
131-
"seed": "ts-node prisma/seed/index.ts"
144+
"seed": "ts-node -r tsconfig-paths/register prisma/seed/index.ts"
132145
},
133146
"lint-staged": {
134147
"src/**/*.ts": [

src/HealthCheck/health-check.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller, Get } from "@nestjs/common";
2-
import { Public } from "../global/decorators/public.decorator";
2+
import { Public } from "@/global/decorators/public.decorator";
33
import { ApiTags } from "@nestjs/swagger";
44

55
@Public()

src/HealthCheck/health-check.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from "@nestjs/common";
2-
import { PrismaService } from "../prisma/prisma.service";
2+
import { PrismaService } from "@/prisma/prisma.service";
33
import { HealthCheckDto } from "./health-check.dto";
44

55
@Injectable()

src/HealthCheck/test/integration/health-check.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from "@nestjs/testing";
2-
import { HealthCheckController } from "../../health-check.controller";
2+
import { HealthCheckController } from "@/HealthCheck/health-check.controller";
33

44
describe("HealthCheckController", () => {
55
let controller: HealthCheckController;

src/HealthCheck/test/integration/health-check.service.int-spec.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
import { Test, TestingModule } from "@nestjs/testing";
2-
import { HealthCheckService } from "src/HealthCheck/health-check.service";
3-
import { PrismaService } from "src/prisma/prisma.service";
2+
import { HealthCheckService } from "@/HealthCheck/health-check.service";
3+
import { PrismaService } from "@/prisma/prisma.service";
4+
import { ConfigService, ConfigModule } from "@nestjs/config";
45

56
describe("HealthCheckService", () => {
67
let healthCheckService: HealthCheckService;
78
let prismaService: PrismaService;
89

910
beforeAll(async () => {
1011
const module: TestingModule = await Test.createTestingModule({
11-
providers: [HealthCheckService, PrismaService],
12+
imports: [ConfigModule.forRoot()],
13+
providers: [
14+
HealthCheckService,
15+
PrismaService,
16+
{
17+
provide: "DB-Config",
18+
useFactory(configService: ConfigService) {
19+
return {
20+
db: {
21+
url: configService.get<string>("DATABASE_URL"),
22+
},
23+
};
24+
},
25+
inject: [ConfigService],
26+
},
27+
],
1228
}).compile();
1329

1430
healthCheckService = module.get<HealthCheckService>(HealthCheckService);
1531
prismaService = module.get<PrismaService>(PrismaService);
1632
});
1733

34+
afterAll(async () => {
35+
await prismaService.healthCheck.deleteMany();
36+
await prismaService.$disconnect();
37+
});
38+
1839
it("should be defined", () => {
1940
expect(healthCheckService).toBeDefined();
2041
});

src/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Module } from "@nestjs/common";
2+
import { ScheduleModule } from "@nestjs/schedule";
3+
import { APP_GUARD, RouterModule } from "@nestjs/core";
24
import { PrismaModule } from "./prisma/prisma.module";
35
import { TeamsModule } from "./teams/teams.module";
46
import { HealthCheckController } from "./HealthCheck/health-check.controller";
@@ -8,13 +10,11 @@ import { SprintsModule } from "./sprints/sprints.module";
810
import { FormsModule } from "./forms/forms.module";
911
import { AuthModule } from "./auth/auth.module";
1012
import { GlobalModule } from "./global/global.module";
11-
import { APP_GUARD, RouterModule } from "@nestjs/core";
1213
import { ResourcesModule } from "./resources/resources.module";
1314
import { TechsModule } from "./techs/techs.module";
1415
import { FeaturesModule } from "./features/features.module";
1516
import { IdeationsModule } from "./ideations/ideations.module";
1617
import { JwtAuthGuard } from "./auth/guards/jwt-auth.guard";
17-
import { ScheduleModule } from "@nestjs/schedule";
1818
import { TasksModule } from "./tasks/tasks.module";
1919
import { VoyagesModule } from "./voyages/voyages.module";
2020
import { AbilityModule } from "./ability/ability.module";

src/auth/auth.controller.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Test, TestingModule } from "@nestjs/testing";
22
import { AuthController } from "./auth.controller";
33
import { AuthService } from "./auth.service";
4-
import { AppConfigService } from "../config/app/appConfig.service";
5-
import { MailConfigService } from "../config/mail/mailConfig.service";
4+
import { AppConfigService } from "@/config/app/appConfig.service";
5+
import { MailConfigService } from "@/config/mail/mailConfig.service";
66
describe("AuthController", () => {
77
let controller: AuthController;
88
let authService: AuthService;

src/auth/auth.controller.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
LoginUnauthorizedErrorResponse,
2525
NotFoundErrorResponse,
2626
UnauthorizedErrorResponse,
27-
} from "../global/responses/errors";
27+
} from "@/global/responses/errors";
2828
import {
2929
LoginResponse,
3030
LogoutResponse,
@@ -35,16 +35,16 @@ import { ResetPasswordRequestDto } from "./dto/reset-password-request.dto";
3535
import { ResetPasswordDto } from "./dto/reset-password.dto";
3636
import { JwtAuthGuard } from "./guards/jwt-auth.guard";
3737
import { JwtRefreshAuthGuard } from "./guards/jwt-rt-auth.guard";
38-
import { Public } from "../global/decorators/public.decorator";
39-
import { Unverified } from "../global/decorators/unverified.decorator";
38+
import { Public } from "@/global/decorators/public.decorator";
39+
import { Unverified } from "@/global/decorators/unverified.decorator";
4040
import { RevokeRTDto } from "./dto/revoke-refresh-token.dto";
41-
import { CheckAbilities } from "../global/decorators/abilities.decorator";
42-
import { Action } from "../ability/ability.factory/ability.factory";
43-
import { CustomRequest } from "../global/types/CustomRequest";
41+
import { CheckAbilities } from "@/global/decorators/abilities.decorator";
42+
import { Action } from "@/ability/ability.factory/ability.factory";
43+
import { CustomRequest } from "@/global/types/CustomRequest";
4444
import { Response } from "express";
4545
import { DiscordAuthGuard } from "./guards/discord-auth.guard";
46-
import { MailConfigService } from "../config/mail/mailConfig.service";
47-
import { AppConfigService } from "../config/app/appConfig.service";
46+
import { MailConfigService } from "@/config/mail/mailConfig.service";
47+
import { AppConfigService } from "@/config/app/appConfig.service";
4848
@ApiTags("Auth")
4949
@Controller("auth")
5050
export class AuthController {

src/auth/auth.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Module } from "@nestjs/common";
22
import { AuthService } from "./auth.service";
3-
import { UsersModule } from "../users/users.module";
3+
import { UsersModule } from "@/users/users.module";
44
import { AuthController } from "./auth.controller";
55
import { PassportModule } from "@nestjs/passport";
66
import { LocalStrategy } from "./strategies/local.strategy";
@@ -13,7 +13,7 @@ import { EmailService } from "../utils/emails/email.service";
1313
import { MailConfigModule } from "@/config/mail/mailConfig.module";
1414
import { AppConfigModule } from "@/config/app/appConfig.module";
1515
import { AuthConfigModule } from "@/config/auth/authConfig.module";
16-
import { OAuthConfigModule } from "../config/Oauth/oauthConfig.module";
16+
import { OAuthConfigModule } from "@/config/Oauth/oauthConfig.module";
1717
import { AuthConfig } from "@/config/auth/auth.interface";
1818

1919
@Module({

0 commit comments

Comments
 (0)