Skip to content

Commit

Permalink
✅ Test: authService test code about 80%
Browse files Browse the repository at this point in the history
  • Loading branch information
황세민 authored and 황세민 committed Jul 13, 2024
1 parent f39b7f2 commit 1a99281
Show file tree
Hide file tree
Showing 24 changed files with 1,045 additions and 265 deletions.
Empty file.
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@ services:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_NAME}

redis:
image: redis:latest
restart: always
ports:
- '6379:6379'
networks:
- mynetwork
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 30s
timeout: 10s
retries: 5

networks:
mynetwork: # 네트워크 정의 추가
driver: bridge
10 changes: 1 addition & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"moment": "^2.30.1",
"mongoose": "^8.4.0",
"multer": "^1.4.5-lts.1",
"nest": "^0.1.6",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion public/client1.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ <h1>WebSocket Client 1</h1>
}

function joinRooms() {
io.emit('joinRooms');
io.emit('joinRooms'); // 'joinRooms' event를 publishing
console.log('join room');
io.on('joinedRooms', (room) => {
// 'joinedRooms' event를 subscribe
console.log(`Joined room: ${room}`);
});
}
Expand Down
36 changes: 18 additions & 18 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// import { Test, TestingModule } from '@nestjs/testing';
// import { AppController } from './app.controller';
// import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;
// describe('AppController', () => {
// let appController: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
// beforeEach(async () => {
// const app: TestingModule = await Test.createTestingModule({
// controllers: [AppController],
// providers: [AppService],
// }).compile();

appController = app.get<AppController>(AppController);
});
// appController = app.get<AppController>(AppController);
// });

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
// describe('root', () => {
// it('should return "Hello World!"', () => {
// expect(appController.getHello()).toBe('Hello World!');
// });
// });
// });
32 changes: 16 additions & 16 deletions src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './AuthService';
// import { Test, TestingModule } from '@nestjs/testing';
// import { AuthController } from './auth.controller';
// import { AuthService } from './auth.service';

describe('AuthController', () => {
let controller: AuthController;
// describe('AuthController', () => {
// let controller: AuthController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [AuthService],
}).compile();
// beforeEach(async () => {
// const module: TestingModule = await Test.createTestingModule({
// controllers: [AuthController],
// providers: [AuthService],
// }).compile();

controller = module.get<AuthController>(AuthController);
});
// controller = module.get<AuthController>(AuthController);
// });

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
// it('should be defined', () => {
// expect(controller).toBeDefined();
// });
// });
5 changes: 1 addition & 4 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class AuthController {
const detective = await this.authService.createDetectiveWithNoFile(
createDetectiveEmployeeAuthDto,
);
console.log('detective', detective);

if (!detective) {
throw new Error('계정을 생성할 수 없습니다');
Expand Down Expand Up @@ -119,8 +118,6 @@ export class AuthController {
try {
const token = await this.authService.signIn(signInDto);

if (!token) throw new UnauthorizedException('로그인에 실패하였습니다.');

return res
.cookie('authorization', `Bearer ${token}`, {
maxAge: 7 * 24 * 60 * 60 * 1000,
Expand All @@ -129,7 +126,7 @@ export class AuthController {
sameSite: 'None',
})
.status(HttpStatus.OK)
.json({ message: '성공적으로 로그인하였습니다.' });
.json({ message: '로그인하였습니다.' });
} catch (error) {
return res.status(HttpStatus.UNAUTHORIZED).json({ message: error.message });
}
Expand Down
3 changes: 2 additions & 1 deletion src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PassportModule } from '@nestjs/passport';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtStrategy } from './strategies/jwt.strategy';
import { AuthService } from './auth.service';
import { DetectiveOffice } from 'src/office/entities/detective-office.entity';

@Module({
controllers: [AuthController],
Expand All @@ -20,7 +21,7 @@ import { AuthService } from './auth.service';
S3Module,
HttpModule,
PassportModule,
TypeOrmModule.forFeature([User, Detective, File]),
TypeOrmModule.forFeature([User, Detective, File, DetectiveOffice]),
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
Expand Down
Loading

0 comments on commit 1a99281

Please sign in to comment.