Skip to content

Commit 5128648

Browse files
committed
(allianz) Extract example code from library
1 parent 9431db6 commit 5128648

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

allianz-example.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import puppeteer from 'puppeteer';
2+
3+
import {
4+
login,
5+
logout,
6+
getSummary,
7+
} from './allianz.js';
8+
9+
const {
10+
ALLIANZ_USERNAME,
11+
ALLIANZ_PASSWORD,
12+
ALLIANZ_SECURITY_IMAGE_SUBSTR,
13+
PUPPETEER_HEADLESS = 'true',
14+
} = process.env;
15+
16+
async function main() {
17+
if (!ALLIANZ_USERNAME) {
18+
console.error(`ALLIANZ_USERNAME was not set!`);
19+
process.exit(1);
20+
}
21+
22+
if (!ALLIANZ_PASSWORD) {
23+
console.error(`ALLIANZ_PASSWORD was not set!`);
24+
process.exit(1);
25+
}
26+
27+
if (!ALLIANZ_SECURITY_IMAGE_SUBSTR) {
28+
console.error(`ALLIANZ_SECURITY_IMAGE_SUBSTR was not set!`);
29+
process.exit(1);
30+
}
31+
32+
const browser = await puppeteer.launch({
33+
headless: PUPPETEER_HEADLESS === 'true',
34+
});
35+
const page = await browser.newPage();
36+
37+
await login(page, ALLIANZ_USERNAME, ALLIANZ_PASSWORD, ALLIANZ_SECURITY_IMAGE_SUBSTR);
38+
39+
const summary = await getSummary(page);
40+
41+
console.log('Allianz summary:', summary);
42+
43+
await logout(page);
44+
await browser.close();
45+
}
46+
47+
(async () => {
48+
await main();
49+
})();

allianz.js

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import puppeteer from 'puppeteer';
2-
31
import { sanitize } from './helpers.js';
42

5-
const {
6-
ALLIANZ_USERNAME,
7-
ALLIANZ_PASSWORD,
8-
ALLIANZ_SECURITY_IMAGE_SUBSTR,
9-
PUPPETEER_HEADLESS = 'true',
10-
} = process.env;
11-
123
const urls = {
134
home: 'https://clientes.allianz.com.mx/',
145
};
@@ -55,37 +46,8 @@ async function getSummary(page) {
5546
};
5647
}
5748

58-
async function main() {
59-
if (!ALLIANZ_USERNAME) {
60-
console.error(`ALLIANZ_USERNAME was not set!`);
61-
process.exit(1);
62-
}
63-
64-
if (!ALLIANZ_PASSWORD) {
65-
console.error(`ALLIANZ_PASSWORD was not set!`);
66-
process.exit(1);
67-
}
68-
69-
if (!ALLIANZ_SECURITY_IMAGE_SUBSTR) {
70-
console.error(`ALLIANZ_SECURITY_IMAGE_SUBSTR was not set!`);
71-
process.exit(1);
72-
}
73-
74-
const browser = await puppeteer.launch({
75-
headless: PUPPETEER_HEADLESS === 'true',
76-
});
77-
const page = await browser.newPage();
78-
79-
await login(page, ALLIANZ_USERNAME, ALLIANZ_PASSWORD, ALLIANZ_SECURITY_IMAGE_SUBSTR);
80-
81-
const summary = await getSummary(page);
82-
83-
console.log('Allianz summary:', summary);
84-
85-
await logout(page);
86-
await browser.close();
87-
}
88-
89-
(async () => {
90-
await main();
91-
})();
49+
export {
50+
login,
51+
logout,
52+
getSummary,
53+
};

0 commit comments

Comments
 (0)