test(e2e): handle 2fa gracefully

This commit is contained in:
alina 🌸 2024-04-23 23:03:00 +03:00
parent 7ad3ddbc0c
commit 38ad5b90e8
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -1,7 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import { describe, it } from 'mocha' import { describe, it } from 'mocha'
import { MtUnsupportedError } from '@mtcute/core' import { MtcuteError } from '@mtcute/core'
import { BaseTelegramClient, TelegramClient } from '@mtcute/core/client.js' import { BaseTelegramClient, TelegramClient } from '@mtcute/core/client.js'
import { getApiParams } from '../utils.js' import { getApiParams } from '../utils.js'
@ -32,10 +32,13 @@ describe('1. authorization', function () {
code: () => '22222', code: () => '22222',
}) })
} catch (e) { } 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 // retry with another number
continue continue
} else throw e } else {
await tg.close()
throw e
}
} }
await tg.close() await tg.close()
@ -64,10 +67,13 @@ describe('1. authorization', function () {
code: () => '11111', code: () => '11111',
}) })
} catch (e) { } 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 // retry with another number
continue continue
} else throw e } else {
await tg.close()
throw e
}
} }
await tg.close() await tg.close()