Fix unit tests

This commit is contained in:
ErickSkrauch 2024-12-23 14:53:49 +01:00
parent a6932255b0
commit cf5973c876
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
4 changed files with 19 additions and 39 deletions

View File

@ -49,6 +49,7 @@
"@types/rtl-detect": "^1.0.0", "@types/rtl-detect": "^1.0.0",
"@types/webfontloader": "^1.6.30", "@types/webfontloader": "^1.6.30",
"@types/webpack-env": "^1.15.2", "@types/webpack-env": "^1.15.2",
"synchronous-promise": "^2.0.17",
"utility-types": "^3.10.0" "utility-types": "^3.10.0"
} }
} }

View File

@ -1,5 +1,6 @@
import expect from 'app/test/unexpected'; import expect from 'app/test/unexpected';
import sinon from 'sinon'; import sinon from 'sinon';
import { SynchronousPromise } from 'synchronous-promise';
import { Store } from 'redux'; import { Store } from 'redux';
@ -100,21 +101,22 @@ describe('AuthFlow.functional', () => {
auth: { auth: {
credentials: {}, credentials: {},
oauth: { oauth: {
params: {
clientId: 123, clientId: 123,
},
prompt: [], prompt: [],
}, },
}, },
}); });
// @ts-ignore // @ts-ignore
flow.run.onCall(0).returns({ then: (fn) => fn() }); flow.run.onCall(0).returns(SynchronousPromise.resolve());
// @ts-ignore // @ts-ignore
flow.run.onCall(1).returns({ flow.run.onCall(1).returns(
then: (fn: Function) => SynchronousPromise.resolve({
fn({
redirectUri: expectedRedirect, redirectUri: expectedRedirect,
}), }),
}); );
navigate('/oauth2'); navigate('/oauth2');

View File

@ -1,5 +1,6 @@
import expect from 'app/test/unexpected'; import expect from 'app/test/unexpected';
import sinon, { SinonMock } from 'sinon'; import sinon, { SinonMock } from 'sinon';
import { SynchronousPromise } from 'synchronous-promise';
import CompleteState from 'app/services/authFlow/CompleteState'; import CompleteState from 'app/services/authFlow/CompleteState';
import LoginState from 'app/services/authFlow/LoginState'; import LoginState from 'app/services/authFlow/LoginState';
@ -351,32 +352,6 @@ describe('CompleteState', () => {
state.enter(context); 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', () => { it('should run redirect by default', () => {
const expectedUrl = 'foo/bar'; const expectedUrl = 'foo/bar';
const promise = Promise.resolve({ redirectUri: expectedUrl }); const promise = Promise.resolve({ redirectUri: expectedUrl });
@ -409,8 +384,7 @@ describe('CompleteState', () => {
resp: Record<string, any>, resp: Record<string, any>,
expectedInstance: typeof AbstractState, expectedInstance: typeof AbstractState,
) => { ) => {
// @ts-ignore const promise = SynchronousPromise[type](resp);
const promise = Promise[type](resp);
context.getState.returns({ context.getState.returns({
user: { user: {
@ -519,9 +493,7 @@ describe('CompleteState', () => {
}); });
expectRun(mock, 'setAccountSwitcher', false); expectRun(mock, 'setAccountSwitcher', false);
expectRun(mock, 'oAuthComplete', {}).returns({ expectRun(mock, 'oAuthComplete', {}).returns(SynchronousPromise.resolve());
then: () => Promise.resolve(),
});
return expect(state.enter(context), 'to be fulfilled'); return expect(state.enter(context), 'to be fulfilled');
}); });

View File

@ -13829,6 +13829,11 @@ symbol.prototype.description@^1.0.0:
has-symbols "^1.0.1" has-symbols "^1.0.1"
object.getownpropertydescriptors "^2.1.2" 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: table@^6.0.9:
version "6.7.1" version "6.7.1"
resolved "https://registry.yarnpkg.com/table/-/table-6.7.1.tgz#ee05592b7143831a8c94f3cee6aae4c1ccef33e2" resolved "https://registry.yarnpkg.com/table/-/table-6.7.1.tgz#ee05592b7143831a8c94f3cee6aae4c1ccef33e2"