Skip to content

Commit 893400e

Browse files
committed
nextPaymentHistory 추가
1 parent 8a62f08 commit 893400e

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/app/naver/scraper.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,37 @@ describe("Scraper", () => {
2424
);
2525
});
2626
});
27+
28+
describe("nextPaymentHistory", () => {
29+
it("should create an post request", async () => {
30+
// given
31+
const second = 1000;
32+
const minute = second * 60;
33+
const hour = minute * 60;
34+
const day = hour * 24;
35+
36+
const cookie = "";
37+
const scraper = new NaverScraper();
38+
const postSpy = jest.spyOn(axios, "post");
39+
postSpy.mockImplementation(() => Promise.resolve({ data: {} }));
40+
41+
// when
42+
await scraper.nextPaymentHistory(
43+
cookie,
44+
"order-1234",
45+
new Date().getTime() - day * 30
46+
);
47+
48+
// then
49+
expect(postSpy).toBeCalledWith(
50+
scraper.nextPaymentHistoryURL,
51+
expect.any(Object),
52+
expect.objectContaining({
53+
headers: expect.objectContaining({
54+
Cookie: cookie,
55+
}),
56+
})
57+
);
58+
});
59+
});
2760
});

src/app/naver/scraper.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { CommonResponse } from "app/common/types/response";
22
import axios from "axios";
3+
import { ServiceGroup } from "./types/serviceGroup";
4+
import { StatusGroup } from "./types/statusGroup";
35

46
export class NaverScraper {
57
private async getTodayString() {
@@ -35,4 +37,41 @@ export class NaverScraper {
3537

3638
return { status: response.status, data: response.data as string };
3739
}
40+
41+
nextPaymentHistoryURL =
42+
"https://new-m.pay.naver.com/api/timeline/nextPaymentHistory";
43+
async nextPaymentHistory(
44+
cookie: string,
45+
lastHistoryId: string,
46+
lastHistoryDateTimestamp: number,
47+
searchOptions?: {
48+
keyword: string;
49+
serviceGroup: ServiceGroup;
50+
statusGroup: StatusGroup;
51+
}
52+
): Promise<CommonResponse> {
53+
const data = {
54+
keyword: searchOptions?.keyword || null,
55+
startDate: "2000-01-01",
56+
endDate: await this.getTodayString(),
57+
serviceGroup: searchOptions?.serviceGroup || null,
58+
statusGroup: searchOptions?.statusGroup || null,
59+
lastId: lastHistoryId,
60+
lastDate: lastHistoryDateTimestamp,
61+
};
62+
const options = {
63+
headers: {
64+
Cookie: cookie,
65+
"content-type": "application/json;charset=UTF-8",
66+
},
67+
};
68+
69+
const response = await axios.post(
70+
this.nextPaymentHistoryURL,
71+
data,
72+
options
73+
);
74+
75+
return { status: response.status, data: response.data as string };
76+
}
3877
}

0 commit comments

Comments
 (0)