From eea0e8325911670d18001b288edc42c9bba8fb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 28 Nov 2024 17:17:24 +0000 Subject: [PATCH] test: Update utils tests --- .../modules/file/service/utils.test.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/api.planx.uk/modules/file/service/utils.test.ts b/api.planx.uk/modules/file/service/utils.test.ts index 95f300868b..1c3aed3c79 100644 --- a/api.planx.uk/modules/file/service/utils.test.ts +++ b/api.planx.uk/modules/file/service/utils.test.ts @@ -1,27 +1,25 @@ import { getS3KeyFromURL, s3Factory } from "./utils.js"; describe("s3 Factory", () => { - const OLD_ENV = process.env; + it("returns Minio config for local development", async () => { + const s3 = s3Factory(); - beforeEach(() => { - process.env = { ...OLD_ENV }; - }); + // Minio should be set up as a custom endpoint + if (!s3.config.endpoint) expect.fail(); - afterAll(() => { - process.env = OLD_ENV; - }); + const endpoint = await s3.config.endpoint(); - it("returns Minio config for local development", () => { - expect(s3Factory()).toHaveProperty("endpoint.host", "minio:1234"); + expect(endpoint.hostname).toBe("minio"); }); ["pizza", "staging", "production"].forEach((env) => { - it(`does not use Minio config on ${env} environment`, () => { - process.env.NODE_ENV = env; - expect(s3Factory()).toHaveProperty( - "endpoint.host", - "s3.eu-west-2.amazonaws.com", - ); + it(`does not use Minio config on ${env} environment`, async () => { + vi.stubEnv("NODE_ENV", env); + + const s3 = s3Factory(); + + // No custom endpoint used + expect(s3.config.endpoint).toBeUndefined(); }); }); });