Remove one retired device pairing and its owned history from the device detail
This commit is contained in:
@@ -116,3 +116,87 @@ test('creates and renames a customer, opens its inventory, and hides editing for
|
||||
{ method: 'PATCH', path: `/api/v1/tenants/${customerId}`, body: { name: 'Nord GmbH' } }
|
||||
]);
|
||||
});
|
||||
|
||||
test('removes the confirmed historical installation and keeps its successor', async ({ page }) => {
|
||||
const customer = { tenant_id: '22222222-2222-4222-8222-222222222222', name: 'Nord GmbH' };
|
||||
const asset = '33333333-3333-4333-8333-333333333333';
|
||||
const old = '44444444-4444-4444-8444-444444444444';
|
||||
const active = '55555555-5555-4555-8555-555555555555';
|
||||
const path = '/api/v1/tenants/' + customer.tenant_id + '/devices/' + asset;
|
||||
const device = { tenant_id: customer.tenant_id, customer_name: customer.name, asset_id: asset,
|
||||
hostname: 'NORD-PC', os: 'Windows', recent_jobs: [], volumes: [] };
|
||||
const listing = (items: unknown[]) => ({ items, next_cursor: null, truncated: false,
|
||||
completeness: 'complete', as_of: new Date().toISOString() });
|
||||
let attempts = 0, revoked = false, deleted = false, canManage = true;
|
||||
await page.route(origin + '/auth/config', r => r.fulfill({ json: {
|
||||
local_login_enabled: true, oidc_configured: false, oidc_login_url: null, dev_login_enabled: false
|
||||
} }));
|
||||
await page.route(origin + '/auth/session', r => r.fulfill({ json: {
|
||||
principal: 'operator', tenant_id: customer.tenant_id, csrf_token: 'fixture-csrf', testsimulation: false,
|
||||
permissions: canManage ? ['inventory:read', 'devices:revoke'] : ['inventory:read']
|
||||
} }));
|
||||
await page.route(origin + '/api/v1/**', async r => {
|
||||
const req = r.request(), url = new URL(req.url());
|
||||
const historical = { ...device, agent_id: old, lifecycle: revoked ? 'revoked' : 'replaced', status: 'offline' };
|
||||
const successor = { ...device, agent_id: active, lifecycle: 'current', status: 'online' };
|
||||
if (url.pathname === '/api/v1/tenants') return r.fulfill({ json: listing([customer]) });
|
||||
if (url.pathname === '/api/v1/devices' || url.pathname === path.slice(0, path.lastIndexOf('/'))) {
|
||||
return r.fulfill({ json: listing(url.searchParams.get('view') === 'history' ? (deleted ? [] : [historical]) : [successor]) });
|
||||
}
|
||||
if (url.pathname === path && req.method() === 'GET') {
|
||||
if (url.searchParams.get('agent_id') === old && !deleted) return r.fulfill({ json: historical });
|
||||
if (url.searchParams.get('agent_id') === active) return r.fulfill({ json: successor });
|
||||
}
|
||||
if (url.pathname === path + '/revocation' && req.method() === 'POST') {
|
||||
expect(url.searchParams.get('agent_id')).toBe(old);
|
||||
expect(req.headers()['x-csrf-token']).toBe('fixture-csrf');
|
||||
expect(req.postDataJSON()).toEqual({ reason: 'Neuinstallation bestätigt' });
|
||||
revoked = true;
|
||||
return r.fulfill({ json: { asset_id: asset, revoked: true } });
|
||||
}
|
||||
if (url.pathname === path && req.method() === 'DELETE') {
|
||||
expect(url.searchParams.get('agent_id')).toBe(old);
|
||||
expect(req.headers()['x-rmm-tenant']).toBe(customer.tenant_id);
|
||||
expect(req.headers()['x-csrf-token']).toBe('fixture-csrf');
|
||||
expect(req.postData()).toBeNull();
|
||||
if (++attempts === 1) return r.fulfill({ status: 409, json: { code: 'DEVICE_HAS_OPEN_WORK' } });
|
||||
deleted = true;
|
||||
return r.fulfill({ status: 204 });
|
||||
}
|
||||
return r.fulfill({ status: 404, json: { code: 'NOT_FOUND' } });
|
||||
});
|
||||
await page.goto(origin + '/#geraete');
|
||||
await page.getByRole('button', { name: 'Historie' }).click();
|
||||
await page.getByRole('button', { name: 'NORD-PC' }).click();
|
||||
await page.getByText('Gerät verwalten', { exact: true }).click();
|
||||
await expect(page.getByRole('button', { name: 'Kopplung löschen' })).toHaveCount(0);
|
||||
await page.getByText('Geräteidentität widerrufen', { exact: true }).click();
|
||||
await page.getByLabel('Grund für Geräteidentität widerrufen').fill('Neuinstallation bestätigt');
|
||||
const nonce = await page.getByText('Aktuelle Bestätigungskennung:').locator('code').innerText();
|
||||
await page.getByLabel('Bestätigungskennung eingeben').fill(nonce);
|
||||
await page.getByRole('checkbox', { name: 'Ich bestätige' }).check();
|
||||
await page.getByRole('button', { name: 'Geräteidentität widerrufen · ausdrücklich ausführen' }).click();
|
||||
await page.getByRole('button', { name: 'Kopplung löschen' }).click();
|
||||
await expect(page.locator('.warning')).toContainText('NORD-PC');
|
||||
await expect(page.locator('.warning')).toContainText(customer.name);
|
||||
await expect(page.getByText('Kopplungs-ID')).toContainText(old);
|
||||
await page.getByRole('button', { name: 'Abbrechen' }).click();
|
||||
expect(attempts).toBe(0);
|
||||
await page.getByRole('button', { name: 'Kopplung löschen' }).click();
|
||||
await page.getByRole('button', { name: 'Endgültig löschen' }).click();
|
||||
await expect(page.getByRole('alert')).toContainText('offene Aufträge');
|
||||
await page.getByRole('button', { name: 'Endgültig löschen' }).click();
|
||||
await expect(page.getByRole('status')).toContainText('Kopplung von „NORD-PC“ bei „Nord GmbH“ gelöscht.');
|
||||
await expect(page.getByRole('button', { name: 'NORD-PC' })).toHaveCount(0);
|
||||
await page.getByRole('button', { name: 'Bestand' }).click();
|
||||
await page.getByRole('button', { name: 'NORD-PC' }).click();
|
||||
await expect(page).toHaveURL(new RegExp(active + '$'));
|
||||
await page.getByText('Gerät verwalten', { exact: true }).click();
|
||||
await expect(page.getByRole('button', { name: 'Kopplung löschen' })).toHaveCount(0);
|
||||
await expect(page.getByText('Geräteidentität widerrufen', { exact: true })).toBeVisible();
|
||||
canManage = false;
|
||||
await page.reload();
|
||||
await expect(page.getByRole('heading', { name: 'NORD-PC' })).toBeVisible();
|
||||
await expect(page.getByText('Gerät verwalten', { exact: true })).toHaveCount(0);
|
||||
expect(attempts).toBe(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user