test(navidrome): complete cleanup review (#6494)
* test(navidrome): hoist album fixture helper * test(navidrome): address coderabbit cleanup feedback
This commit is contained in:
1 parent
61128ddcc8
commit
ade640dcea
2 files changed
+16
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: "Audio Stats"
|
title: "Audio Stats"
|
||||||
description: "Displays library statistics from Navidrome or Audiobookshelf, adapting its display based on the linked integration."
|
description: "Displays media and listening statistics from Navidrome or Audiobookshelf, adapting its display based on the linked integration."
|
||||||
hide_title: true
|
hide_title: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
// @vitest-environment node
|
||||||
import { Response } from "undici";
|
import { Response } from "undici";
|
||||||
import { beforeEach, describe, expect, test, vi } from "vitest";
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
|
vi.hoisted(() => {
|
||||||
|
process.env.SKIP_ENV_VALIDATION = "true";
|
||||||
|
process.env.SECRET_ENCRYPTION_KEY = "0".repeat(64);
|
||||||
|
});
|
||||||
|
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
import type { IntegrationSecret } from "../../base/types";
|
import type { IntegrationSecret } from "../../base/types";
|
||||||
@@ -39,19 +45,19 @@ const subsonicFailed = (message: string, code = 70) =>
|
|||||||
"subsonic-response": { status: "failed", error: { code, message } },
|
"subsonic-response": { status: "failed", error: { code, message } },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const makeAlbums = (count: number, songCount: number) =>
|
||||||
|
Array.from({ length: count }, (_, index) => ({
|
||||||
|
id: `album-${index}`,
|
||||||
|
name: `Album ${index}`,
|
||||||
|
songCount,
|
||||||
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockFetch.mockReset();
|
mockFetch.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("NavidromeIntegration.getDashboardDataAsync", () => {
|
describe("NavidromeIntegration.getDashboardDataAsync", () => {
|
||||||
test("paginates album list and counts songs", async () => {
|
test("paginates album list and counts songs", async () => {
|
||||||
const makeAlbums = (count: number, songCount: number) =>
|
|
||||||
Array.from({ length: count }, (_, i) => ({
|
|
||||||
id: `album-${i}`,
|
|
||||||
name: `Album ${i}`,
|
|
||||||
songCount,
|
|
||||||
}));
|
|
||||||
|
|
||||||
mockFetch.mockImplementation((url) => {
|
mockFetch.mockImplementation((url) => {
|
||||||
const urlStr = toUrlString(url);
|
const urlStr = toUrlString(url);
|
||||||
|
|
||||||
@@ -84,7 +90,7 @@ describe("NavidromeIntegration.getDashboardDataAsync", () => {
|
|||||||
>;
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(new Response(subsonicOk({}), { status: 200 })) as unknown as ReturnType<
|
return Promise.reject(new Error(`Unexpected dashboard request: ${urlStr}`)) as unknown as ReturnType<
|
||||||
typeof fetchWithTrustedCertificatesAsync
|
typeof fetchWithTrustedCertificatesAsync
|
||||||
>;
|
>;
|
||||||
});
|
});
|
||||||
@@ -113,7 +119,7 @@ describe("NavidromeIntegration.getDashboardDataAsync", () => {
|
|||||||
) as unknown as ReturnType<typeof fetchWithTrustedCertificatesAsync>;
|
) as unknown as ReturnType<typeof fetchWithTrustedCertificatesAsync>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(new Response(subsonicOk({}), { status: 200 })) as unknown as ReturnType<
|
return Promise.reject(new Error(`Unexpected dashboard request: ${urlStr}`)) as unknown as ReturnType<
|
||||||
typeof fetchWithTrustedCertificatesAsync
|
typeof fetchWithTrustedCertificatesAsync
|
||||||
>;
|
>;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user