test: adjust nzbget test to use append instead of scan (#1952)
This commit is contained in:
@@ -22,9 +22,9 @@
|
|||||||
"lint:ws": "pnpm dlx sherif@latest",
|
"lint:ws": "pnpm dlx sherif@latest",
|
||||||
"package:new": "turbo gen init",
|
"package:new": "turbo gen init",
|
||||||
"release": "semantic-release",
|
"release": "semantic-release",
|
||||||
"test": "cross-env NODE_ENV=development vitest run --exclude e2e --coverage.enabled ",
|
"test": "cross-env NODE_ENV=development CI=true vitest run --exclude e2e --coverage.enabled ",
|
||||||
"test:e2e": "cross-env NODE_ENV=development vitest e2e",
|
"test:e2e": "cross-env NODE_ENV=development CI=true vitest e2e",
|
||||||
"test:ui": "cross-env NODE_ENV=development vitest --exclude e2e --ui --coverage.enabled",
|
"test:ui": "cross-env NODE_ENV=development CI=true vitest --exclude e2e --ui --coverage.enabled",
|
||||||
"typecheck": "turbo typecheck",
|
"typecheck": "turbo typecheck",
|
||||||
"with-env": "dotenv -e .env --"
|
"with-env": "dotenv -e .env --"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { readFile } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import type { StartedTestContainer } from "testcontainers";
|
import type { StartedTestContainer } from "testcontainers";
|
||||||
import { GenericContainer, getContainerRuntimeClient, ImageName, Wait } from "testcontainers";
|
import { GenericContainer, getContainerRuntimeClient, ImageName, Wait } from "testcontainers";
|
||||||
@@ -169,29 +170,34 @@ const nzbGetAddItemAsync = async (
|
|||||||
password: string,
|
password: string,
|
||||||
integration: NzbGetIntegration,
|
integration: NzbGetIntegration,
|
||||||
) => {
|
) => {
|
||||||
// Add nzb file in the watch folder
|
const fileContent = await readFile(join(__dirname, "/volumes/usenet/test_download_100MB.nzb"), "base64");
|
||||||
await container.copyFilesToContainer([
|
|
||||||
{
|
|
||||||
source: join(__dirname, "/volumes/usenet/test_download_100MB.nzb"),
|
|
||||||
target: "/downloads/nzb/test_download_100MB.nzb",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
// Trigger scanning of the watch folder (Only available way to add an item except "append" which is too complex and unnecessary)
|
// 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`, {
|
await fetch(`http://${container.getHost()}:${container.getMappedPort(6789)}/${username}:${password}/jsonrpc`, {
|
||||||
method: "POST",
|
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 {
|
||||||
const {
|
items: [item],
|
||||||
items: [item],
|
} = await integration.getClientJobsAndStatusAsync();
|
||||||
} = await integration.getClientJobsAndStatusAsync();
|
|
||||||
if (item) {
|
if (!item) {
|
||||||
// Remove the added time because NzbGet doesn't return it properly in this specific case
|
throw new Error("No item found");
|
||||||
const { added: _, ...itemRest } = item;
|
|
||||||
return itemRest;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Throws if it can't find the item
|
|
||||||
throw new Error("No item found");
|
return item;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user