-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdevice-profile.test.ts
More file actions
86 lines (70 loc) · 3.17 KB
/
device-profile.test.ts
File metadata and controls
86 lines (70 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { expect, test } from '@forgerock/e2e-shared/coverage-fixture';
import { asyncEvents } from './utils/async-events.js';
import { username, password } from './utils/demo-user.js';
test('Test device profile collection journey flow', async ({ page }) => {
const { clickButton, navigate } = asyncEvents(page);
const messageArray: string[] = [];
let deviceProfileRequestBody: Record<string, unknown> | null = null;
page.on('console', async (msg) => {
messageArray.push(msg.text());
return Promise.resolve(true);
});
page.on('request', (request) => {
if (request.url().includes('/authenticate') && request.method() === 'POST') {
try {
const postData = request.postData();
if (!postData) return;
const body = JSON.parse(postData);
const deviceCallback = body.callbacks?.find(
(cb: { type: string }) => cb.type === 'DeviceProfileCallback',
);
if (!deviceCallback) return;
const profileInput = deviceCallback.input?.find(
(input: { name: string }) => input.name === 'IDToken1',
);
if (profileInput?.value) {
deviceProfileRequestBody = JSON.parse(profileInput.value);
}
} catch {
// Ignore parsing errors
}
}
});
await navigate('/?journey=DeviceProfileCallbackTest&clientId=basic');
await expect(page.getByLabel('User Name')).toBeVisible({ timeout: 10000 });
await page.getByLabel('User Name').fill(username);
await page.getByLabel('Password').fill(password);
await clickButton('Submit', '/authenticate');
await expect(page.getByText('Collecting device profile information...')).toBeVisible({
timeout: 10000,
});
await expect(page.getByText('Device profile collected successfully!')).toBeVisible({
timeout: 15000,
});
await expect(page.getByText('Complete')).toBeVisible({ timeout: 15000 });
expect(deviceProfileRequestBody).not.toBeNull();
expect(deviceProfileRequestBody).toHaveProperty('identifier');
expect(typeof deviceProfileRequestBody?.identifier).toBe('string');
expect((deviceProfileRequestBody?.identifier as string).length).toBeGreaterThan(0);
expect(deviceProfileRequestBody).toHaveProperty('metadata');
const metadata = deviceProfileRequestBody?.metadata as Record<string, unknown>;
expect(metadata).toHaveProperty('hardware');
expect(metadata).toHaveProperty('browser');
expect(metadata).toHaveProperty('platform');
const platform = metadata.platform as Record<string, unknown>;
expect(platform).toHaveProperty('deviceName');
expect(typeof platform.deviceName).toBe('string');
await clickButton('Logout', '/sessions');
await expect(page.getByLabel('User Name')).toBeVisible({ timeout: 10000 });
expect(messageArray.some((msg) => msg.includes('Device profile collected successfully'))).toBe(
true,
);
expect(messageArray.some((msg) => msg.includes('Journey completed successfully'))).toBe(true);
expect(messageArray.some((msg) => msg.includes('Logout successful'))).toBe(true);
});