-
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.
[GWL-211] Matches API 테스트 코드 작성 및 리팩토링 (#270)
* chore: matches/random * chore: create-match.dto 테스트 코드 작성 * test: random-match.dto 테스트 코드 작성 * chore: format 적용 * refactor: 레디스 expired 추가 * test: 서비스 코드에 expired 추가 * test: 올바르지 못한 코드 제거 * chore: matches 스웨거 작성 * chore: expired 타임 조정
- Loading branch information
Showing
9 changed files
with
106 additions
and
13 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
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
23 changes: 23 additions & 0 deletions
23
BackEnd/src/live-workouts/matches/dto/create-match.dto.spec.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,23 @@ | ||
import { plainToInstance } from 'class-transformer'; | ||
import { validate } from 'class-validator'; | ||
import { CreateMatchDto } from './create-match.dto'; | ||
|
||
describe('CreateMatchDto', () => { | ||
it('workoutId가 숫자일 때, 에러는 발생하지 않는다.', async () => { | ||
const dto = plainToInstance(CreateMatchDto, { workoutId: 1 }); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('workoutId가 문자로 들어왔을 때, 에러가 발생한다.', async () => { | ||
const dto = plainToInstance(CreateMatchDto, { workoutId: '닌자' }); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('만약 dto가 비어 있다면, 에러가 발생한다.', async () => { | ||
const dto = plainToInstance(CreateMatchDto, {}); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
BackEnd/src/live-workouts/matches/dto/random-match.dto.spec.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,44 @@ | ||
import { plainToInstance } from 'class-transformer'; | ||
import { validate } from 'class-validator'; | ||
import { | ||
RandomMatchDto, | ||
RandomMatch, | ||
RandomMatchResDto, | ||
randomNoMatchingResDto, | ||
} from './random-match.dto'; | ||
|
||
describe('RandomMatchDto', () => { | ||
it('workoutId와 waitingTime를 둘다 가질 경우에는 오류가 발생하지 않는다.', async () => { | ||
const dto = plainToInstance(RandomMatchDto, { | ||
workoutId: 1, | ||
waitingTime: 60, | ||
}); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('workoutId와 waitingTime를 둘 중 한개라도 숫자가 아닌 경우에는 오류가 발생한다.', async () => { | ||
const dto = plainToInstance(RandomMatchDto, { | ||
workoutId: '진', | ||
waitingTime: '육백만초', | ||
}); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('만약 값이 비어있다면, 오류가 발생한다.', async () => { | ||
const dto = plainToInstance(RandomMatchDto, {}); | ||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
|
||
describe('RandomMatchResDto', () => { | ||
it('만약 매칭이 잡힌 경우, true를 리턴한다.', async () => { | ||
const resDto = plainToInstance(RandomMatchResDto, { | ||
data: { matched: true }, | ||
}); | ||
const errors = await validate(resDto); | ||
expect(errors.length).toBe(0); | ||
}); | ||
}); |
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