Skip to content

Commit ee86cb5

Browse files
committed
getTodayString 이 잘못된 값을 반환하는 오류 수정
1 parent 90ea4b1 commit ee86cb5

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/app/naver/scraper.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ describe("Scraper", () => {
44
describe("searchPaymentHistory", () => {
55
it("should create an post request", async () => {
66
// given
7-
const cookie = "";
7+
const cookies = "";
88
const scraper = new NaverScraper();
99
const postSpy = jest.spyOn(axios, "post");
1010
postSpy.mockImplementation(() => Promise.resolve({ data: {} }));
1111

1212
// when
13-
await scraper.searchPaymentHistory(cookie);
13+
await scraper.searchPaymentHistory(cookies);
1414

1515
// then
1616
expect(postSpy).toBeCalledWith(
1717
scraper.searchPaymentHistoryURL,
1818
expect.any(Object),
1919
expect.objectContaining({
2020
headers: expect.objectContaining({
21-
Cookie: cookie,
21+
Cookie: cookies,
2222
}),
2323
})
2424
);
@@ -33,14 +33,14 @@ describe("Scraper", () => {
3333
const hour = minute * 60;
3434
const day = hour * 24;
3535

36-
const cookie = "";
36+
const cookies = "";
3737
const scraper = new NaverScraper();
3838
const postSpy = jest.spyOn(axios, "post");
3939
postSpy.mockImplementation(() => Promise.resolve({ data: {} }));
4040

4141
// when
4242
await scraper.nextPaymentHistory(
43-
cookie,
43+
cookies,
4444
"order-1234",
4545
new Date().getTime() - day * 30
4646
);
@@ -51,7 +51,7 @@ describe("Scraper", () => {
5151
expect.any(Object),
5252
expect.objectContaining({
5353
headers: expect.objectContaining({
54-
Cookie: cookie,
54+
Cookie: cookies,
5555
}),
5656
})
5757
);

src/app/naver/scraper.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ export class NaverScraper {
99
const year = today.getFullYear();
1010
const month = today.getMonth() + 1;
1111
const date = today.getDate();
12-
return `${year}-${month}-${date}`;
12+
const monthString = month >= 10 ? month : "0" + month;
13+
const dateString = date >= 10 ? date : "0" + date;
14+
return `${year}-${monthString}-${dateString}`;
1315
}
1416

1517
searchPaymentHistoryURL =
1618
"https://new-m.pay.naver.com/api/timeline/searchPaymentHistory";
1719
async searchPaymentHistory(
18-
cookie: string,
20+
cookies: string,
1921
searchOptions?: {
2022
keyword: string;
2123
serviceGroup: ServiceGroup;
@@ -31,24 +33,23 @@ export class NaverScraper {
3133
};
3234
const options = {
3335
headers: {
34-
Cookie: cookie,
36+
Cookie: cookies,
3537
"content-type": "application/json;charset=UTF-8",
3638
},
3739
};
38-
3940
const response = await axios.post(
4041
this.searchPaymentHistoryURL,
4142
data,
4243
options
4344
);
4445

45-
return { status: response.status, data: response.data as string };
46+
return { status: response.status, data: JSON.stringify(response.data) };
4647
}
4748

4849
nextPaymentHistoryURL =
4950
"https://new-m.pay.naver.com/api/timeline/nextPaymentHistory";
5051
async nextPaymentHistory(
51-
cookie: string,
52+
cookies: string,
5253
lastHistoryId: string,
5354
lastHistoryDateTimestamp: number,
5455
searchOptions?: {
@@ -68,17 +69,15 @@ export class NaverScraper {
6869
};
6970
const options = {
7071
headers: {
71-
Cookie: cookie,
72+
Cookie: cookies,
7273
"content-type": "application/json;charset=UTF-8",
7374
},
7475
};
75-
7676
const response = await axios.post(
7777
this.nextPaymentHistoryURL,
7878
data,
7979
options
8080
);
81-
82-
return { status: response.status, data: response.data as string };
81+
return { status: response.status, data: JSON.stringify(response.data) };
8382
}
8483
}

0 commit comments

Comments
 (0)