Skip to content

fix(davinci-client): event-name-and-formData #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-parents-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@forgerock/davinci-client': patch
---

add continue as a fallback when an eventName isn't provided and dont include undefined keys in the formData
13 changes: 13 additions & 0 deletions e2e/davinci-suites/src/form-fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,17 @@ test('should render form validation fields', async ({ page }) => {

await page.getByRole('textbox', { name: 'Email Address' }).fill('[email protected]');
await expect(page.getByText('Not a valid email')).not.toBeVisible();

await page.getByRole('textbox', { name: 'Password' }).fill('1234');

const requestPromise = page.waitForRequest((request) => request.url().includes('/customForm'));
await page.getByRole('button', { name: 'Submit' }).click();

const request = await requestPromise;

expect(request.postDataJSON().parameters.data.formData).toEqual({
'user.username': '',
'user.email': '[email protected]',
'user.password': '1234',
});
});
23 changes: 16 additions & 7 deletions packages/davinci-client/src/lib/collector.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,22 @@ export function returnSingleValueCollector<
value: '',
type: field.type,
},
output: {
key: field.key,
label: field.label,
type: field.type,
value: data || '',
options: options,
},
output:
field.key !== undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we should do this. If there's no key property, there's something fundamentally wrong with the data. If this is a SingleValueCollector, it requires a key in order to send the value back to the server. Without a key, we can't assign the collected value to something and the whole flow will break.

