forked from yy0ung/nibobnebob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : myPage 메인페이지 정보 및 수정 페이지 정보 요청 api 테스트 구현 #35
- Loading branch information
Showing
5 changed files
with
155 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3.8' | ||
services: | ||
postgres: | ||
image: postgis/postgis | ||
environment: | ||
POSTGRES_DB: testdb | ||
POSTGRES_USER: user | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- "5433:5432" | ||
volumes: | ||
- pgdata:/var/lib/postgresql/data | ||
volumes: | ||
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,48 +7,53 @@ import { newDb } from "pg-mem"; | |
import { DataSource, TypeORMError } from "typeorm"; | ||
import { User } from "./entities/user.entity"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { FollowEntity } from "./entities/user.followList.entity"; | ||
import { RestaurantInfoEntity } from "../restaurant/entities/restaurant.entity"; | ||
import { UserRestaurantListEntity } from "./entities/user.restaurantlist.entity"; | ||
import { UserWishRestaurantListEntity } from "./entities/user.wishrestaurantlist.entity"; | ||
import { ReviewInfoEntity } from "../review/entities/review.entity"; | ||
import { UserFollowListRepository } from "./user.followList.repository"; | ||
import { UserRestaurantListRepository } from "./user.restaurantList.repository"; | ||
import { UserWishRestaurantListRepository } from "./user.wishrestaurantList.repository"; | ||
import { RestaurantRepository } from "../restaurant/restaurant.repository"; | ||
import { ReviewRepository } from "../review/review.repository"; | ||
|
||
describe("UserService", () => { | ||
let userService: UserService; | ||
let dataSource: DataSource; | ||
beforeAll(async () => { | ||
const db = newDb({ autoCreateForeignKeyIndices: true }); | ||
|
||
db.public.registerFunction({ | ||
name: "current_database", | ||
implementation: () => "test_database", | ||
}); | ||
|
||
db.public.registerFunction({ | ||
name: "version", | ||
implementation: () => | ||
"PostgreSQL 12.16, compiled by Visual C++ build 1914, 64-bit", | ||
}); | ||
|
||
dataSource = await db.adapters.createTypeormDataSource({ | ||
type: "postgres", | ||
entities: [User], | ||
}); | ||
|
||
await dataSource.initialize(); | ||
await dataSource.synchronize(); | ||
|
||
beforeEach(async () => { | ||
const userRepository = dataSource.getRepository(User); | ||
await userRepository.query(`DELETE FROM public.user;`); | ||
}); | ||
beforeAll(async () => { | ||
const testModule = await Test.createTestingModule({ | ||
imports: [ | ||
AuthModule, | ||
TypeOrmModule.forRoot(), | ||
TypeOrmModule.forFeature([User]), | ||
TypeOrmModule.forRoot({ | ||
type: 'postgres', | ||
host: 'localhost', | ||
port: 5433, | ||
username: 'user', | ||
password: 'password', | ||
database: 'testdb', | ||
entities: [User, FollowEntity, RestaurantInfoEntity, UserRestaurantListEntity, UserWishRestaurantListEntity, ReviewInfoEntity], | ||
synchronize: true, | ||
}), | ||
TypeOrmModule.forFeature([User, RestaurantRepository, UserRepository, UserRestaurantListRepository, UserFollowListRepository, UserWishRestaurantListRepository, ReviewRepository]), | ||
], | ||
providers: [UserService, UserRepository], | ||
}) | ||
.overrideProvider(DataSource) | ||
.useValue(dataSource) | ||
.compile(); | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
userService = testModule.get<UserService>(UserService); | ||
dataSource = testModule.get<DataSource>(DataSource); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dataSource.destroy(); | ||
}); | ||
|
||
it("should create a new user and return the user data", async () => { | ||
it("회원가입", async () => { | ||
const userInfoDto: UserInfoDto = { | ||
email: "[email protected]", | ||
password: "1234", | ||
|
@@ -68,7 +73,7 @@ describe("UserService", () => { | |
where: { email: "[email protected]" }, | ||
}); | ||
|
||
expect(foundUser).toEqual( | ||
expect(foundUser).toEqual(await | ||
expect.objectContaining({ | ||
nickName: "hi", | ||
region: "인천", | ||
|
@@ -78,3 +83,95 @@ describe("UserService", () => { | |
); | ||
}); | ||
}); | ||
|
||
describe("마이페이지", () => { | ||
let userService: UserService; | ||
let dataSource: DataSource; | ||
beforeEach(async () => { | ||
const userRepository = dataSource.getRepository(User); | ||
await userRepository.query(`DELETE FROM public.user;`); | ||
}); | ||
|
||
|
||
beforeAll(async () => { | ||
const testModule = await Test.createTestingModule({ | ||
imports: [ | ||
AuthModule, | ||
TypeOrmModule.forRoot({ | ||
type: 'postgres', | ||
host: 'localhost', | ||
port: 5433, | ||
username: 'user', | ||
password: 'password', | ||
database: 'testdb', | ||
entities: [User, FollowEntity, RestaurantInfoEntity, UserRestaurantListEntity, UserWishRestaurantListEntity, ReviewInfoEntity], | ||
synchronize: true, | ||
}), | ||
TypeOrmModule.forFeature([User, RestaurantRepository, UserRepository, UserRestaurantListRepository, UserFollowListRepository, UserWishRestaurantListRepository, ReviewRepository]), | ||
], | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
userService = testModule.get<UserService>(UserService); | ||
dataSource = testModule.get<DataSource>(DataSource); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dataSource.destroy(); | ||
}); | ||
|
||
it("마이페이지 정보 요청", async () => { | ||
const userInfoDto: UserInfoDto = { | ||
email: "[email protected]", | ||
password: "1234", | ||
provider: " ", | ||
nickName: "hi", | ||
region: "인천", | ||
birthdate: "1999/10/13", | ||
isMale: true | ||
}; | ||
const userRepository = dataSource.getRepository(User); | ||
const id = await userRepository.save(userInfoDto); | ||
|
||
const mypageInfo = await userService.getMypageUserInfo(id) | ||
|
||
expect(mypageInfo).toEqual(await | ||
expect.objectContaining({ | ||
"userInfo": { | ||
nickName: "hi", | ||
region: "인천", | ||
birthdate: "1999/10/13", | ||
isMale: true, | ||
}, | ||
}) | ||
); | ||
}); | ||
it("마이페이지 수정 페이지 정보 요청", async () => { | ||
const userInfoDto: UserInfoDto = { | ||
email: "[email protected]", | ||
password: "1234", | ||
provider: " ", | ||
nickName: "hi", | ||
region: "인천", | ||
birthdate: "1999/10/13", | ||
isMale: true | ||
}; | ||
const userRepository = dataSource.getRepository(User); | ||
const id = await userRepository.save(userInfoDto); | ||
|
||
const mypageInfo = await userService.getMypageUserDetailInfo(id) | ||
|
||
expect(mypageInfo).toEqual(await | ||
expect.objectContaining({ | ||
"userInfo": { | ||
email: "[email protected]", | ||
nickName: "hi", | ||
provider: " ", | ||
region: "인천", | ||
birthdate: "1999/10/13", | ||
isMale: true, | ||
}, | ||
}) | ||
); | ||
}); | ||
}); |