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

Feat: 식물 카드 상세 조회 API #33

Merged
merged 11 commits into from
Nov 4, 2023
18 changes: 13 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
## 📚 PR 요약 / Linked Issue
해당 PR에서 작업한 내용을 한 줄로 요약해주세요.

해당 PR에서 작업한 내용을 한 줄로 요약해주세요.
close #{no}

## 💡 변경 사항

디테일한 작업 내역을 적어주세요.
주의할 사항이 있다면 적어주세요.
변경사항 (모듈 설치 등)이 있다면 적어주세요.

## ✅ PR check list
- [ ] 커밋 컨벤션, 제목 등을 확인했나요?
- [ ] 알맞은 라벨을 달았나요?
- [ ] 셀프 코드리뷰를 작성했나요?
## 📖 Swagger

API Swagger 를 추가했다면 캡쳐해주세요.

## ✅ PR check list

- [ ] 테스트 코드를 작성했나요? (unit/e2e)
- [ ] 커밋 컨벤션, 제목 등을 확인했나요?
- [ ] 알맞은 라벨을 달았나요?
- [ ] 셀프 코드리뷰를 작성했나요?
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lerna-debug.log*

# env
.env
.env.test

# OS
.DS_Store
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Set the version of docker compose to use
version: '3.9'

# The containers that compose the project
services:
db:
image: mysql:8.0
restart: always
container_name: e2e-test-prisma
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
volumes:
- /var/lib/mysql
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --skip-character-set-client-handshake
Comment on lines +1 to +20
Copy link
Member Author

@jokj624 jokj624 Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e 테스트 시 현재 사용중인 DB 에 영향이 가지 않도록 docker-compose 를 사용해 MySQL 로컬 DB 를 띄우고 격리된 환경으로 진행하기 위한 compose file 입니다.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "yarn docker:up && sleep 6.5 && yarn migrate:test && yarn seed:test && dotenv -e .env.test -- jest --config ./test/jest-e2e.json && yarn docker:down",
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
"seed:test": "dotenv -e .env.test -- npx prisma db seed",
"docker:up": "docker-compose -f docker-compose.test.yml up -d",
"docker:down": "docker-compose -f docker-compose.test.yml down -v"
},
"prisma": {
"seed": "cross-env NODE_ENV=test ts-node prisma/seed.ts"
Comment on lines +21 to +28
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn test:e2e 진행 시 다음과 같은 순서로 진행됩니다.

  1. docker-compose 로 MySQL 컨테이너 Up
  2. 컨테이너 환경 구축 동안 잠시 sleep
  3. env.test 파일을 환경 변수로 하여 prisma migrate 진행
  4. 만들어져 있는 seed 파일을 실행시켜 DB에 더미 데이터 삽입
  5. env.test 파일을 환경 변수로 하여 jest e2e 테스트 진행
  6. 테스트 성공적 종료 시 MySQL 컨테이너 down

참고)
dotenv -e .env.test 의 경우 prisma 문서에서 prisma 를 multi 환경에서 사용하기 위해 dotenv-cli 라는 패키지를 사용해 진행하면 된다고 명시되어 있어 사용했습니다. 가이드

},
"dependencies": {
"@nestjs/axios": "^2.0.0",
Expand All @@ -39,6 +46,7 @@
"class-validator": "^0.14.0",
"dayjs": "^1.11.9",
"dotenv": "^16.0.3",
"dotenv-cli": "^7.2.1",
"jest-mock-extended": "^3.0.4",
"nanoid": "3.3.4",
"passport": "^0.6.0",
Expand All @@ -58,6 +66,7 @@
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
Expand Down
274 changes: 274 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
import { PrismaClient } from '@prisma/client';
import * as dayjs from 'dayjs';
import * as utc from 'dayjs/plugin/utc';
import * as timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);

const prisma = new PrismaClient();

