Skip to content

Commit 57546cb

Browse files
authored
Merge pull request #3 from code-yeongyu/injectable
`URLChanger` 의 URL 들이 쉽게 변경 가능 하도록 property 로 변경합니다.
2 parents e5c9aec + 11d0294 commit 57546cb

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trackpurchase",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"main": "src/index.ts",
55
"license": "MIT",
66
"repository": {
@@ -20,7 +20,10 @@
2020
],
2121
"jest": {
2222
"preset": "jest-puppeteer",
23-
"coveragePathIgnorePatterns": ["dist/", "elementParser.ts"]
23+
"coveragePathIgnorePatterns": [
24+
"dist/",
25+
"elementParser.ts"
26+
]
2427
},
2528
"scripts": {
2629
"test": "jest .",

src/app/naver/pageInteractor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class PageInteractor {
88
this.page = page;
99
}
1010

11-
async login(id: string, password: string, delay?: number) {
11+
async login(id: string, password: string, delay?: number, loginURL?: string) {
1212
await Promise.all([
1313
this.page.waitForSelector("#id"),
1414
this.page.waitForSelector("#pw"),
@@ -24,7 +24,11 @@ export default class PageInteractor {
2424
this.page.waitForNavigation({ waitUntil: "networkidle2" }),
2525
]);
2626

27-
if (this.page.url().includes("https://nid.naver.com/nidlogin.login")) {
27+
if (
28+
this.page
29+
.url()
30+
.includes(loginURL || "https://nid.naver.com/nidlogin.login")
31+
) {
2832
throw new Error("Login failed");
2933
}
3034
}

src/app/naver/urlChanger.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ describe("Login", () => {
1010
await urlChanger.moveToLoginURL();
1111

1212
// then
13-
expect(pageSpy).toHaveBeenCalledWith(
14-
"https://nid.naver.com/nidlogin.login"
15-
);
13+
expect(pageSpy).toHaveBeenCalledWith(urlChanger.loginURL);
1614
});
1715
});
1816

@@ -28,8 +26,6 @@ describe("PaymentHistory", () => {
2826
await urlChanger.moveToPaymentHistoryURL();
2927

3028
// then
31-
expect(pageSpy).toHaveBeenCalledWith(
32-
"https://new-m.pay.naver.com/historybenefit/paymenthistory"
33-
);
29+
expect(pageSpy).toHaveBeenCalledWith(urlChanger.paymentHistoryURL);
3430
});
3531
});

src/app/naver/urlChanger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import puppeteer from "puppeteer";
22

33
export default class URLChanger {
44
private readonly page: puppeteer.Page;
5+
loginURL = "https://nid.naver.com/nidlogin.login";
6+
paymentHistoryURL =
7+
"https://new-m.pay.naver.com/historybenefit/paymenthistory";
58

69
constructor(page: puppeteer.Page) {
710
this.page = page;
811
}
912

1013
async moveToLoginURL() {
11-
await this.page.goto("https://nid.naver.com/nidlogin.login");
14+
await this.page.goto(this.loginURL);
1215
}
1316

1417
async moveToPaymentHistoryURL() {
15-
await this.page.goto(
16-
"https://new-m.pay.naver.com/historybenefit/paymenthistory"
17-
);
18+
await this.page.goto(this.paymentHistoryURL);
1819
await this.page.waitForSelector("div[class^='paymentHistory_section__']");
1920
}
2021
}

0 commit comments

Comments
 (0)