-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: add-tests #15
chore: add-tests #15
Changes from all commits
3b3c554
1e24446
9569ae5
a8c7124
6fa225e
194133a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@forgerock/davinci-client': patch | ||
--- | ||
|
||
fixes the checks to determine what node state we are in based on the response from p1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function dotToCamelCase(str: string) { | ||
return str | ||
.split('.') | ||
.map((part: string, index: number) => | ||
index === 0 ? part.toLowerCase() : part.charAt(0).toUpperCase() + part.slice(1).toLowerCase(), | ||
) | ||
.join(''); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,23 @@ test('Test happy paths on test page', async ({ page }) => { | |
|
||
const accessToken = await page.locator('#accessTokenValue').innerText(); | ||
await expect(accessToken).toBeTruthy(); | ||
|
||
const logoutButton = page.getByRole('button', { name: 'Logout' }); | ||
await expect(logoutButton).toBeVisible(); | ||
const revokeCall = page.waitForResponse((response) => { | ||
if (response.url().includes('/revoke') && response.status() === 200) { | ||
return true; | ||
} | ||
}); | ||
const signoff = page.waitForResponse((response) => { | ||
if (response.url().includes('/signoff') && response.status() === 302) { | ||
return true; | ||
} | ||
}); | ||
await logoutButton.click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extended this test to include logout for my own sanity. |
||
await revokeCall; | ||
await signoff; | ||
await expect(page.getByText('Username/Password Form')).toBeVisible(); | ||
}); | ||
test('ensure query params passed to start are sent off in authorize call', async ({ page }) => { | ||
const { navigate } = asyncEvents(page); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('Should render form fields', async ({ page }) => { | ||
await page.goto('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359'); | ||
await page.getByRole('heading', { name: 'Select Test Form' }).click(); | ||
await page.getByRole('button', { name: 'Form Fields' }).click(); | ||
await page.getByRole('textbox', { name: 'Text Input Label' }).click(); | ||
await page.getByRole('textbox', { name: 'Text Input Label' }).click(); | ||
|
||
const txtInput = page.getByRole('textbox', { name: 'Text Input Label' }); | ||
await txtInput.fill('This is some text'); | ||
expect(txtInput).toHaveValue('This is some text'); | ||
|
||
const flowLink = page.getByRole('button', { name: 'Flow Link' }); | ||
await flowLink.click(); | ||
|
||
const flowButton = page.getByRole('button', { name: 'Flow Button' }); | ||
await flowButton.click(); | ||
|
||
const requestPromise = page.waitForRequest((request) => request.url().includes('/customForm')); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
const request = await requestPromise; | ||
const parsedData = JSON.parse(request.postData()); | ||
const data = parsedData.parameters.data; | ||
expect(data.actionKey).toBe('submit'); | ||
expect(data.formData).toEqual({ | ||
['text-input-key']: 'This is some text', | ||
['dropdown-field-key']: '', | ||
['radio-group-key']: '', | ||
}); | ||
}); | ||
|
||
test('should render form validation fields', async ({ page }) => { | ||
await page.goto('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359'); | ||
await expect(page.getByRole('link', { name: 'Vite logo' })).toBeVisible(); | ||
await expect(page.getByRole('button', { name: 'Form Validation' })).toBeVisible(); | ||
await expect(page.locator('#form')).toContainText('Form Validation'); | ||
await page.getByRole('button', { name: 'Form Validation' }).click(); | ||
await expect(page.getByRole('heading', { name: 'Form Fields Validation' })).toBeVisible(); | ||
|
||
await page.getByRole('textbox', { name: 'Username' }).fill('sdk-user'); | ||
await expect(page.getByRole('textbox', { name: 'Username' })).toHaveValue('sdk-user'); | ||
|
||
const password = page.getByRole('textbox', { name: 'Password' }); | ||
await password.type('password'); | ||
await expect(password).toHaveValue('password'); | ||
|
||
await page.getByRole('textbox', { name: 'Email Address' }).fill('[email protected]'); | ||
await expect(page.getByRole('textbox', { name: 'Email Address' })).toHaveValue( | ||
'[email protected]', | ||
); | ||
|
||
const requestPromise = page.waitForRequest((request) => request.url().includes('/customForm')); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
|
||
const request = await requestPromise; | ||
const parsedData = JSON.parse(request.postData()); | ||
|
||
const data = parsedData.parameters.data; | ||
|
||
expect(data.actionKey).toBe('submit'); | ||
expect(data.formData).toEqual({ | ||
'user.username': 'sdk-user', | ||
'user.password': 'password', | ||
'user.email': '[email protected]', | ||
}); | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is why i'm adding a changeset. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,14 @@ import { InternalErrorResponse } from './client.types.js'; | |
export function transformSubmitRequest(node: ContinueNode): DaVinciRequest { | ||
// Filter out ActionCollectors as they are not used in form submissions | ||
const collectors = node.client?.collectors?.filter( | ||
(collector) => collector.category === 'SingleValueCollector', | ||
(collector) => | ||
collector.category === 'MultiValueCollector' || | ||
collector.category === 'SingleValueCollector' || | ||
collector.category === 'ValidatedSingleValueCollector', | ||
); | ||
|
||
const formData = collectors?.reduce<{ | ||
[key: string]: string | number | boolean; | ||
[key: string]: string | number | boolean | (string | number | boolean)[]; | ||
}>((acc, collector) => { | ||
acc[collector.input.key] = collector.input.value; | ||
return acc; | ||
|
@@ -175,12 +178,25 @@ export function handleResponse(cacheEntry: DaVinciCacheEntry, dispatch: Dispatch | |
*/ | ||
if (cacheEntry.isSuccess) { | ||
const requestId = cacheEntry.requestId; | ||
if ('eventName' in cacheEntry.data && cacheEntry.data.eventName === 'continue') { | ||
const data = cacheEntry.data as DaVinciNextResponse; | ||
dispatch(nodeSlice.actions.next({ data, requestId, httpStatus: status })); | ||
} else if ('session' in cacheEntry.data || 'authorizeResponse' in cacheEntry.data) { | ||
const hasNextUrl = () => { | ||
const data = cacheEntry.data; | ||
|
||
if ('_links' in data) { | ||
if ('next' in data._links) { | ||
if ('href' in data._links.next) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
Comment on lines
+181
to
+192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this should be a pure, stateless utility that could be used for fetching any property within |
||
|
||
if ('session' in cacheEntry.data || 'authorizeResponse' in cacheEntry.data) { | ||
const data = cacheEntry.data as DaVinciSuccessResponse; | ||
dispatch(nodeSlice.actions.success({ data, requestId, httpStatus: status })); | ||
} else if (hasNextUrl()) { | ||
const data = cacheEntry.data as DaVinciNextResponse; | ||
dispatch(nodeSlice.actions.next({ data, requestId, httpStatus: status })); | ||
} else { | ||
// If we got here, the response type is unknown and therefore an unrecoverable failure | ||
const data = cacheEntry.data as DaVinciFailureResponse; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the above changes , fixed this to use origin so it doesnt include the clientId param