Some tests progress [skip ci]

This commit is contained in:
ErickSkrauch 2024-12-23 12:33:41 +01:00
parent be08857edc
commit a6932255b0
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
7 changed files with 106 additions and 134 deletions

View File

@ -88,9 +88,13 @@ describe('components/auth/actions', () => {
[
setOAuthRequest({
params: {
userCode: '',
clientId: '',
redirectUrl: '',
responseType: '',
state: '',
scope: '',
},
prompt: 'none',
prompt: ['none'],
loginHint: undefined,
}),
],
@ -117,7 +121,7 @@ describe('components/auth/actions', () => {
return callThunk(oAuthComplete).then(() => {
expect(request.post, 'to have a call satisfying', [
'/api/oauth2/v1/complete?client_id=&redirect_uri=&response_type=&description=&scope=&prompt=none&login_hint=&state=',
'/api/oauth2/v1/complete?client_id=&redirect_uri=&response_type=&scope=&state=',
{},
]);
});

View File

@ -481,10 +481,11 @@ interface SetOauthAction extends ReduxAction {
payload: OAuthState | null;
}
type SetOauthRequestPayload = Pick<OAuthState, 'params' | 'description' | 'loginHint' | 'prompt'>;
// Input data is coming right from the query string, so the names
// are the same, as used for initializing OAuth2 request
// TODO: filter out allowed properties
export function setOAuthRequest(payload: OAuthState | null): SetOauthAction {
export function setOAuthRequest(payload: SetOauthRequestPayload | null): SetOauthAction {
return {
type: 'set_oauth',
payload,

View File

@ -15,7 +15,7 @@ export default class DeviceCodeBody extends BaseAuthBody {
<>
{this.renderErrors()}
<Message id="deviceCode" defaultMessage="Device Code">
<Message id="enterDeviceCode" defaultMessage="Enter Device Code">
{(nodes) => (
<Input
{...this.bindField('user_code')}

View File

@ -1,62 +0,0 @@
import React from 'react';
import sinon from 'sinon';
import uxpect from 'app/test/unexpected';
import { render, screen } from '@testing-library/react';
import authFlow from 'app/services/authFlow';
import AuthFlowRouteContents from './AuthFlowRouteContents';
describe('AuthFlowRouteContents', () => {
beforeEach(() => {
sinon.stub(authFlow, 'handleRequest');
});
afterEach(() => {
(authFlow.handleRequest as any).restore();
});
let componentProps: { [key: string]: any };
function Component(props: { [key: string]: any }) {
componentProps = props;
return <div data-testid="test-component" />;
}
it('should render component if route allowed', () => {
const authRequest = {
path: '/path',
params: { foo: 1 },
query: new URLSearchParams(),
};
const routerProps: any = {
location: {
pathname: authRequest.path,
search: '',
query: new URLSearchParams(),
},
match: {
params: authRequest.params,
},
};
(authFlow.handleRequest as any).callsArg(2);
render(<AuthFlowRouteContents component={Component} {...routerProps} />);
const component = screen.getByTestId('test-component');
uxpect(authFlow.handleRequest, 'to have a call satisfying', [
{
...authRequest,
query: uxpect.it('to be a', URLSearchParams),
},
uxpect.it('to be a function'),
uxpect.it('to be a function'),
]);
expect(component).toBeInTheDocument();
uxpect(componentProps, 'to equal', routerProps);
});
});

View File

@ -14,6 +14,7 @@ import ResendActivationState from 'app/services/authFlow/ResendActivationState';
import LoginState from 'app/services/authFlow/LoginState';
import CompleteState from 'app/services/authFlow/CompleteState';
import ChooseAccountState from 'app/services/authFlow/ChooseAccountState';
import FinishState from 'app/services/authFlow/FinishState';
import { Store } from 'redux';
describe('AuthFlow', () => {
@ -211,11 +212,6 @@ describe('AuthFlow', () => {
expect(actual, 'to be', expected);
});
it('should throw if no state', () => {
// @ts-ignore
expect(() => flow.setState(), 'to throw', 'State is required');
});
});
describe('#run', () => {
@ -313,7 +309,7 @@ describe('AuthFlow', () => {
'/accept-rules': LoginState,
'/oauth/permissions': LoginState,
'/oauth/choose-account': LoginState,
'/oauth/finish': LoginState,
'/oauth/finish': FinishState,
'/oauth2/v1/foo': InitOAuthAuthCodeFlowState,
'/oauth2/v1': InitOAuthAuthCodeFlowState,
'/oauth2': InitOAuthAuthCodeFlowState,

View File

@ -137,7 +137,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
code: 'XXX',
},
},
@ -157,7 +159,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
acceptRequired: true,
},
},
@ -176,7 +180,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: ['consent'],
},
},
@ -202,7 +208,9 @@ describe('CompleteState', () => {
credentials: {},
isSwitcherEnabled: true,
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
@ -227,7 +235,9 @@ describe('CompleteState', () => {
isSwitcherEnabled: true,
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
@ -251,13 +261,15 @@ describe('CompleteState', () => {
isSwitcherEnabled: false,
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
});
expectRun(mock, 'oAuthComplete', {}).returns({ then() {} });
expectRun(mock, 'oAuthComplete', {}).returns(Promise.resolve());
state.enter(context);
});
@ -275,7 +287,9 @@ describe('CompleteState', () => {
isSwitcherEnabled: true,
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: ['select_account'],
},
},
@ -299,13 +313,15 @@ describe('CompleteState', () => {
isSwitcherEnabled: false,
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: ['select_account'],
},
},
});
expectRun(mock, 'oAuthComplete', {}).returns({ then() {} });
expectRun(mock, 'oAuthComplete', {}).returns(Promise.resolve());
state.enter(context);
});
@ -322,15 +338,15 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
});
expectRun(mock, 'oAuthComplete', sinon.match.object).returns({
then() {},
});
expectRun(mock, 'oAuthComplete', sinon.match.object).returns(Promise.resolve());
state.enter(context);
});
@ -343,7 +359,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
@ -370,7 +388,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
@ -399,7 +419,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
@ -447,7 +469,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
loginHint: account[field],
prompt: [],
},
@ -485,7 +509,9 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
loginHint: account.id,
prompt: [],
},
@ -518,16 +544,16 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
loginHint: account.id,
prompt: [],
},
},
});
expectRun(mock, 'oAuthComplete', {}).returns({
then: () => Promise.resolve(),
});
expectRun(mock, 'oAuthComplete', {}).returns(Promise.resolve());
return expect(state.enter(context), 'to be fulfilled');
});
@ -560,16 +586,15 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
});
mock.expects('run')
.once()
.withExactArgs('oAuthComplete', sinon.match(expected))
.returns({ then() {} });
mock.expects('run').once().withExactArgs('oAuthComplete', sinon.match(expected)).returns(Promise.resolve());
state.enter(context);
});
@ -585,15 +610,15 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
},
},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns({
then() {},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns(Promise.resolve());
state.enter(context);
});
@ -611,16 +636,16 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
acceptRequired: true,
},
},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns({
then() {},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns(Promise.resolve());
state.enter(context);
});
@ -638,16 +663,16 @@ describe('CompleteState', () => {
auth: {
credentials: {},
oauth: {
clientId: 'ely.by',
params: {
clientId: 'ely.by',
},
prompt: [],
acceptRequired: true,
},
},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns({
then() {},
});
expectRun(mock, 'oAuthComplete', sinon.match(expected)).returns(Promise.resolve());
state.enter(context);
});

View File

@ -44,14 +44,16 @@ describe('OAuthState', () => {
mock,
'oAuthValidate',
sinon.match({
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
params: {
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: query.scope,
state: query.state,
},
description: query.description,
scope: query.scope,
prompt: query.prompt,
loginHint: query.login_hint,
state: query.state,
}),
).returns({ then() {} });
@ -76,11 +78,13 @@ describe('OAuthState', () => {
mock,
'oAuthValidate',
sinon.match({
clientId,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: query.scope,
state: query.state,
params: {
clientId,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: query.scope,
state: query.state,
},
}),
).returns({ then() {} });
@ -106,11 +110,13 @@ describe('OAuthState', () => {
mock,
'oAuthValidate',
sinon.match({
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: query.scope,
state: query.state,
params: {
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: query.scope,
state: query.state,
},
}),
).returns({ then() {} });
@ -134,11 +140,13 @@ describe('OAuthState', () => {
mock,
'oAuthValidate',
sinon.match({
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: 'scope1 scope2 scope3',
state: query.state,
params: {
clientId: query.client_id,
redirectUrl: query.redirect_uri,
responseType: query.response_type,
scope: 'scope1 scope2 scope3',
state: query.state,
},
}),
).returns({ then() {} });