feat(import): complete OpenAPI onboarding and verify delivery
This commit is contained in:
1 parent
bb3e376767
commit
e93de7015a
244 files changed
+57020
-5139
No files matched your search
@@ -0,0 +1,165 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
const { getCurrentWorkspace, login } = require('./helpers');
|
||||
|
||||
function draftSnapshot(operationId) {
|
||||
return {
|
||||
id: operationId,
|
||||
name: operationId,
|
||||
display_name: 'Imported rates',
|
||||
category: 'general',
|
||||
protocol: 'rest',
|
||||
target: {
|
||||
kind: 'rest',
|
||||
base_url: 'https://api.example.test',
|
||||
method: 'GET',
|
||||
path_template: '/rates',
|
||||
static_headers: {},
|
||||
},
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
description: null,
|
||||
required: false,
|
||||
nullable: false,
|
||||
default_value: null,
|
||||
fields: {},
|
||||
items: null,
|
||||
enum_values: [],
|
||||
variants: [],
|
||||
},
|
||||
output_schema: {
|
||||
type: 'object',
|
||||
description: null,
|
||||
required: false,
|
||||
nullable: false,
|
||||
default_value: null,
|
||||
fields: {},
|
||||
items: null,
|
||||
enum_values: [],
|
||||
variants: [],
|
||||
},
|
||||
input_mapping: { rules: [] },
|
||||
output_mapping: {
|
||||
rules: [
|
||||
{ source: '$.response.body', target: '$.output', required: true },
|
||||
{ source: '$.response.body.rate', target: '$.output.rate', required: true },
|
||||
],
|
||||
},
|
||||
execution_config: {
|
||||
timeout_ms: 10000,
|
||||
retry_policy: null,
|
||||
auth_profile_ref: null,
|
||||
headers: {},
|
||||
approval_policy: null,
|
||||
},
|
||||
tool_description: { title: 'Imported rates', description: 'Get rates.', tags: [], examples: [] },
|
||||
wizard_state: { input_sample: {}, output_sample: {}, test_input: {}, import_findings: [] },
|
||||
};
|
||||
}
|
||||
|
||||
test('edit wizard skips no-op saves and refreshes its baseline after a real edit', async ({ page }) => {
|
||||
await login(page);
|
||||
const workspace = await getCurrentWorkspace(page);
|
||||
const operationId = 'imported_rates_noop';
|
||||
const operationPath = `/api/admin/workspaces/${encodeURIComponent(workspace.id)}/operations/${operationId}`;
|
||||
const versionPath = `${operationPath}/versions/*`;
|
||||
let version = 4;
|
||||
let updateCount = 0;
|
||||
const testedVersions = [];
|
||||
const publishedVersions = [];
|
||||
const analyzedPayloads = [];
|
||||
|
||||
await page.route(operationPath, async (route) => {
|
||||
if (route.request().method() === 'PATCH') {
|
||||
updateCount += 1;
|
||||
version += 1;
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ operation_id: operationId, workspace_id: workspace.id, version, status: 'draft' }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
id: operationId,
|
||||
workspace_id: workspace.id,
|
||||
name: operationId,
|
||||
display_name: 'Imported rates',
|
||||
category: 'general',
|
||||
protocol: 'rest',
|
||||
status: 'draft',
|
||||
current_draft_version: version,
|
||||
draft_version_ref: { version, status: 'draft' },
|
||||
published_version_ref: null,
|
||||
agent_refs: [],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route(versionPath, async (route) => {
|
||||
const requestedVersion = Number(new URL(route.request().url()).pathname.split('/').pop());
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
operation_id: operationId,
|
||||
workspace_id: workspace.id,
|
||||
version: requestedVersion,
|
||||
status: 'draft',
|
||||
snapshot: draftSnapshot(operationId),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route(`**/operations/${operationId}/test-runs`, async (route) => {
|
||||
testedVersions.push(route.request().postDataJSON().version);
|
||||
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, errors: [] }) });
|
||||
});
|
||||
await page.route('**/operations/analyze-quality', async (route) => {
|
||||
analyzedPayloads.push(route.request().postDataJSON());
|
||||
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ blocking: false, findings: [] }) });
|
||||
});
|
||||
await page.route(`**/operations/${operationId}/publish`, async (route) => {
|
||||
const payload = route.request().postDataJSON();
|
||||
publishedVersions.push(payload.version);
|
||||
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ published_version: payload.version }) });
|
||||
});
|
||||
page.on('dialog', (dialog) => dialog.accept());
|
||||
|
||||
await page.goto(`/wizard/?mode=edit&operationId=${operationId}`);
|
||||
await expect(page.locator('#tool-display-name')).toHaveValue('Imported rates');
|
||||
|
||||
const loadedOutputMapping = await page.evaluate(() => (
|
||||
window.jsyaml.load(document.getElementById('tool-output-mapping').value)
|
||||
));
|
||||
expect(loadedOutputMapping['$.output']).toBe('$.response.body');
|
||||
expect(loadedOutputMapping.rate).toBe('$.response.body.rate');
|
||||
expect(JSON.stringify(loadedOutputMapping)).not.toContain('$.response.body.$.output');
|
||||
|
||||
await page.evaluate(() => window.CrankWizardShell.doGoToStep(5));
|
||||
|
||||
await page.locator('#wizard-run-test').click();
|
||||
await expect.poll(() => testedVersions).toEqual([4]);
|
||||
expect(updateCount).toBe(0);
|
||||
|
||||
await page.evaluate(() => window.CrankWizardShell.doGoToStep(4));
|
||||
await page.locator('#tool-display-name').fill('Edited rates');
|
||||
await page.locator('.btn-save-draft').click();
|
||||
await expect.poll(() => updateCount).toBe(1);
|
||||
|
||||
await page.evaluate(() => window.CrankWizardShell.doGoToStep(5));
|
||||
await page.locator('#wizard-run-test').click();
|
||||
await expect.poll(() => testedVersions).toEqual([4, 5]);
|
||||
expect(updateCount).toBe(1);
|
||||
|
||||
await page.locator('#wizard-publish-operation').click();
|
||||
await expect.poll(() => publishedVersions).toEqual([5]);
|
||||
expect(updateCount).toBe(1);
|
||||
|
||||
const publishedRules = analyzedPayloads[analyzedPayloads.length - 1].output_mapping.rules;
|
||||
expect(publishedRules).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ source: '$.response.body', target: '$.output' }),
|
||||
expect.objectContaining({ source: '$.response.body.rate', target: '$.output.rate' }),
|
||||
]));
|
||||
expect(JSON.stringify(publishedRules)).not.toContain('$.response.body.$.output');
|
||||
});
|
||||
Reference in new issue
Block a user