From cbbf9b7bb9915f51eee680042af0bcc19ad8c8ac Mon Sep 17 00:00:00 2001 From: Avraham Wales <47576381+Avrhamwales@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:11:11 +0300 Subject: [PATCH] feat: add bank pagi scraper (#880) Co-authored-by: Avraham wales --- src/definitions.ts | 5 ++++ src/scrapers/factory.ts | 3 ++ src/scrapers/pagi.test.ts | 50 ++++++++++++++++++++++++++++++++++ src/scrapers/pagi.ts | 12 ++++++++ src/tests/.tests-config.tpl.js | 3 +- 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/scrapers/pagi.test.ts create mode 100644 src/scrapers/pagi.ts diff --git a/src/definitions.ts b/src/definitions.ts index a1c9dad0..5ad678af 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -22,6 +22,7 @@ export enum CompanyTypes { behatsdaa = 'behatsdaa', beyahadBishvilha = 'beyahadBishvilha', oneZero = 'oneZero', + pagi = 'pagi', } export const SCRAPERS = { @@ -101,6 +102,10 @@ export const SCRAPERS = { name: 'Behatsdaa', loginFields: ['id', PASSWORD_FIELD], }, + [CompanyTypes.pagi]: { + name: 'Pagi', + loginFields: ['username', PASSWORD_FIELD], + }, }; export enum ScraperProgressTypes { diff --git a/src/scrapers/factory.ts b/src/scrapers/factory.ts index ca2258fc..c82c9436 100644 --- a/src/scrapers/factory.ts +++ b/src/scrapers/factory.ts @@ -15,6 +15,7 @@ import MercantileScraper from './mercantile'; import MizrahiScraper from './mizrahi'; import OneZeroScraper from './one-zero'; import OtsarHahayalScraper from './otsar-hahayal'; +import PagiScraper from './pagi'; import UnionBankScraper from './union-bank'; import VisaCalScraper from './visa-cal'; import YahavScraper from './yahav'; @@ -63,6 +64,8 @@ export default function createScraper(options: ScraperOptions): Scraper { + beforeAll(() => { + extendAsyncTimeout(); // The default timeout is 5 seconds per async test, this function extends the timeout value + }); + test('should expose login fields in scrapers constant', () => { + expect(SCRAPERS.pagi).toBeDefined(); + expect(SCRAPERS.pagi.loginFields).toContain('username'); + expect(SCRAPERS.pagi.loginFields).toContain('password'); + }); + + maybeTestCompanyAPI(COMPANY_ID, (config) => config.companyAPI.invalidPassword)('should fail on invalid user/password"', async () => { + const options = { + ...testsConfig.options, + companyId: COMPANY_ID, + }; + + const scraper = new PagiScraper(options); + + const result = await scraper.scrape({ username: 'e10s12', password: '3f3ss3d' }); + + expect(result).toBeDefined(); + expect(result.success).toBeFalsy(); + expect(result.errorType).toBe(LoginResults.InvalidPassword); + }); + + maybeTestCompanyAPI(COMPANY_ID)('should scrape transactions"', async () => { + const options = { + ...testsConfig.options, + companyId: COMPANY_ID, + }; + + const scraper = new PagiScraper(options); + const result = await scraper.scrape(testsConfig.credentials.pagi); + expect(result).toBeDefined(); + const error = `${result.errorType || ''} ${result.errorMessage || ''}`.trim(); + expect(error).toBe(''); + expect(result.success).toBeTruthy(); + + exportTransactions(COMPANY_ID, result.accounts || []); + }); +}); \ No newline at end of file diff --git a/src/scrapers/pagi.ts b/src/scrapers/pagi.ts new file mode 100644 index 00000000..90df8bc7 --- /dev/null +++ b/src/scrapers/pagi.ts @@ -0,0 +1,12 @@ +import BeinleumiGroupBaseScraper from './base-beinleumi-group'; + +class PagiScraper extends BeinleumiGroupBaseScraper { + BASE_URL = 'https://online.pagi.co.il/'; + + LOGIN_URL = `${this.BASE_URL}/MatafLoginService/MatafLoginServlet?bankId=PAGIPORTAL&site=Private&KODSAFA=HE`; + + TRANSACTIONS_URL = `${this.BASE_URL}/wps/myportal/FibiMenu/Online/OnAccountMngment/OnBalanceTrans/PrivateAccountFlow`; + +} + +export default PagiScraper; \ No newline at end of file diff --git a/src/tests/.tests-config.tpl.js b/src/tests/.tests-config.tpl.js index 35771254..507a0bea 100644 --- a/src/tests/.tests-config.tpl.js +++ b/src/tests/.tests-config.tpl.js @@ -28,7 +28,8 @@ module.exports = { // yahav: {username: '', nationalID: '', password: ''} // beyahadBishvilha: { id: '', password: ''}, // behatsdaa: { id: '', password: ''}, - // oneZero: { email: '', password: '', otpCode: '', otpToken: null } + // oneZero: { email: '', password: '', otpCode: '', otpToken: null }, + // pagi: { username: '', password: ''}, }, companyAPI: { // enable companyAPI to execute tests against the real companies api enabled: true,