Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

test(http,immich): address CodeRabbit review

ajnart8579fcbfc2ec
diff --git a/packages/core/src/test/infrastructure/http/request.spec.ts b/packages/core/src/test/infrastructure/http/request.spec.ts
index 3d2b9c888..e1980862d 100644
--- a/packages/core/src/test/infrastructure/http/request.spec.ts
+++ b/packages/core/src/test/infrastructure/http/request.spec.ts
@@ -41,6 +41,22 @@ describe("mergeHeadersWithUserAgent", () => {
expect(merged.get("user-agent")).toContain("Homarr/");
});
+ test("should keep existing headers when given a tuple array", () => {
+ // Arrange
+ const headers: [string, string][] = [
+ ["x-api-key", "some-api-key"],
+ ["Accept", "application/json"],
+ ];
+
+ // Act
+ const merged = mergeHeadersWithUserAgent(headers);
+
+ // Assert
+ expect(merged.get("x-api-key")).toBe("some-api-key");
+ expect(merged.get("accept")).toBe("application/json");
+ expect(merged.get("user-agent")).toContain("Homarr/");
+ });
+
test("should not override an existing user-agent in any casing", () => {
// Arrange
const headers = new Headers({ "USER-AGENT": "custom-agent" });
@@ -88,14 +104,17 @@ describe("fetchWithTrustedCertificatesAsync", () => {
const headers = new Headers({ "x-api-key": "immich-api-key", Accept: "application/json" });
// Act
- const response = await fetchWithTrustedCertificatesAsync(`http://127.0.0.1:${port}/api/server/statistics`, {
- headers: headers as unknown as RequestInit["headers"],
- });
- server.close();
-
- // Assert
- expect(response.status).toBe(200);
- expect(getReceivedHeaders()["x-api-key"]).toBe("immich-api-key");
- expect(getReceivedHeaders()["user-agent"]).toContain("Homarr/");
+ try {
+ const response = await fetchWithTrustedCertificatesAsync(`http://127.0.0.1:${port}/api/server/statistics`, {
+ headers: headers as unknown as RequestInit["headers"],
+ });
+
+ // Assert
+ expect(response.status).toBe(200);
+ expect(getReceivedHeaders()["x-api-key"]).toBe("immich-api-key");
+ expect(getReceivedHeaders()["user-agent"]).toContain("Homarr/");
+ } finally {
+ server.close();
+ }
});
});
diff --git a/packages/integrations/test/immich-sdk-e2e.spec.ts b/packages/integrations/test/immich-sdk-e2e.spec.ts
index 00072e91f..9e1f5ade9 100644
--- a/packages/integrations/test/immich-sdk-e2e.spec.ts
+++ b/packages/integrations/test/immich-sdk-e2e.spec.ts
@@ -25,13 +25,15 @@ describe("real @immich/sdk end-to-end through fetchWithTrustedCertificatesAsync"
const port = (server.address() as AddressInfo).port;
init({ baseUrl: `http://127.0.0.1:${port}/api`, apiKey: "sdk-configured-key" });
- const stats = await getServerStatistics({
- fetch: fetchWithTrustedCertificatesAsync as unknown as typeof fetch,
- });
-
- server.close();
-
- expect(receivedXApiKey).toBe("sdk-configured-key");
- expect(stats).toMatchObject({ usage: 1000, photos: 5, videos: 2 });
+ try {
+ const stats = await getServerStatistics({
+ fetch: fetchWithTrustedCertificatesAsync as unknown as typeof fetch,
+ });
+
+ expect(receivedXApiKey).toBe("sdk-configured-key");
+ expect(stats).toMatchObject({ usage: 1000, photos: 5, videos: 2 });
+ } finally {
+ server.close();
+ }
});
});