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

Staging #61

Merged
merged 8 commits into from
Sep 25, 2024
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ erDiagram
sticker_category_mapper ||--o{ sticker_category : categorized_as
```

## 커밋 컨벤션

## 네이밍 룰의 우선사항

**엔티티 중심의 클래스 작명**: {Entity}{Action}{Purpose}{Layer}
Expand Down Expand Up @@ -326,12 +324,12 @@ AgreementsService
- **접두사:** `dto_`
- **예시:** `dto_agreement`

### DB 관련 변수 (db connection pool 등)
### DB 관련 변수 (db connection pool 등)

- **접두사:** `db_`
- **예시:** `db_redisQueue`, `db_dataSource`

커밋 메세지과 머지 룰
## 커밋 메세지과 머지 룰

### 커밋 컨벤션

Expand Down
12 changes: 6 additions & 6 deletions deploy/deploy-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 스크립트의 실제 위치를 기준으로 경로 설정
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR=$(cd "$SCRIPT_DIR/.."; pwd)
PEM_PATH="$SCRIPT_DIR/../../../keys/blccu-prod.pem"
PEM_PATH="$SCRIPT_DIR/../../../keys/blccu-dev-rsa.pem"

# PEM 파일 경로가 올바른지 확인
if [[ ! -f "$PEM_PATH" ]]; then
Expand All @@ -13,12 +13,12 @@ fi
# PEM 파일 권한 확인 및 수정
chmod 400 "$PEM_PATH"

HOSTS=("13.209.215.21")
HOSTS=("3.34.58.11")
ACCOUNT=ubuntu
SERVICE_NAME=blccu
SERVICE_NAME=blccu-ecr
DOCKER_TAG=latest
ECR_URL="792939917746.dkr.ecr.ap-northeast-2.amazonaws.com"
AWS_PROFILE=production # 배포 프로파일 사용
ECR_URL="637423583546.dkr.ecr.ap-northeast-2.amazonaws.com"
AWS_PROFILE=staging # 배포 프로파일 사용
ENV_FILE="$ROOT_DIR/.env.prod"

NGINX_CONFIG=/etc/nginx/nginx.conf
Expand Down Expand Up @@ -66,7 +66,7 @@ for HOST in "${HOSTS[@]}"; do
echo -e "\n## new docker pull & run on $HOST ##\n"
ssh -i $PEM_PATH $SERVER "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_URL"
ssh -i $PEM_PATH $SERVER "docker pull $ECR_URL/$SERVICE_NAME:$DOCKER_TAG"
ssh -i $PEM_PATH $SERVER "docker run --env-file /home/$ACCOUNT/upload/.env.prod -d -p $NEW_PORT:3000 --name $NEW_SERVICE_NAME -e TZ=Asia/Seoul --network blccu_network $ECR_URL/$SERVICE_NAME"
ssh -i $PEM_PATH $SERVER "docker run --env-file /home/$ACCOUNT/upload/.env.prod -d -p $NEW_PORT:3000 --name $NEW_SERVICE_NAME -e TZ=Asia/Seoul $ECR_URL/$SERVICE_NAME"

# 헬스체크 수행
echo -e "\n## 헬스체크 수행 on $HOST ##\n"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "UNLICENSED",
"scripts": {
"ssh:staging": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected];",
"ssh:prod": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected]",
"ssh:prod1": "ssh -i ../../keys/blccu-prod.pem [email protected]",
"ssh:prod2": "ssh -i ../../keys/blccu-prod.pem [email protected]",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
Expand Down
1 change: 1 addition & 0 deletions src/APIs/agreements/__test__/agreements.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('AgreementsService', () => {
...TEST_DATE_FIELDS,
};
});

describe('createAgreement', () => {
it('should return AgreementDto with valid input', async () => {
const createAgreementInput: IAgreementsServiceCreate = {
Expand Down
155 changes: 155 additions & 0 deletions src/APIs/announcements/__test__/announcements.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AnnouncementsController } from '../announcements.controller';
import { AnnouncementsService } from '../announcements.service';
import {
MockService,
MockServiceFactory,
TEST_DATE_FIELDS,
} from '@/utils/test.utils';
import { Request } from 'express';
import { AnnouncementCreateRequestDto } from '../dtos/request/announcement-create-request.dto';
import { AnnouncementDto } from '../dtos/common/announcement.dto';
import { AnnouncementPatchRequestDto } from '../dtos/request/announcement-patch-request.dto';
import {
BlccuExceptionTest,
BlccuHttpException,
} from '@/common/blccu-exception';

describe('announcementsController', () => {
let req: Request;
let ctrl_announcements: AnnouncementsController;
let svc_annoucements: MockService<AnnouncementsService>;
let dto_announcement: AnnouncementDto;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AnnouncementsController],
providers: [
{
provide: AnnouncementsService,
useValue: MockServiceFactory.getMockService(AnnouncementsService),
},
],
}).compile();

dto_announcement = {
id: 1,
title: '제목없음',
content: '공지내용',
...TEST_DATE_FIELDS,
};
ctrl_announcements = module.get<AnnouncementsController>(
AnnouncementsController,
);
svc_annoucements =
module.get<MockService<AnnouncementsService>>(AnnouncementsService);
req = { user: { userId: 1 } } as Request;
});

describe('createAnnouncement', () => {
it('should return AnnouncementDto for valid input', async () => {
// Arrange
const dto_createAnnouncement: AnnouncementCreateRequestDto = {
title: '제목없음',
content: '공지내용',
};
svc_annoucements.createAnnoucement.mockResolvedValue(dto_announcement);
// Act
const result = await ctrl_announcements.createAnnouncement(
req,
dto_createAnnouncement,
);
// Assert
expect(result).toEqual(dto_announcement);
expect(svc_annoucements.createAnnoucement).toHaveBeenCalledWith({
...dto_createAnnouncement,
userId: req.user.userId,
});
});
});

describe('getAnnouncements', () => {
it('should return AnnoucementDto[] for any condition', async () => {
// Arrange
svc_annoucements.getAnnouncements.mockResolvedValue([dto_announcement]);
// Act
const result = await ctrl_announcements.getAnnouncements();
// Assert
expect(result).toEqual([dto_announcement]);
expect(svc_annoucements.getAnnouncements).toHaveBeenCalled();
});
});

describe('patchAnnouncement', () => {
it('should return AnnouncementDto for valid input', async () => {
// Arrange
const announcementId = 1;
const dto_patchAnnouncement: AnnouncementPatchRequestDto = {
title: '수정된 제목',
content: '수정된 내용',
};
svc_annoucements.patchAnnouncement.mockResolvedValue({
dto_announcement,
...dto_patchAnnouncement,
});

// Act
const result = await ctrl_announcements.patchAnnouncement(
req,
dto_patchAnnouncement,
announcementId,
);
// Assert
expect(result).toEqual({ dto_announcement, ...dto_patchAnnouncement });
expect(svc_annoucements.patchAnnouncement).toHaveBeenCalledWith({
...dto_patchAnnouncement,
announcementId,
userId: req.user.userId,
});
});

it('should throw exception for non-admin user', async () => {
// Arrange
const announcementId = 1;
const dto_patchAnnouncement: AnnouncementPatchRequestDto = {
title: '수정된 제목',
content: '수정된 내용',
};
svc_annoucements.patchAnnouncement.mockRejectedValue(
new BlccuHttpException('NOT_AN_ADMIN'),
);
// Act
const act = () =>
ctrl_announcements.patchAnnouncement(
req,
dto_patchAnnouncement,
announcementId,
);
// Assert
expect(act()).rejects.toThrow(BlccuExceptionTest('NOT_AN_ADMIN'));
expect(svc_annoucements.patchAnnouncement).toHaveBeenCalledWith({
...dto_patchAnnouncement,
announcementId,
userId: req.user.userId,
});
});
});

describe('removeAnnouncement', () => {
it('should return AnnouncementDto for valid input', async () => {
// Arrange
const announcementId = 1;
svc_annoucements.removeAnnouncement.mockResolvedValue(dto_announcement);
// Act
const result = await ctrl_announcements.removeAnnouncement(
req,
announcementId,
);
// Assert
expect(result).toEqual(dto_announcement);
expect(svc_annoucements.removeAnnouncement).toHaveBeenCalledWith({
userId: req.user.userId,
announcementId,
});
});
});
});
Loading
Loading