-
Notifications
You must be signed in to change notification settings - Fork 3
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
13-7 [BE] [논문 상세 - 논문 정보] Request batch test 코드 작성 #92
Conversation
export function mockRedisQueue(popItem: () => string) { | ||
const lpush = jest.fn().mockResolvedValue(true); | ||
const rpush = jest.fn().mockResolvedValue(true); | ||
const lpop = jest | ||
.fn() | ||
.mockImplementation((key: string, size: number) => Array.from({ length: size }, () => popItem())); | ||
const llen = jest.fn().mockResolvedValue(10); | ||
return { | ||
lpush, | ||
rpush, | ||
lpop, | ||
llen, | ||
} as unknown as Redis; | ||
} | ||
|
||
export const popDoiItem = () => `0:0:-1:https://api.crossref.org/works/10.1234/asdf`; | ||
export const popSearchItem = () => `0:0:-1:https://api.crossref.org/works?query=keyword&rows=1000&cursor=examplecursor`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function mockRedisQueue(popItem: () => string) { | |
const lpush = jest.fn().mockResolvedValue(true); | |
const rpush = jest.fn().mockResolvedValue(true); | |
const lpop = jest | |
.fn() | |
.mockImplementation((key: string, size: number) => Array.from({ length: size }, () => popItem())); | |
const llen = jest.fn().mockResolvedValue(10); | |
return { | |
lpush, | |
rpush, | |
lpop, | |
llen, | |
} as unknown as Redis; | |
} | |
export const popDoiItem = () => `0:0:-1:https://api.crossref.org/works/10.1234/asdf`; | |
export const popSearchItem = () => `0:0:-1:https://api.crossref.org/works?query=keyword&rows=1000&cursor=examplecursor`; | |
export function mockRedisQueue(item: string) { | |
const lpush = jest.fn().mockResolvedValue(true); | |
const rpush = jest.fn().mockResolvedValue(true); | |
const lpop = jest | |
.fn() | |
.mockImplementation((key: string, size: number) => Array.from({ length: size }, () => item); | |
const llen = jest.fn().mockResolvedValue(10); | |
return { | |
lpush, | |
rpush, | |
lpop, | |
llen, | |
} as unknown as Redis; | |
} | |
export const DOI_ITEM =`0:0:-1:https://api.crossref.org/works/10.1234/asdf`; | |
export const SEARCH_ITEM = `0:0:-1:https://api.crossref.org/works?query=keyword&rows=1000&cursor=examplecursor`; |
함수로 선언하신 이유가 있나요? 상수로 사용해도 될 것 같아서요~
mockRedisQueue(popDoiItem)
개인적으로는 이 부분에서 redisQueue에 popDoiItem이라는 parameter가 좀 모호하게 느껴져서, mockRedisQueue(DOI_ITEM) 처럼 상수로 사용하는게 가독성이 더 좋은 것 같아요.
@@ -15,7 +15,7 @@ export class PaperInfo { | |||
constructor(body: PaperInfo) { | |||
this.title = body.title; | |||
this.authors = body.authors; | |||
this.doi = this.key = body.doi; | |||
this.doi = this.key = body.doi.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분 처리해주셨군요 👍
그럼 프론트쪽엔 LowerCase로 변환하는 로직이 있을필요는 없을 것 같은데.. 프론트로직에선 빼도 될까요? (지금 곳곳에 주렁주렁 달린 toLowerCase가 많아요 ..)
프론트에선 api 요청시 보내는 쿼리에 포함된 doi, 캐싱 키로 쓰이는 doi만 LowerCase로 변환해줘도 될 것 같아서요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋네요👍
항상 테스트 꼼꼼하게 신경써주셔서 감사합니다.
개요
Request batch에 대한 test 코드 템플릿 작성
작업사항
src/batch/tests
에 테스트 코드 작성 (진행중)리뷰 요청사항