Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add more tests

Sara Vieirac249f7c992e4
diff --git a/packages/asset-uploader/src/helpers/get-asset-path.test.ts b/packages/asset-uploader/src/helpers/get-asset-path.test.ts
index 68190db7c3..6d4c084c4e 100644
--- a/packages/asset-uploader/src/helpers/get-asset-path.test.ts
+++ b/packages/asset-uploader/src/helpers/get-asset-path.test.ts
@@ -5,7 +5,7 @@ const commonAsset = {
id: "sa-546",
width: new Decimal(200),
height: new Decimal(200),
- projectId: "jdhajk",
+ projectId: "id",
size: 2135,
format: "png",
createdAt: new Date(),
@@ -16,16 +16,20 @@ describe("getAssetPath", () => {
const OLD_ENV = process.env;
beforeEach(() => {
- jest.resetModules(); // Most important - it clears the cache
- process.env = { ...OLD_ENV }; // Make a copy
+ jest.resetModules();
+ process.env = {
+ ...OLD_ENV,
+ S3_ACCESS_KEY_ID: "testid",
+ S3_SECRET_ACCESS_KEY: "testkey",
+ };
});
afterAll(() => {
- process.env = OLD_ENV; // Restore old environment
+ process.env = OLD_ENV;
});
describe("local", () => {
- test("return local path with no custom path", () => {
+ test("returns local path with no custom path", () => {
const { getAssetPath } = require("./get-asset-path");
expect(
getAssetPath({
@@ -48,4 +52,48 @@ describe("getAssetPath", () => {
).toBe("/assets/test.png");
});
});
+ describe("s3", () => {
+ test("returns s3 url", () => {
+ process.env.S3_ENDPOINT = "https://fr1.s3.com";
+ process.env.S3_BUCKET = "bucket";
+ process.env.S3_REGION = "fr1";
+ const { getAssetPath } = require("./get-asset-path");
+ expect(
+ getAssetPath({
+ ...commonAsset,
+ name: "test.png",
+ location: "REMOTE",
+ })
+ ).toBe("https://bucket.fr1.s3.com/test.png");
+ });
+ test("returns s3 url and fixes extra slashes", () => {
+ process.env.S3_ENDPOINT = "https://fr1.s3.com//";
+ process.env.S3_BUCKET = "bucket";
+ process.env.S3_REGION = "fr1";
+ const { getAssetPath } = require("./get-asset-path");
+ expect(
+ getAssetPath({
+ ...commonAsset,
+ name: "test.png",
+ location: "REMOTE",
+ })
+ ).toBe("https://bucket.fr1.s3.com/test.png");
+ });
+ });
+ describe("R2", () => {
+ test("returns r2 url", () => {
+ process.env.S3_ENDPOINT = "https://userid.r2.cloudflarestorage.com";
+ process.env.S3_BUCKET = "bucket";
+ process.env.S3_REGION = "auto";
+ process.env.WORKER_URL = "https://worker-test.workers.dev";
+ const { getAssetPath } = require("./get-asset-path");
+ expect(
+ getAssetPath({
+ ...commonAsset,
+ name: "test.png",
+ location: "REMOTE",
+ })
+ ).toBe("https://worker-test.workers.dev/test.png");
+ });
+ });
});