Skip to content

Commit

Permalink
fix tests/lint for OV/step feature
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongranick-okta committed Jan 20, 2022
1 parent dae18ca commit f1b290b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/idx/remediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function getRemediator(
let remediator;
// remediation name specified by caller - fast-track remediator lookup
if (options.step) {
const remediation = idxRemediations.find(({ name }) => name === options.step);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const remediation = idxRemediations.find(({ name }) => name === options.step)!;
const T = remediators[remediation.name];
return new T(remediation, values);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/idx/remediators/EnrollmentChannelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type EnrollmentChannelDataValues = RemediationValues & {
export class EnrollmentChannelData extends Remediator {
static remediationName = 'enrollment-channel-data';

values: EnrollmentChannelDataValues;
values!: EnrollmentChannelDataValues;

map = {
email: [],
Expand Down
Empty file.
7 changes: 4 additions & 3 deletions lib/idx/remediators/SelectEnrollmentChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type SelectEnrollmentChannelValues = RemediationValues & {
export class SelectEnrollmentChannel extends Remediator {
static remediationName = 'select-enrollment-channel';

values: SelectEnrollmentChannelValues;
values!: SelectEnrollmentChannelValues;

canRemediate() {
return Boolean(this.values.channel);
Expand All @@ -41,14 +41,15 @@ export class SelectEnrollmentChannel extends Remediator {
};
}

private getChannels(): IdxOption[] {
private getChannels(): IdxOption[] | undefined {
const authenticator: IdxRemediationValue = getAuthenticatorFromRemediation(this.remediation);
const remediationValue = authenticator.value as IdxRemediationValueForm;
return remediationValue.form.value.find(({ name }) => name === 'channel')?.options;
}

getData() {
const remediationValue = this.remediation.value[0].value as IdxRemediationValueForm;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const remediationValue = this.remediation!.value![0].value as IdxRemediationValueForm;
return {
authenticator: {
id: remediationValue.form.value[0].value,
Expand Down
5 changes: 3 additions & 2 deletions lib/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export async function run(
actions,
withCredentials,
exchangeCodeForTokens,
autoRemediate
autoRemediate,
step
} = options;

// Only one flow can be operating at a time
Expand Down Expand Up @@ -155,7 +156,7 @@ export async function run(
terminal,
canceled,
messages: messagesFromResp,
} = await remediate(idxResponse, values, { remediators, actions, flow });
} = await remediate(idxResponse, values, { remediators, actions, flow, step });
idxResponse = idxResponseFromResp || idxResponse;

// Track fields from remediation response
Expand Down
17 changes: 12 additions & 5 deletions test/spec/idx/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1912,12 +1912,14 @@ describe('idx/register', () => {
const {
authClient,
selectAuthenticatorResponse,
successWithInteractionCodeResponse
} = testContext;

chainResponses([
selectAuthenticatorResponse,
enrollPollResponse,
enrollmentChannelDataSmsResponse,
successWithInteractionCodeResponse
]);

jest.spyOn(mocked.introspect, 'introspect')
Expand All @@ -1932,18 +1934,19 @@ describe('idx/register', () => {
await register(authClient, {
authenticator: AuthenticatorKey.OKTA_VERIFY
});
const { nextStep: { options } } = await proceed(authClient, {
let res = await proceed(authClient, {
step: 'select-enrollment-channel'
});

const { options } = res.nextStep!;
expect(options).toContainEqual({
label: 'SMS',
value: 'sms'
});

const { nextStep: { inputs } } = await proceed(authClient, {
res = await proceed(authClient, {
channel: 'phoneNumber'
});
const { inputs } = res.nextStep!;

expect(enrollPollResponse.proceed).toHaveBeenCalledWith(
'select-enrollment-channel',
Expand All @@ -1968,12 +1971,14 @@ describe('idx/register', () => {
const {
authClient,
selectAuthenticatorResponse,
successWithInteractionCodeResponse
} = testContext;

chainResponses([
selectAuthenticatorResponse,
enrollPollResponse,
enrollmentChannelDataEmailResponse,
successWithInteractionCodeResponse
]);

jest.spyOn(mocked.introspect, 'introspect')
Expand All @@ -1988,18 +1993,20 @@ describe('idx/register', () => {
await register(authClient, {
authenticator: AuthenticatorKey.OKTA_VERIFY
});
const { nextStep: { options } } = await proceed(authClient, {
let res = await proceed(authClient, {
step: 'select-enrollment-channel'
});
const { options } = res.nextStep!;

expect(options).toContainEqual({
label: 'EMAIL',
value: 'email'
});

const { nextStep: { inputs } } = await proceed(authClient, {
res = await proceed(authClient, {
channel: 'email'
});
const { inputs } = res.nextStep!;

expect(enrollPollResponse.proceed).toHaveBeenCalledWith(
'select-enrollment-channel',
Expand Down

0 comments on commit f1b290b

Please sign in to comment.