From 3dab0d01cdc9534353447204a859ac9ffad913cb Mon Sep 17 00:00:00 2001 From: Barbara Date: Mon, 17 Aug 2026 19:02:29 +0200 Subject: [PATCH] feat(2FA): remove 2FA required modal - UOD-3895 --- src/v0/iam_me.ts | 31 ----- test/iam_me/setup-2fa-action.test.ts | 175 --------------------------- 2 files changed, 206 deletions(-) delete mode 100644 test/iam_me/setup-2fa-action.test.ts diff --git a/src/v0/iam_me.ts b/src/v0/iam_me.ts index adc2c1d657a..1ec2642a742 100644 --- a/src/v0/iam_me.ts +++ b/src/v0/iam_me.ts @@ -3,7 +3,6 @@ import { Client } from '../client' import { BaseError } from '../errors/baseError' import { UriHelper } from '../uri-helper' import { ThBaseHandler } from '../base' -import { IamUser, IamUserResponse } from './iam_users' export interface IamMeClassOptions { user?: string @@ -76,26 +75,6 @@ export class IamMeClass extends ThBaseHandler { throw new IamMeFetchFailed(error.message, { error }) } } - - async setup2faActionMe (tenantId: string): Promise { - const base = this.options.base ?? 'https://api.tillhub.com' - const uri = `${base}${this.endpoint}/${tenantId}/reset-2fa` - - try { - const response = await this.http.getClient().post(uri) - - if (response.status !== 200) { - throw new IamMeSetup2faActionFailed(undefined, { status: response.status }) - } - return { - data: response.data.results[0] as IamUser, - msg: response.data.msg, - metadata: { count: response.data.count } - } - } catch (error: any) { - throw new IamMeSetup2faActionFailed(error.message, { error }) - } - } } export class IamMeFetchFailed extends BaseError { @@ -118,13 +97,3 @@ export class IamMeBackupCodes2faFailed extends BaseError { Object.setPrototypeOf(this, IamMeBackupCodes2faFailed.prototype) } } -export class IamMeSetup2faActionFailed extends BaseError { - public name = 'IamMeSetup2faActionFailed' - constructor ( - public message: string = 'Could not setup 2fa action', - properties?: Record - ) { - super(message, properties) - Object.setPrototypeOf(this, IamMeSetup2faActionFailed.prototype) - } -} diff --git a/test/iam_me/setup-2fa-action.test.ts b/test/iam_me/setup-2fa-action.test.ts deleted file mode 100644 index 4e95dc5c63f..00000000000 --- a/test/iam_me/setup-2fa-action.test.ts +++ /dev/null @@ -1,175 +0,0 @@ -import * as dotenv from 'dotenv' -import axios from 'axios' -import MockAdapter from 'axios-mock-adapter' -import { TillhubClient, v0 } from '../../src/tillhub-js' -dotenv.config() - -const user = { - username: 'test@example.com', - password: '12345678', - clientAccount: 'someuuid', - apiKey: '12345678' -} - -const legacyId = '4564' -const tenantId = 'abc12345' - -const mock = new MockAdapter(axios) -afterEach(() => { - mock.reset() -}) - -describe('v0: IamMeClass: can setup 2FA action for the current user', () => { - it('successfully resets 2FA', async () => { - if (process.env.SYSTEM_TEST !== 'true') { - mock.onPost('https://api.tillhub.com/api/v0/users/login').reply(() => { - return [ - 200, - { - token: '', - user: { - id: '123', - legacy_id: legacyId - } - } - ] - }) - - mock - .onPost(`https://api.tillhub.com/api/v0/iam/me/${tenantId}/reset-2fa`) - .reply(() => { - return [ - 200, - { - results: [{ - id: '123', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - username: 'test@example.com', - has2faConfigured: false - }], - msg: '2FA reset successfully', - count: 1 - } - ] - }) - } - - const options = { - credentials: { - username: user.username, - password: user.password - }, - base: process.env.TILLHUB_BASE - } - - const th = new TillhubClient() - - th.init(options) - await th.auth.loginUsername({ - username: user.username, - password: user.password - }) - - const iamMeClass = th.iamMeClass() - - expect(iamMeClass).toBeInstanceOf(v0.IamMeClass) - - const result = await iamMeClass.setup2faActionMe(tenantId) - - expect(result.data.has2faConfigured).toBe(false) - expect(result.msg).toBe('2FA reset successfully') - expect(result.metadata.count).toBe(1) - }) - - it('rejects on status codes that are not 200', async () => { - if (process.env.SYSTEM_TEST !== 'true') { - mock.onPost('https://api.tillhub.com/api/v0/users/login').reply(() => { - return [ - 200, - { - token: '', - user: { - id: '123', - legacy_id: legacyId - } - } - ] - }) - - mock - .onPost(`https://api.tillhub.com/api/v0/iam/me/${tenantId}/reset-2fa`) - .reply(() => { - return [400] - }) - } - - const options = { - credentials: { - username: user.username, - password: user.password - }, - base: process.env.TILLHUB_BASE - } - - const th = new TillhubClient() - - th.init(options) - await th.auth.loginUsername({ - username: user.username, - password: user.password - }) - - try { - await th.iamMeClass().setup2faActionMe(tenantId) - } catch (err: any) { - expect(err.name).toBe('IamMeSetup2faActionFailed') - } - }) - - it('handles server errors correctly', async () => { - if (process.env.SYSTEM_TEST !== 'true') { - mock.onPost('https://api.tillhub.com/api/v0/users/login').reply(() => { - return [ - 200, - { - token: '', - user: { - id: '123', - legacy_id: legacyId - } - } - ] - }) - - mock - .onPost(`https://api.tillhub.com/api/v0/iam/me/${tenantId}/reset-2fa`) - .reply(() => { - return [500] - }) - } - - const options = { - credentials: { - username: user.username, - password: user.password - }, - base: process.env.TILLHUB_BASE - } - - const th = new TillhubClient() - - th.init(options) - await th.auth.loginUsername({ - username: user.username, - password: user.password - }) - - try { - await th.iamMeClass().setup2faActionMe(tenantId) - } catch (err: any) { - expect(err.name).toBe('IamMeSetup2faActionFailed') - } - }) -})