diff --git a/.github/workflows/server-dev-ci.yml b/.github/workflows/server-dev-ci.yml new file mode 100644 index 0000000..2a02fb5 --- /dev/null +++ b/.github/workflows/server-dev-ci.yml @@ -0,0 +1,38 @@ +name: Backend Dev CI + +on: + pull_request: + branches: [develop] + paths: + - "server/**" + +defaults: + run: + working-directory: ./server + +jobs: + BACKEND-CI: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Use NodeJS + uses: actions/setup-node@v2 + with: + node-version: 20.8.1 + + - name: Cache node modules + id: cache + uses: actions/cache@v2 + with: + path: "**/node_modules" + key: npm-packages-${{ hashFiles('**/package-lock.json') }} + + - name: Install Dependency + if: steps.cache.outputs.cache-hit != 'true' + run: npm install + + - name: Execute Test + run: npm run test diff --git a/server/package.json b/server/package.json index 8d0f7dc..876a3e3 100644 --- a/server/package.json +++ b/server/package.json @@ -81,6 +81,9 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^src/(.*)": "/$1" + } } } diff --git a/server/src/auth/auth.controller.spec.ts b/server/src/auth/auth.controller.spec.ts index 27a31e6..bbeb643 100644 --- a/server/src/auth/auth.controller.spec.ts +++ b/server/src/auth/auth.controller.spec.ts @@ -1,15 +1,34 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { User } from 'src/entity/user.entity'; +import { Repository } from 'typeorm'; +import { JwtModule, JwtService } from '@nestjs/jwt'; describe('AuthController', () => { let controller: AuthController; + let service: AuthService; + let jwtModule: JwtModule; + let repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [JwtModule], controllers: [AuthController], + providers: [ + AuthService, + { + provide: getRepositoryToken(User), + useClass: Repository, + }, + ], }).compile(); controller = module.get(AuthController); + service = module.get(AuthService); + jwtModule = module.get(JwtModule); + repository = module.get(getRepositoryToken(User)); }); it('should be defined', () => { diff --git a/server/src/auth/auth.service.spec.ts b/server/src/auth/auth.service.spec.ts index 800ab66..32496c8 100644 --- a/server/src/auth/auth.service.spec.ts +++ b/server/src/auth/auth.service.spec.ts @@ -1,15 +1,30 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AuthService } from './auth.service'; +import { Repository } from 'typeorm'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { User } from 'src/entity/user.entity'; +import { JwtModule, JwtService } from '@nestjs/jwt'; describe('AuthService', () => { let service: AuthService; + let jwtModule: JwtModule; + let repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [AuthService], + imports: [JwtModule], + providers: [ + AuthService, + { + provide: getRepositoryToken(User), + useClass: Repository, + }, + ], }).compile(); service = module.get(AuthService); + jwtModule = module.get(JwtModule); + repository = module.get(getRepositoryToken(User)); }); it('should be defined', () => { diff --git a/server/src/user/user.controller.spec.ts b/server/src/user/user.controller.spec.ts index 7057a1a..4856bff 100644 --- a/server/src/user/user.controller.spec.ts +++ b/server/src/user/user.controller.spec.ts @@ -1,15 +1,30 @@ import { Test, TestingModule } from '@nestjs/testing'; import { UserController } from './user.controller'; +import { UserService } from './user.service'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { User } from 'src/entity/user.entity'; +import { Repository } from 'typeorm'; describe('UserController', () => { let controller: UserController; + let userService: UserService; + let repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [UserController], + providers: [ + UserService, + { + provide: getRepositoryToken(User), + useClass: Repository, + }, + ], }).compile(); controller = module.get(UserController); + userService = module.get(UserService); + repository = module.get(getRepositoryToken(User)); }); it('should be defined', () => { diff --git a/server/src/user/user.service.spec.ts b/server/src/user/user.service.spec.ts index 873de8a..5653523 100644 --- a/server/src/user/user.service.spec.ts +++ b/server/src/user/user.service.spec.ts @@ -1,15 +1,26 @@ import { Test, TestingModule } from '@nestjs/testing'; import { UserService } from './user.service'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; +import { User } from '../entity/user.entity'; describe('UserService', () => { let service: UserService; + let repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [UserService], + providers: [ + UserService, + { + provide: getRepositoryToken(User), + useClass: Repository, + }, + ], }).compile(); service = module.get(UserService); + repository = module.get(getRepositoryToken(User)) }); it('should be defined', () => {