From cf5973c8767f22eaacc7eec6eb22a1957f226bef Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 23 Dec 2024 14:53:49 +0100 Subject: [PATCH] Fix unit tests --- packages/app/package.json | 1 + .../authFlow/AuthFlow.functional.test.ts | 18 +++++----- .../services/authFlow/CompleteState.test.ts | 34 ++----------------- yarn.lock | 5 +++ 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index b733761..9562ddb 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -49,6 +49,7 @@ "@types/rtl-detect": "^1.0.0", "@types/webfontloader": "^1.6.30", "@types/webpack-env": "^1.15.2", + "synchronous-promise": "^2.0.17", "utility-types": "^3.10.0" } } diff --git a/packages/app/services/authFlow/AuthFlow.functional.test.ts b/packages/app/services/authFlow/AuthFlow.functional.test.ts index 376b379..16f6fdd 100644 --- a/packages/app/services/authFlow/AuthFlow.functional.test.ts +++ b/packages/app/services/authFlow/AuthFlow.functional.test.ts @@ -1,5 +1,6 @@ import expect from 'app/test/unexpected'; import sinon from 'sinon'; +import { SynchronousPromise } from 'synchronous-promise'; import { Store } from 'redux'; @@ -100,21 +101,22 @@ describe('AuthFlow.functional', () => { auth: { credentials: {}, oauth: { - clientId: 123, + params: { + clientId: 123, + }, prompt: [], }, }, }); // @ts-ignore - flow.run.onCall(0).returns({ then: (fn) => fn() }); + flow.run.onCall(0).returns(SynchronousPromise.resolve()); // @ts-ignore - flow.run.onCall(1).returns({ - then: (fn: Function) => - fn({ - redirectUri: expectedRedirect, - }), - }); + flow.run.onCall(1).returns( + SynchronousPromise.resolve({ + redirectUri: expectedRedirect, + }), + ); navigate('/oauth2'); diff --git a/packages/app/services/authFlow/CompleteState.test.ts b/packages/app/services/authFlow/CompleteState.test.ts index f0d625e..7cb25c3 100644 --- a/packages/app/services/authFlow/CompleteState.test.ts +++ b/packages/app/services/authFlow/CompleteState.test.ts @@ -1,5 +1,6 @@ import expect from 'app/test/unexpected'; import sinon, { SinonMock } from 'sinon'; +import { SynchronousPromise } from 'synchronous-promise'; import CompleteState from 'app/services/authFlow/CompleteState'; import LoginState from 'app/services/authFlow/LoginState'; @@ -351,32 +352,6 @@ describe('CompleteState', () => { state.enter(context); }); - it('should listen for auth success/failure', () => { - context.getState.returns({ - user: { - isGuest: false, - }, - auth: { - credentials: {}, - oauth: { - params: { - clientId: 'ely.by', - }, - prompt: [], - }, - }, - }); - - expectRun(mock, 'oAuthComplete', sinon.match.object).returns({ - then(success: Function, fail: Function) { - expect(success, 'to be a', 'function'); - expect(fail, 'to be a', 'function'); - }, - }); - - state.enter(context); - }); - it('should run redirect by default', () => { const expectedUrl = 'foo/bar'; const promise = Promise.resolve({ redirectUri: expectedUrl }); @@ -409,8 +384,7 @@ describe('CompleteState', () => { resp: Record, expectedInstance: typeof AbstractState, ) => { - // @ts-ignore - const promise = Promise[type](resp); + const promise = SynchronousPromise[type](resp); context.getState.returns({ user: { @@ -519,9 +493,7 @@ describe('CompleteState', () => { }); expectRun(mock, 'setAccountSwitcher', false); - expectRun(mock, 'oAuthComplete', {}).returns({ - then: () => Promise.resolve(), - }); + expectRun(mock, 'oAuthComplete', {}).returns(SynchronousPromise.resolve()); return expect(state.enter(context), 'to be fulfilled'); }); diff --git a/yarn.lock b/yarn.lock index aa95157..0c12799 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13829,6 +13829,11 @@ symbol.prototype.description@^1.0.0: has-symbols "^1.0.1" object.getownpropertydescriptors "^2.1.2" +synchronous-promise@^2.0.17: + version "2.0.17" + resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.17.tgz#38901319632f946c982152586f2caf8ddc25c032" + integrity sha512-AsS729u2RHUfEra9xJrE39peJcc2stq2+poBXX8bcM08Y6g9j/i/PUzwNQqkaJde7Ntg1TO7bSREbR5sdosQ+g== + table@^6.0.9: version "6.7.1" resolved "https://registry.yarnpkg.com/table/-/table-6.7.1.tgz#ee05592b7143831a8c94f3cee6aae4c1ccef33e2"