Skip to content

Commit

Permalink
Merge pull request #115 from boostcampwm2023/server/feature/test
Browse files Browse the repository at this point in the history
서버 테스트 자동화 코드 작성
  • Loading branch information
sk000801 authored Nov 20, 2023
2 parents 56b7711 + f39ff65 commit 980fb56
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/server-dev-ci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)": "<rootDir>/$1"
}
}
}
19 changes: 19 additions & 0 deletions server/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(AuthController);
service = module.get<AuthService>(AuthService);
jwtModule = module.get<JwtModule>(JwtModule);
repository = module.get(getRepositoryToken(User));
});

it('should be defined', () => {
Expand Down
17 changes: 16 additions & 1 deletion server/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(AuthService);
jwtModule = module.get<JwtModule>(JwtModule);
repository = module.get(getRepositoryToken(User));
});

it('should be defined', () => {
Expand Down
15 changes: 15 additions & 0 deletions server/src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(UserController);
userService = module.get<UserService>(UserService);
repository = module.get(getRepositoryToken(User));
});

it('should be defined', () => {
Expand Down
13 changes: 12 additions & 1 deletion server/src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(UserService);
repository = module.get(getRepositoryToken(User))
});

it('should be defined', () => {
Expand Down

0 comments on commit 980fb56

Please sign in to comment.