Skip to content

Commit 15b5075

Browse files
alexey-yarmoshMartinKolarik
authored andcommitted
feat: token based adoption e2e tests (#64)
1 parent 16b4267 commit 15b5075

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

test/e2e/tests/probes.spec.ts

+44-12
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const addUserProbes = async (user: User) => {
6060
};
6161

6262
const addProbeWithoutUser = async () => {
63-
await sql('gp_probes').insert({
63+
const probe = {
6464
id: randomUUID(),
6565
ip: '2.2.2.2',
6666
uuid: '7bac0b3a-f808-48e1-8892-062bab3280f8',
@@ -80,7 +80,9 @@ const addProbeWithoutUser = async () => {
8080
userId: null,
8181
version: '0.28.0',
8282
hardwareDevice: null,
83-
});
83+
};
84+
await sql('gp_probes').insert(probe);
85+
return probe;
8486
};
8587

8688
const addProbeWithUser = async (user2: User) => {
@@ -114,37 +116,67 @@ test('Probes page', async ({ page, user }) => {
114116
await expect(page.locator('tr')).toHaveCount(3);
115117
});
116118

117-
test('Probe adoption', async ({ page }) => {
118-
addProbeWithoutUser();
119+
test('Software probe adoption (token)', async ({ page, user }) => {
120+
const probe = await addProbeWithoutUser();
119121
await page.goto('/probes');
120122
await page.getByRole('button', { name: 'Adopt a probe' }).click();
121-
await page.getByLabel('Next step').click();
123+
await page.getByRole('button', { name: 'Software probe' }).click();
124+
await page.getByRole('button', { name: 'Next step' }).click();
125+
await sql('gp_probes').where({ id: probe.id }).update({ userId: user.id, name: 'probe-bf-ouagadougou-01' });
126+
await page.getByRole('button', { name: 'Finish' }).click();
127+
await expect(page.getByText('probe-bf-ouagadougou-01').first()).toBeVisible();
128+
});
129+
130+
test('Software probe adoption (code)', async ({ page }) => {
131+
await addProbeWithoutUser();
132+
await page.goto('/probes');
133+
await page.getByRole('button', { name: 'Adopt a probe' }).click();
134+
await page.getByRole('button', { name: 'Software probe' }).click();
135+
await page.getByRole('button', { name: 'Next step' }).click();
136+
await page.waitForTimeout(10000);
137+
await page.getByLabel('Adopt the probe manually').click();
122138
await page.getByPlaceholder('Enter IP address of your probe').fill('2.2.2.2');
123139
await page.getByLabel('Send adoption code').click();
124140
await page.getByTestId('adoption-code').locator('input').first().fill('111111');
125141
await page.getByLabel('Verify the code').click();
126-
await page.getByLabel('Finish').click();
142+
await page.getByRole('button', { name: 'Finish' }).click();
127143
await expect(page.getByText('probe-bf-ouagadougou-01').first()).toBeVisible();
128144
});
129145

130-
test('Probe adoption fail if probe is already adopted', async ({ page, user2 }) => {
131-
addProbeWithUser(user2);
146+
test('Hardware probe adoption', async ({ page }) => {
147+
await addProbeWithoutUser();
132148
await page.goto('/probes');
133149
await page.getByRole('button', { name: 'Adopt a probe' }).click();
134-
await page.getByLabel('Next step').click();
150+
await page.getByRole('button', { name: 'Hardware probe' }).click();
151+
await page.getByRole('button', { name: 'Next step' }).click();
135152
await page.getByPlaceholder('Enter IP address of your probe').fill('2.2.2.2');
136153
await page.getByLabel('Send adoption code').click();
137-
await expect(page.getByText('The probe with this IP address is already adopted').first()).toBeVisible();
154+
await page.getByTestId('adoption-code').locator('input').first().fill('111111');
155+
await page.getByLabel('Verify the code').click();
156+
await page.getByRole('button', { name: 'Finish' }).click();
157+
await expect(page.getByText('probe-bf-ouagadougou-01').first()).toBeVisible();
138158
});
139159

140160
test('Probe adoption of non-synced probe', async ({ page }) => {
141161
await page.goto('/probes');
142162
await page.getByRole('button', { name: 'Adopt a probe' }).click();
143-
await page.getByLabel('Next step').click();
163+
await page.getByRole('button', { name: 'Hardware probe' }).click();
164+
await page.getByRole('button', { name: 'Next step' }).click();
144165
await page.getByPlaceholder('Enter IP address of your probe').fill('2.2.2.2');
145166
await page.getByLabel('Send adoption code').click();
146167
await page.getByTestId('adoption-code').locator('input').first().fill('111111');
147168
await page.getByLabel('Verify the code').click();
148-
await page.getByLabel('Finish').click();
169+
await page.getByRole('button', { name: 'Finish' }).click();
149170
await expect(page.getByText('probe-bf-ouagadougou-01').first()).toBeVisible();
150171
});
172+
173+
test('Probe adoption by code fails if probe is already adopted', async ({ page, user2 }) => {
174+
await addProbeWithUser(user2);
175+
await page.goto('/probes');
176+
await page.getByRole('button', { name: 'Adopt a probe' }).click();
177+
await page.getByRole('button', { name: 'Hardware probe' }).click();
178+
await page.getByRole('button', { name: 'Next step' }).click();
179+
await page.getByPlaceholder('Enter IP address of your probe').fill('2.2.2.2');
180+
await page.getByLabel('Send adoption code').click();
181+
await expect(page.getByText('The probe with this IP address is already adopted').first()).toBeVisible();
182+
});

0 commit comments

Comments
 (0)