Some tests progress [skip ci]

This commit is contained in:
ErickSkrauch
2024-12-23 12:33:41 +01:00
parent be08857edc
commit a6932255b0
7 changed files with 106 additions and 134 deletions

View File

@@ -88,9 +88,13 @@ describe('components/auth/actions', () => {
[ [
setOAuthRequest({ setOAuthRequest({
params: { params: {
userCode: '', clientId: '',
redirectUrl: '',
responseType: '',
state: '',
scope: '',
}, },
prompt: 'none', prompt: ['none'],
loginHint: undefined, loginHint: undefined,
}), }),
], ],
@@ -117,7 +121,7 @@ describe('components/auth/actions', () => {
return callThunk(oAuthComplete).then(() => { return callThunk(oAuthComplete).then(() => {
expect(request.post, 'to have a call satisfying', [ 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; payload: OAuthState | null;
} }
type SetOauthRequestPayload = Pick<OAuthState, 'params' | 'description' | 'loginHint' | 'prompt'>;
// Input data is coming right from the query string, so the names // Input data is coming right from the query string, so the names
// are the same, as used for initializing OAuth2 request // are the same, as used for initializing OAuth2 request
// TODO: filter out allowed properties export function setOAuthRequest(payload: SetOauthRequestPayload | null): SetOauthAction {
export function setOAuthRequest(payload: OAuthState | null): SetOauthAction {
return { return {
type: 'set_oauth', type: 'set_oauth',
payload, payload,

View File

@@ -15,7 +15,7 @@ export default class DeviceCodeBody extends BaseAuthBody {
<> <>
{this.renderErrors()} {this.renderErrors()}
<Message id="deviceCode" defaultMessage="Device Code"> <Message id="enterDeviceCode" defaultMessage="Enter Device Code">
{(nodes) => ( {(nodes) => (
<Input <Input
{...this.bindField('user_code')} {...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 LoginState from 'app/services/authFlow/LoginState';
import CompleteState from 'app/services/authFlow/CompleteState'; import CompleteState from 'app/services/authFlow/CompleteState';
import ChooseAccountState from 'app/services/authFlow/ChooseAccountState'; import ChooseAccountState from 'app/services/authFlow/ChooseAccountState';
import FinishState from 'app/services/authFlow/FinishState';
import { Store } from 'redux'; import { Store } from 'redux';
describe('AuthFlow', () => { describe('AuthFlow', () => {
@@ -211,11 +212,6 @@ describe('AuthFlow', () => {
expect(actual, 'to be', expected); expect(actual, 'to be', expected);
}); });
it('should throw if no state', () => {
// @ts-ignore
expect(() => flow.setState(), 'to throw', 'State is required');
});
}); });
describe('#run', () => { describe('#run', () => {
@@ -313,7 +309,7 @@ describe('AuthFlow', () => {
'/accept-rules': LoginState, '/accept-rules': LoginState,
'/oauth/permissions': LoginState, '/oauth/permissions': LoginState,
'/oauth/choose-account': LoginState, '/oauth/choose-account': LoginState,
'/oauth/finish': LoginState, '/oauth/finish': FinishState,
'/oauth2/v1/foo': InitOAuthAuthCodeFlowState, '/oauth2/v1/foo': InitOAuthAuthCodeFlowState,
'/oauth2/v1': InitOAuthAuthCodeFlowState, '/oauth2/v1': InitOAuthAuthCodeFlowState,
'/oauth2': InitOAuthAuthCodeFlowState, '/oauth2': InitOAuthAuthCodeFlowState,

View File

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

View File

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