? {
key: field.key,
label: field.label,
type: field.type,
value: data || '',
options: options,
// No default or existing value is passed
}
: {
label: field.label,
type: field.type,
value: data || '',
options: options,
},
} as InferSingleValueCollectorType<'SingleSelectCollector'>;
} else if ('validation' in field || 'required' in field) {
const validationArray = [];
Expand Down
20 changes: 20 additions & 0 deletions packages/davinci-client/src/lib/davinci.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { next0 } from './mock-data/davinci.next.mock.js';
import { DaVinciCacheEntry } from './davinci.types.js';
import { error0a, error3 } from './mock-data/davinci.error.mock.js';
import { success0 } from './mock-data/davinci.success.mock.js';
import { nodeNext1 } from './mock-data/node.next.mock.js';

describe('transformSubmitRequest', () => {
it('should transform node state to DaVinciRequest for next request', () => {
Expand Down Expand Up @@ -327,4 +328,23 @@ describe('handleResponse', () => {
const [action] = dispatch.mock.calls[0];
expect(action.type).toBe('node/failure');
});
it('should transformSubmitRequest', () => {
const n = nodeNext1 as ContinueNode;
const result = transformSubmitRequest(n);
expect(result).toEqual({
eventName: 'continue',
id: 'elvr5pbwzn',
interactionId: '03534806-abbc-4f43-a9b1-8bdba1a57765',
parameters: {
data: {
actionKey: 'submit',
formData: {
'user.password': '',
'user.username': '',
},
},
eventType: 'submit',
},
});
});
});
4 changes: 3 additions & 1 deletion packages/davinci-client/src/lib/davinci.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function transformSubmitRequest(node: ContinueNode): DaVinciRequest {
const formData = collectors?.reduce<{
[key: string]: string | number | boolean | (string | number | boolean)[];
}>((acc, collector) => {
acc[collector.input.key] = collector.input.value;
if (collector.input.key !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we need this. If we are filtering by category, and no collector within these categories should have an undefined, did we get something wrong?

acc[collector.input.key] = collector.input.value;
}
return acc;
}, {});

Expand Down
65 changes: 65 additions & 0 deletions packages/davinci-client/src/lib/mock-data/davinci.next.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,68 @@ export const next3 = {
},
},
};

export const next4 = {
interactionId: '03534806-abbc-4f43-a9b1-8bdba1a57765',
companyId: '490b9f38-f20b-4afa-b02e-3cc1315e29ab',
connectionId: '8209285e0d2f3fc76bfd23fd10d45e6f',
connectorId: 'api',
id: 'elvr5pbwzn',
capabilityName: 'customForm',
enablePolling: false,
pollInterval: '2000',
pollRetries: '60',
pollChallengeStatus: true,
form: {
components: {
fields: [
{
type: 'ERROR_DISPLAY',
},
{
type: 'LABEL',
content:
'<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis.</p>',
},
{
type: 'TEXT',
key: 'user.username',
label: 'Enter your Email Address',
required: true,
},
{
type: 'PASSWORD',
key: 'user.password',
label: 'Enter your Password',
required: true,
},
{
type: 'SUBMIT_BUTTON',
label: 'Sign On',
key: 'submit',
},
],
},
name: 'SDK - Sign On',
description: 'This is an out-of-the-box sign on form that prompts for username and password.',
category: 'CUSTOM_FORM',
},
enableMagicLinkAuthentication: true,
nodeTitle: 'Sign On',
nodeDescription: 'P1 Form - SignOn',
envId: '490b9f38-f20b-4afa-b02e-3cc1315e29ab',
formId: 'cc713951-1ff3-4c77-8b33-cf91690f0c07',
isResponseCompatibleWithMobileAndWebSdks: true,
_links: {
next: {
href: 'https://auth.pingone.com/490b9f38-f20b-4afa-b02e-3cc1315e29ab/davinci/connections/8209285e0d2f3fc76bfd23fd10d45e6f/capabilities/customForm',
},
self: {
href: 'https://auth.pingone.com/490b9f38-f20b-4afa-b02e-3cc1315e29ab/davinci/policy/c233870943cbaa6ff1a021622d074842/start',
},
},
interactionToken:
'460b6e374ff40f453eb83e3cf3da33d289538371e293df51afde06dab7ae37963234bb7bac201160b53857e49bdf245367c719ad087efc6d95fa09df4ad3d1bb94b75e1c49d72bd948eddf3a8aff9ebcb4d7a8212741d8d41abb010dd75d26e4d246ef0cea0e2550dc6fbbe36a4492105b28c33f39325291a596cd1ad77cbf95',
success: true,
startUiSubFlow: true,
};
118 changes: 118 additions & 0 deletions packages/davinci-client/src/lib/mock-data/node.next.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,121 @@ export const nodeNext0 = {
status: 'continue',
httpStatus: 200,
};

export const nodeNext1 = {
cache: {
key: '1234',
},
client: {
action: 'submit',
collectors: [
{
category: 'SingleValueCollector',
error: 'Key is not found in the field object. Label is not found in the field object. ',
id: 'undefined-0',
input: {
key: undefined,
type: 'ERROR_DISPLAY',
value: '',
},
name: undefined,
output: {
key: undefined,
label: undefined,
type: 'ERROR_DISPLAY',
value: '',
},
type: 'SingleValueCollector',
},
{
category: 'NoValueCollector',
error: null,
id: 'LABEL-1',
name: 'LABEL-1',
output: {
key: 'LABEL-1',
label:
'<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis.</p>',
type: 'LABEL',
},
type: 'ReadOnlyCollector',
},
{
category: 'ValidatedSingleValueCollector',
error: null,
id: 'user.username-2',
input: {
key: 'user.username',
type: 'TEXT',
validation: [
{
message: 'Value cannot be empty',
rule: true,
type: 'required',
},
],
value: '',
},
name: 'user.username',
output: {
key: 'user.username',
label: 'Enter your Email Address',
type: 'TEXT',
value: '',
},
type: 'TextCollector',
},
{
category: 'SingleValueCollector',
error: null,
id: 'user.password-3',
input: {
key: 'user.password',
type: 'PASSWORD',
value: '',
},
name: 'user.password',
output: {
key: 'user.password',
label: 'Enter your Password',
type: 'PASSWORD',
},
type: 'PasswordCollector',
},
{
category: 'ActionCollector',
error: null,
id: 'submit-4',
name: 'submit',
output: {
key: 'submit',
label: 'Sign On',
type: 'SUBMIT_BUTTON',
},
type: 'SubmitCollector',
},
],
description: 'This is an out-of-the-box sign on form that prompts for username and password.',
name: 'SDK - Sign On',
status: 'continue',
},
error: null,
httpStatus: 200,
server: {
_links: {
next: {
href: 'https://auth.pingone.com/490b9f38-f20b-4afa-b02e-3cc1315e29ab/davinci/connections/8209285e0d2f3fc76bfd23fd10d45e6f/capabilities/customForm',
},
self: {
href: 'https://auth.pingone.com/490b9f38-f20b-4afa-b02e-3cc1315e29ab/davinci/policy/c233870943cbaa6ff1a021622d074842/start',
},
},
eventName: 'continue',
id: 'elvr5pbwzn',
interactionId: '03534806-abbc-4f43-a9b1-8bdba1a57765',
interactionToken:
'460b6e374ff40f453eb83e3cf3da33d289538371e293df51afde06dab7ae37963234bb7bac201160b53857e49bdf245367c719ad087efc6d95fa09df4ad3d1bb94b75e1c49d72bd948eddf3a8aff9ebcb4d7a8212741d8d41abb010dd75d26e4d246ef0cea0e2550dc6fbbe36a4492105b28c33f39325291a596cd1ad77cbf95',
status: 'continue',
},
status: 'continue',
};
16 changes: 14 additions & 2 deletions packages/davinci-client/src/lib/node.slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { describe, it, expect } from 'vitest';

import { nodeSlice } from './node.slice.js';
import { next0 } from './mock-data/davinci.next.mock.js';
import { nodeNext0 } from './mock-data/node.next.mock.js';
import { next0, next4 } from './mock-data/davinci.next.mock.js';
import { nodeNext0, nodeNext1 } from './mock-data/node.next.mock.js';
import { success0, success1 } from './mock-data/davinci.success.mock.js';
import { nodeSuccess0, nodeSuccess1 } from './mock-data/node.success.mock.js';
import { error0a, error2b, error3 } from './mock-data/davinci.error.mock.js';
Expand Down Expand Up @@ -163,4 +163,16 @@ describe('The node slice reducers', () => {
status: 'failure',
});
});
it('should add continue to eventName when forms are used', () => {
const action = {
type: 'node/next',
payload: {
data: next4,
requestId: '1234',
httpStatus: 200,
},
};

expect(nodeSlice.reducer(undefined, action)).toEqual(nodeNext1);
});
});
2 changes: 1 addition & 1 deletion packages/davinci-client/src/lib/node.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const nodeSlice = createSlice({
id: action.payload.data.id,
interactionId: action.payload.data.interactionId,
interactionToken: action.payload.data.interactionToken,
eventName: action.payload.data.eventName,
eventName: action.payload.data.eventName || 'continue',
status: CONTINUE_STATUS,
};

Expand Down
Loading