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/webfontloader": "^1.6.30",
"@types/webpack-env": "^1.15.2",
"synchronous-promise": "^2.0.17",
"utility-types": "^3.10.0"
}
}

View File

@ -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');

View File

@ -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<string, any>,
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');
});

View File

@ -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"