Skip to content

Commit

Permalink
refactor: 테스트 픽스쳐에서 unique 한 값들에 대해 랜덤 값 부여 #170
Browse files Browse the repository at this point in the history
  • Loading branch information
koomchang committed Nov 25, 2024
1 parent 8d53c17 commit 120ada1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/test/course/course.repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('CourseRepository', () => {
coursePlaceRepository = datasource.getRepository(CoursePlace);
courseRepository = new CourseRepository(datasource, coursePlaceRepository);

fakeUser1 = UserFixture.createUser({ oauthId: 'abc' });
fakeUser2 = UserFixture.createUser({ oauthId: 'def' });
fakeUser1 = UserFixture.createUser({});
fakeUser2 = UserFixture.createUser({});
await datasource.getRepository(User).save([fakeUser1, fakeUser2]);
});

Expand Down
2 changes: 1 addition & 1 deletion backend/test/course/course.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('CourseService', () => {
placeRepository = new PlaceRepository(datasource);
courseRepository = new CourseRepository(datasource, coursePlaceRepository);
courseService = new CourseService(courseRepository, placeRepository);
fakeUser1 = UserFixture.createUser({ oauthId: 'abc' });
fakeUser1 = UserFixture.createUser({});
await datasource.getRepository(User).save(fakeUser1);
currentPage = 1;
pageSize = 10;
Expand Down
2 changes: 1 addition & 1 deletion backend/test/place/fixture/place.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlaceFixtureType } from '@test/place/fixture/place.fixture.type';

export class PlaceFixture {
static createPlace = ({
googlePlaceId = 'googlePlaceId_1',
googlePlaceId = `googlePlaceId${Date.now()}${Math.random()}`,
name = 'Central Park',
imageUrl = 'https://example.com/central_park.jpg',
rating = 4.5,
Expand Down
17 changes: 5 additions & 12 deletions backend/test/place/place.repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ describe('PlaceRepository', () => {

it('페이지 번호와 페이지 크기를 기준으로 모든 장소를 반환한다', async () => {
const places = [
PlaceFixture.createPlace({ googlePlaceId: 'googlePlaceId_1' }),
PlaceFixture.createPlace({ googlePlaceId: 'googlePlaceId_2' }),
PlaceFixture.createPlace({ googlePlaceId: 'googlePlaceId_3' }),
PlaceFixture.createPlace({}),
PlaceFixture.createPlace({}),
PlaceFixture.createPlace({}),
];

await placeRepository.save(places);
Expand Down Expand Up @@ -101,7 +101,6 @@ describe('PlaceRepository', () => {
it('페이지 크기가 전체 개수를 초과할 경우에도 정상적으로 작동한다', async () => {
const places = Array.from({ length: 50 }, (_, i) =>
PlaceFixture.createPlace({
googlePlaceId: `googlePlaceId_${i + 1}`,
name: `Place ${i + 1}`,
formattedAddress: `Address ${i + 1}`,
}),
Expand Down Expand Up @@ -166,26 +165,22 @@ describe('PlaceRepository', () => {
it('장소 이름이나 주소에 포함된 키워드를 찾아 해당하는 장소를 반환한다', async () => {
const placesWithParkName = [
{
googlePlaceId: 'googlePlaceId_1',
name: 'Central Park',
formattedAddress: 'New York, NY, USA',
},
{
googlePlaceId: 'googlePlaceId_2',
name: 'Tower Park',
formattedAddress: 'London, UK',
},
];
const placesWithParkAddress = [
{
googlePlaceId: 'googlePlaceId_3',
name: 'Eiffel Tower',
formattedAddress: 'Park Avenue, New York, NY, USA',
},
];
const placesEtc = [
{
googlePlaceId: 'googlePlaceId_4',
name: 'Seoul Forest',
formattedAddress: 'Seoul, South Korea',
},
Expand All @@ -195,8 +190,8 @@ describe('PlaceRepository', () => {
...placesWithParkName,
...placesWithParkAddress,
...placesEtc,
].map(({ googlePlaceId, name, formattedAddress }) =>
PlaceFixture.createPlace({ googlePlaceId, name, formattedAddress }),
].map(({ name, formattedAddress }) =>
PlaceFixture.createPlace({ name, formattedAddress }),
);
await placeRepository.save(places);

Expand Down Expand Up @@ -228,7 +223,6 @@ describe('PlaceRepository', () => {

it('검색 키워드는 대소문자를 구분하지 않는다', async () => {
const place = PlaceFixture.createPlace({
googlePlaceId: 'googlePlaceId_1',
name: 'Park View',
formattedAddress: 'New York, NY, USA',
});
Expand Down Expand Up @@ -259,7 +253,6 @@ describe('PlaceRepository', () => {
it('결과 개수가 페이지 크기를 초과할 경우 페이지 크기만큼만 반환한다', async () => {
const places = Array.from({ length: 20 }, (_, i) =>
PlaceFixture.createPlace({
googlePlaceId: `googlePlaceId_${i + 1}`,
name: `Place ${i + 1}`,
formattedAddress: `Address ${i + 1}`,
}),
Expand Down
2 changes: 1 addition & 1 deletion backend/test/user/fixture/user.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class UserFixture {
static createUser({
provider = 'google',
nickname = 'test',
oauthId = 'abcd1234',
oauthId = `${Date.now()}${Math.random()}`,
role = UserRole.MEMBER,
profileImageUrl = 'https://test.com/test.jpg',
}: UserFixtureType) {
Expand Down
2 changes: 1 addition & 1 deletion backend/test/user/fixture/user.fixture.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserRole } from '../../../src/user/user.role';
import { UserRole } from '@src/user/user.role';

export type UserFixtureType = {
provider?: string;
Expand Down

0 comments on commit 120ada1

Please sign in to comment.