async function main() {
const user = await prisma.user.create({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 환경을 위해 만들어진 DB 에 더미데이터 삽입을 위한 seed 파일

앞으로 테스트 로직이 추가 될 때 필요한 더미 데이터가 있다면 seed 파일을 통해 삽입하면 됩니다.

data: {
id: 1,
email: 'ddd',
createdAt: dayjs('2023-07-22 08:15:37.225Z').toDate(),
fcmToken: 'dd',
nickname: 'ddd',
password: 'dd',
phone: 'ddd',
profileImageURL: 'dd',
refreshToken: 'dd',
socialType: 'kakao',
title: 'dd',
updatedAt: dayjs('2023-07-22 08:15:37.225Z').toDate(),
uuid: 'dd',
appleId: null,
appleRefreshToken: null,
kakaoId: 1,
},
});

const plants = await prisma.plant.createMany({
data: [
{
id: 1,
name: '오렌지 자스민',
cycle: 2,
introduction: '붙임성이 좋은\n앙증맞은 오렌지 자스민',
meaning: '당신을 향해',
explanation:
'1~2일에 한 번 물을 주는 것을 추천해요\n물을 좋아하는 자스민이 곧 귀여운 열매를 선물할거에요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/mindlere-circle.png',
gifURL: 'aaa',
},
{
id: 2,
name: '로즈마리',
cycle: 4,
introduction: '당신의 하루를 치유하는\n향기로운 로즈마리',
meaning: '기억해 주세요',
explanation:
'3~4일에 한 번 물을 주는 것을 추천해요\n자주 연락하고 많은 시간을 함께하며 추억을 쌓아가요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/rosemari-circle.png',
gifURL: 'aaa',
},
{
id: 3,
name: '아메리칸 블루',
cycle: 6,
introduction: '매일매일 꽃이 피는\n푸른 빛의 아메리칸 블루',
meaning: '두 사람의 인연',
explanation:
'일주일에 한 번 물을 주는 것을 추천해요\n종종 안부를 물으면서 오손도손 이야기를 나누어요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/americanblue-circle.png',
gifURL: 'aaa',
},
{
id: 4,
name: '민들레',
cycle: 13,
introduction: '감사하는 마음을 가진\n따뜻한 민들레',
meaning: '인연에서의 행복',
explanation:
'보름에 한 번 물을 주는 것을 추천해요\n당신의 연락이 홀씨가 되어 날아가 행복으로 피어날거에요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/mindlere-circle.png',
gifURL: 'ㅁㅁ',
},
{
id: 5,
name: '스투키',
cycle: 29,
introduction: '언제나 당신을 지켜주는\n든든한 스투키',
meaning: '너그러움',
explanation:
'한달에 한 번 물을 주는 것을 추천해요\n가끔씩 연락하더라도 오래 만날 수 있길 바라요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/stuki-circle.png',
gifURL: 'ㅁㅁ',
},
{
id: 6,
name: '단모환',
cycle: 90,
introduction: '당신의 밤을 지켜주는\n씩씩한 단모환',
meaning: '사랑과 열정',
explanation:
'세 달에 한 번 물을 주는 것을 추천해요\n자주 보지 못해도 분명 당신의 연락을 기다릴거에요!',
circleImageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/circleImages/danmohwan-circle.png',
gifURL: 'ㅁㅁㅁ',
},
],
skipDuplicates: true,
});

const plantLevels = await prisma.plantLevel.createMany({
data: [
{
id: 1,
plantId: 1,
level: 0,
levelName: '어린 나무',
description: '무럭무럭 자랄 준비를 하고 있어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/mindlere-1.png',
},
{
id: 2,
plantId: 1,
level: 1,
levelName: '개화',
description: '하얀 꽃이 활짝 피어났어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/mindlere-2.png',
},
{
id: 3,
plantId: 1,
level: 2,
levelName: '열매',
description: '꽃이 머물다간 자리에 앙증맞은 열매가 열렸네요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/mindlere-complete.png',
},
{
id: 4,
plantId: 2,
level: 0,
levelName: '새싹',
description: '새싹이 쏘옥 얼굴을 내밀었어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/rosemari-1.png',
},
{
id: 5,
plantId: 2,
level: 1,
levelName: '꽃망울',
description: '꽃망울이 방울방울 맺혔어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/rosemari-2.png',
},
{
id: 6,
plantId: 2,
level: 2,
levelName: '개화',
description: '예쁜 꽃이 활짝 피어났어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/rosemari-complete.png',
},
{
id: 7,
plantId: 3,
level: 0,
levelName: '새싹',
description: '새싹이 쏘옥 얼굴을 내밀었어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/americanblue-1.png',
},
{
id: 8,
plantId: 3,
level: 1,
levelName: '꽃망울',
description: '꽃망울이 방울방울 맺혔어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/americanblue-2.png',
},
{
id: 9,
plantId: 3,
level: 2,
levelName: '개화',
description: '예쁜 꽃이 활짝 피어났어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/americanblue-complete.png',
},
{
id: 10,
plantId: 4,
level: 0,
levelName: '새싹',
description: '새싹이 쏘옥 얼굴을 내밀었어요!',
imageURL:
'https://cherish-static-dev.s3.ap-northeast-2.amazonaws.com/plantLevel/mindlere-1.png',
},
],
skipDuplicates: true,
});

const userPlant = await prisma.userPlant.create({
data: {
id: 1,
userId: 1,
nickname: 'test',
instagram: null,
phone: null,
waterCycle: 14,
waterCount: 0,
isNotified: true,
loveGauge: 0,
createdAt: dayjs('2023-07-22 08:16:52.538Z').toDate(),
updatedAt: dayjs('2023-07-22 08:16:52.538Z').toDate(),
waterTime: null,
plantId: 4,
},
});

const water = await prisma.water.createMany({
data: [
{
id: 1,
userPlantId: 1,
review: '리뷰1',
wateringDate: dayjs('2023-07-22 08:55:31.799Z').toDate(),
updatedAt: dayjs('2023-07-22 08:55:31.799Z').toDate(),
},
{
id: 3,
userPlantId: 1,
review: '리뷰2',
wateringDate: dayjs('2023-07-22 18:16:53Z').toDate(),
updatedAt: dayjs('2023-07-22 09:16:54.635Z').toDate(),
},
],
skipDuplicates: true,
});

const waterKeword = await prisma.waterKeyword.createMany({
data: [
{
id: 1,
waterId: 4,
keyword: 'keyword1',
createdAt: dayjs('2023-07-22 12:20:11.257Z').toDate(),
updatedAt: dayjs('2023-07-22 12:20:11.257Z').toDate(),
},
{
id: 2,
waterId: 4,
keyword: 'keyword2',
createdAt: dayjs('2023-07-22 12:20:11.257Z').toDate(),
updatedAt: dayjs('2023-07-22 12:20:11.257Z').toDate(),
},
],
skipDuplicates: true,
});
}

