Skip to content

Commit

Permalink
feat: Support Visa Cal change password flow (eshaham#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaham authored Mar 31, 2024
1 parent 7bdcfd0 commit 71262d4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/scrapers/visa-cal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ async function hasInvalidPasswordError(page: Page) {
return errorMessage === InvalidPasswordMessage;
}

async function hasChangePasswordForm(page: Page) {
const frame = await getLoginFrame(page);
const errorFound = await elementPresentOnPage(frame, '.change-password-subtitle');
return errorFound;
}

function getPossibleLoginResults() {
debug('return possible login results');
const urls: LoginOptions['possibleResults'] = {
Expand All @@ -162,7 +168,13 @@ function getPossibleLoginResults() {
return hasInvalidPasswordError(page);
}],
// [LoginResults.AccountBlocked]: [], // TODO add when reaching this scenario
// [LoginResults.ChangePassword]: [], // TODO add when reaching this scenario
[LoginResults.ChangePassword]: [async (options?: { page?: Page }) => {
const page = options?.page;
if (!page) {
return false;
}
return hasChangePasswordForm(page);
}],
};
return urls;
}
Expand Down Expand Up @@ -303,6 +315,8 @@ class VisaCalScraper extends BaseScraperWithBrowser<ScraperSpecificCredentials>
} catch (e) {
const currentUrl = await getCurrentUrl(this.page);
if (currentUrl.endsWith('dashboard')) return;
const requiresChangePassword = await hasChangePasswordForm(this.page);
if (requiresChangePassword) return;
throw e;
}
},
Expand Down

0 comments on commit 71262d4

Please sign in to comment.