Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

서버 테스트 자동화 코드 작성 #115

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading