Skip to content

Commit

Permalink
test: Update utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 28, 2024
1 parent b51fd63 commit eea0e83
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions api.planx.uk/modules/file/service/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
Expand Down

0 comments on commit eea0e83

Please sign in to comment.