main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { PrismaService } from 'src/prisma.service';
ConfigModule.forRoot({
isGlobal: true,
load: [configuration],
envFilePath: '.env',
envFilePath: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
}),
AuthModule,
HttpModule,
Expand Down
1 change: 1 addition & 0 deletions src/common/objects/response-message.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const RESPONSE_MESSAGE: {
REISSUED_TOKEN_SUCCESS: '토큰 재발급 성공',

// plants
READ_PLANT_DETAIL_SUCCESS: '식물 상세 조회 성공',
READ_PLANT_INFORMATION_SUCCESS: '식물 단계 조회 성공',
READ_PLANT_WATER_LOG_SUCCESS: '식물 물주기 기록 조회 성공',
};
13 changes: 11 additions & 2 deletions src/constants/swagger/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { SIGNIN_DESCRIPTION } from './auth';
import { PLANT_INFORMATION, PLANT_WATER_LOG } from './plants';
import {
READ_PLANT_DETAIL,
READ_PLANT_INFORMATION,
READ_PLANT_WATER_LOG,
} from './plants';

export const ERROR_DESCRIPTION = {
INTERNAL_SERVER_ERROR: 'Internal Server Error',
};

export { SIGNIN_DESCRIPTION, PLANT_INFORMATION, PLANT_WATER_LOG };
export {
SIGNIN_DESCRIPTION,
READ_PLANT_DETAIL,
READ_PLANT_INFORMATION,
READ_PLANT_WATER_LOG,
};