fix(backups): сверять сервер и файл подтверждения импорта
This commit is contained in:
1 parent
af86d2c3cd
commit
99ff5aebaf
11 files changed
+51
-13
No files matched your search
@@ -74,7 +74,7 @@ for (const operation of ["delete", "restore", "download"]) for (const change of
|
||||
try {
|
||||
if (fails) await r.fulfill({ headers, status: 503, json: { error: "СТАРАЯ ОПЕРАЦИЯ ОТКАЗАЛА" } })
|
||||
else if (operation === "delete") await r.fulfill({ headers, status: 204 })
|
||||
else if (operation === "restore") await r.fulfill({ headers, json: { filename: backup.filename, serverName: "СТАРЫЙ РОУТЕР" } })
|
||||
else if (operation === "restore") await r.fulfill({ headers, json: { backupId: backup.id, serverId: 1, filename: backup.filename, serverName: "СТАРЫЙ РОУТЕР" } })
|
||||
else await r.fulfill({ headers, contentType: "text/plain", body: "old config" })
|
||||
} catch {} finally { completed = true }
|
||||
})
|
||||
|
||||
@@ -22,7 +22,7 @@ for (const status of [403, 503, 200]) test("Бэкапы: удаление " + s
|
||||
})
|
||||
test("Бэкапы: ошибка restore и чужой filename сохраняют диалог", async ({ page }) => {
|
||||
await setupBackups(page); let failure = true
|
||||
await page.route("**/api/backups/backup-1/restore", r => r.fulfill(failure ? { status: 503, json: { error: "Импорт отказал" } } : { json: { filename: "other.rsc", serverName: "router" } }))
|
||||
await page.route("**/api/backups/backup-1/restore", r => r.fulfill(failure ? { status: 503, json: { error: "Импорт отказал" } } : { json: { backupId: "backup-1", serverId: 1, filename: "other.rsc", serverName: "router" } }))
|
||||
await page.goto("/backups"); await page.getByRole("button", { name: "Восстановить " + backup.filename, exact: true }).click()
|
||||
const dialog = page.getByRole("alertdialog"); await dialog.getByRole("button", { name: "Восстановить", exact: true }).click()
|
||||
await expect(dialog.getByRole("alert").filter({ hasText: "Импорт отказал" })).toBeVisible()
|
||||
@@ -37,3 +37,13 @@ test("Бэкапы: download получает файл, HTML 200 показыв
|
||||
const download = page.waitForEvent("download"); await button.click(); expect((await download).suggestedFilename()).toBe(backup.filename)
|
||||
html = true; await button.click(); await expect(page.getByRole("alert", { name: "Операция резервных копий" })).toContainText("не подтверждён API")
|
||||
})
|
||||
|
||||
test("Бэкапы: restore требует правильный serverId и принимает новое имя сервера", async ({ page }) => {
|
||||
await setupBackups(page); let serverId = 2, calls = 0
|
||||
await page.route("**/api/backups/backup-1/restore", async r => { calls++; await r.fulfill({ json: { backupId: backup.id, serverId, filename: backup.filename, serverName: "Новое имя роутера" } }) })
|
||||
await page.goto("/backups"); await page.getByRole("button", { name: "Восстановить " + backup.filename, exact: true }).click()
|
||||
const dialog = page.getByRole("alertdialog"); await dialog.getByRole("button", { name: "Восстановить", exact: true }).click()
|
||||
await expect(dialog.getByRole("alert").filter({ hasText: "другой резервной копии или серверу" })).toBeVisible()
|
||||
serverId = 1; await dialog.getByRole("button", { name: "Восстановить", exact: true }).dblclick()
|
||||
await expect(dialog).toBeHidden(); await expect(page.getByText("API подтвердил импорт " + backup.filename + " на Новое имя роутера", { exact: true })).toBeVisible(); expect(calls).toBe(2)
|
||||
})
|
||||
Reference in new issue
Block a user