-
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.
Merge pull request #8 from snuhcs-course/backend/feat/review
Backend/feat/review
- Loading branch information
Showing
16 changed files
with
529 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
backend/src/review/dtos/in-dtos/review-adjacent-query.dto.ts
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,16 @@ | ||
import { IsNumber } from 'class-validator'; | ||
import { Transform, Type } from 'class-transformer'; | ||
|
||
export class ReviewAdjacentQueryDto { | ||
@IsNumber() | ||
@Type(() => Number) | ||
latitude: number; | ||
|
||
@IsNumber() | ||
@Type(() => Number) | ||
longitude: number; | ||
|
||
@IsNumber() | ||
@Type(() => Number) | ||
distance: number; | ||
} |
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,12 @@ | ||
import { RestaurantDto } from './restaurant.dto'; | ||
import { RestaurantEntity } from '../../models/restaurant.entity'; | ||
|
||
export class RestaurantListDto { | ||
private restaurantList: RestaurantDto[]; | ||
|
||
constructor(restaurantList: RestaurantEntity[]) { | ||
this.restaurantList = restaurantList.map( | ||
(restaurant) => new RestaurantDto(restaurant), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { NestExpressApplication } from '@nestjs/platform-express'; | ||
import { AppModule } from '../../app.module'; | ||
import { Test } from '@nestjs/testing'; | ||
import { DataSource } from 'typeorm'; | ||
import { appSetting } from '../../main'; | ||
import * as supertest from 'supertest'; | ||
import { UserEntity } from '../../user/models/user.entity'; | ||
import { UserFixture } from '../fixture/user.fixture'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { RestaurantEntity } from '../../review/models/restaurant.entity'; | ||
import { RestaurantFixture } from '../fixture/restaurant.fixture'; | ||
import { ReviewEntity } from '../../review/models/review.entity'; | ||
import { ReviewFixture } from '../fixture/review.fixture'; | ||
import { ImageFixture } from '../fixture/image.fixture'; | ||
import { | ||
validateRestaurantList, | ||
validateReview, | ||
validateReviewList, | ||
} from './validateReviewList'; | ||
|
||
describe('Get adjacent restaurant test', () => { | ||
let testServer: NestExpressApplication; | ||
let dataSource: DataSource; | ||
let user: UserEntity; | ||
let accessToken: string; | ||
let restaurant: RestaurantEntity; | ||
let review: ReviewEntity; | ||
|
||
beforeAll(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
testServer = module.createNestApplication<NestExpressApplication>(); | ||
dataSource = testServer.get(DataSource); | ||
await dataSource.synchronize(true); | ||
appSetting(testServer); | ||
|
||
await testServer.init(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await dataSource.synchronize(true); | ||
|
||
user = await UserFixture.create({ | ||
name: 'hi', | ||
username: 'hello', | ||
password: 'world', | ||
}); | ||
|
||
const { body } = await supertest(testServer.getHttpServer()) | ||
.post('/auth/login') | ||
.send({ | ||
username: 'hello', | ||
password: 'world', | ||
}) | ||
.expect(HttpStatus.CREATED); | ||
|
||
accessToken = body.accessToken; | ||
|
||
restaurant = await RestaurantFixture.create({}); | ||
const image = await ImageFixture.create({}); | ||
review = await ReviewFixture.create({ | ||
restaurant, | ||
images: [image], | ||
user, | ||
}); | ||
}); | ||
|
||
it('unauthorized', async () => { | ||
await supertest(testServer.getHttpServer()) | ||
.get( | ||
`/reviews/adjacent/restaurants?longitude=127.0&latitude=37.0&distance=1`, | ||
) | ||
.expect(HttpStatus.UNAUTHORIZED); | ||
}); | ||
|
||
it('OK', async () => { | ||
await supertest(testServer.getHttpServer()) | ||
.get( | ||
`/reviews/adjacent/restaurants?longitude=127.0&latitude=37.0&distance=1`, | ||
) | ||
.set('Authorization', `Bearer ${accessToken}`) | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it('DTO check', async () => { | ||
restaurant.longitude = 127.0; | ||
restaurant.latitude = 37.0; | ||
await restaurant.save(); | ||
|
||
const { body } = await supertest(testServer.getHttpServer()) | ||
.get( | ||
`/reviews/adjacent/restaurants?longitude=127.0&latitude=37.0&distance=1`, | ||
) | ||
.set('Authorization', `Bearer ${accessToken}`) | ||
.expect(HttpStatus.OK); | ||
|
||
validateRestaurantList(body); | ||
}); | ||
|
||
// TODO : unittest | ||
it('멀리 떨어지면 안잡한다', async () => { | ||
restaurant.longitude = 127.0; | ||
restaurant.latitude = 37.018018; | ||
await restaurant.save(); | ||
|
||
const { body } = await supertest(testServer.getHttpServer()) | ||
.get( | ||
`/reviews/adjacent/restaurants?longitude=127.0&latitude=37.0&distance=1`, | ||
) | ||
.set('Authorization', `Bearer ${accessToken}`) | ||
.expect(HttpStatus.OK); | ||
|
||
expect(body.restaurantList.length).toEqual(0); | ||
|
||
const { body: body2 } = await supertest(testServer.getHttpServer()) | ||
.get( | ||
`/reviews/adjacent/restaurants?longitude=127.0&latitude=37.0&distance=3`, | ||
) | ||
.set('Authorization', `Bearer ${accessToken}`) | ||
.expect(HttpStatus.OK); | ||
|
||
expect(body2.restaurantList.length).toEqual(1); | ||
}); | ||
}); |
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
Oops, something went wrong.