From 38ad5b90e87cb05fdf7f8612272a0ba8efc348a2 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Tue, 23 Apr 2024 23:03:00 +0300 Subject: [PATCH] test(e2e): handle 2fa gracefully --- e2e/node/ts/tests/01.auth.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/e2e/node/ts/tests/01.auth.ts b/e2e/node/ts/tests/01.auth.ts index 25813073..1c4b7e6e 100644 --- a/e2e/node/ts/tests/01.auth.ts +++ b/e2e/node/ts/tests/01.auth.ts @@ -1,7 +1,7 @@ import { expect } from 'chai' import { describe, it } from 'mocha' -import { MtUnsupportedError } from '@mtcute/core' +import { MtcuteError } from '@mtcute/core' import { BaseTelegramClient, TelegramClient } from '@mtcute/core/client.js' import { getApiParams } from '../utils.js' @@ -32,10 +32,13 @@ describe('1. authorization', function () { code: () => '22222', }) } catch (e) { - if (e instanceof MtUnsupportedError && e.message.includes('Signup is no longer supported')) { + if (e instanceof MtcuteError && e.message.match(/Signup is no longer supported|2FA is enabled/)) { // retry with another number continue - } else throw e + } else { + await tg.close() + throw e + } } await tg.close() @@ -64,10 +67,13 @@ describe('1. authorization', function () { code: () => '11111', }) } catch (e) { - if (e instanceof MtUnsupportedError && e.message.includes('Signup is no longer supported')) { + if (e instanceof MtcuteError && e.message.match(/Signup is no longer supported|2FA is enabled/)) { // retry with another number continue - } else throw e + } else { + await tg.close() + throw e + } } await tg.close()