test: adjust nzbget test to use append instead of scan (#1952)

This commit is contained in:
Meier Lukas
2025-01-14 18:39:12 +01:00
committed by GitHub
parent 75c791801e
commit 4d94fce523
2 changed files with 29 additions and 23 deletions

View File

@@ -22,9 +22,9 @@
"lint:ws": "pnpm dlx sherif@latest",
"package:new": "turbo gen init",
"release": "semantic-release",
"test": "cross-env NODE_ENV=development vitest run --exclude e2e --coverage.enabled ",
"test:e2e": "cross-env NODE_ENV=development vitest e2e",
"test:ui": "cross-env NODE_ENV=development vitest --exclude e2e --ui --coverage.enabled",
"test": "cross-env NODE_ENV=development CI=true vitest run --exclude e2e --coverage.enabled ",
"test:e2e": "cross-env NODE_ENV=development CI=true vitest e2e",
"test:ui": "cross-env NODE_ENV=development CI=true vitest --exclude e2e --ui --coverage.enabled",
"typecheck": "turbo typecheck",
"with-env": "dotenv -e .env --"
},

View File

@@ -1,3 +1,4 @@
import { readFile } from "fs/promises";
import { join } from "path";
import type { StartedTestContainer } from "testcontainers";
import { GenericContainer, getContainerRuntimeClient, ImageName, Wait } from "testcontainers";
@@ -169,29 +170,34 @@ const nzbGetAddItemAsync = async (
password: string,
integration: NzbGetIntegration,
) => {
// Add nzb file in the watch folder
await container.copyFilesToContainer([
{
source: join(__dirname, "/volumes/usenet/test_download_100MB.nzb"),
target: "/downloads/nzb/test_download_100MB.nzb",
},
]);
const fileContent = await readFile(join(__dirname, "/volumes/usenet/test_download_100MB.nzb"), "base64");
// Trigger scanning of the watch folder (Only available way to add an item except "append" which is too complex and unnecessary)
await fetch(`http://${container.getHost()}:${container.getMappedPort(6789)}/${username}:${password}/jsonrpc`, {
method: "POST",
body: JSON.stringify({ method: "scan" }),
body: JSON.stringify({
method: "append",
params: [
"/downloads/nzb/test_download_100MB.nzb", // NZBFilename
fileContent, // Content
"", // Category
0, // Priority
true, // AddToTop
false, // Paused
"random", // DupeKey
1000, // DupeScore
"all", // DupeMode
[], // PPParameters
],
}),
});
// Retries up to 10000 times to let NzbGet scan and process the nzb (1 retry should suffice tbh but NzbGet is slow)
for (let i = 0; i < 10000; i++) {
const {
items: [item],
} = await integration.getClientJobsAndStatusAsync();
if (item) {
// Remove the added time because NzbGet doesn't return it properly in this specific case
const { added: _, ...itemRest } = item;
return itemRest;
}
const {
items: [item],
} = await integration.getClientJobsAndStatusAsync();
if (!item) {
throw new Error("No item found");
}
// Throws if it can't find the item
throw new Error("No item found");
return item;
};