Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"devDependencies": {
"@base44-cli/logger": "workspace:*",
"@base44/sdk": "^0.8.23",
"@clack/prompts": "^1.0.1",
"@seald-io/nedb": "^4.1.2",
"@types/bun": "^1.2.15",
Expand Down
75 changes: 75 additions & 0 deletions packages/cli/tests/cli/dev-media.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { type Base44Client, createClient } from "@base44/sdk";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { waitForDevServer } from "./testkit/dev-utils.js";
import { fixture, type RunLiveHandle, setupCLITests } from "./testkit/index.js";

describe("media in dev", () => {
const t = setupCLITests();
let handle: RunLiveHandle;
let base44: Base44Client;

beforeEach(async () => {
await t.givenLoggedInWithProject(fixture("basic"));

handle = await t.runLive("dev");
const serverUrl = await waitForDevServer(handle);

base44 = createClient({
appId: t.kit.api.appId,
serverUrl,
});
});

afterEach(async () => {
const result = await handle.stop();
t.expectResult(result).toSucceed();
});

it("should upload public file and serve it", async () => {
const file = new File(["hello world"], "test.txt", { type: "text/plain" });
const { file_url } = await base44.integrations.Core.UploadFile({ file });
expect(file_url).toMatch(/\/media\/.+\.txt$/);

const fileRes = await fetch(file_url);
expect(fileRes.status).toBe(200);
expect(await fileRes.text()).toBe("hello world");
});

it("should upload secret file and serve it with token", async () => {
const file = new File(["secret content"], "secret.txt", {
type: "text/plain",
});
const { file_uri } = await base44.integrations.Core.UploadPrivateFile({
file,
});
expect(file_uri).toMatch(/\.txt$/);

// Get a signed URL for the private file
const { signed_url } = await base44.integrations.Core.CreateFileSignedUrl({
file_uri,
});
expect(signed_url).toContain("/media/private/");
expect(signed_url).toContain("token=");

// Fetch with valid token succeeds
const fileRes = await fetch(signed_url);
expect(fileRes.status).toBe(200);
expect(await fileRes.text()).toBe("secret content");

// Fetch with wrong token returns 400
const badUrl = signed_url.replace(/([?&]token=)[^&]+/, "$1invalid");
const badRes = await fetch(badUrl);
expect(badRes.status).toBe(400);
const badBody = (await badRes.json()) as { error: string };
expect(badBody.error).toBe("InvalidJWT");

// Fetch with no token returns 401
const urlWithToken = new URL(signed_url);
urlWithToken.searchParams.delete("token");
const noTokenUrl = urlWithToken.toString();
const noTokenRes = await fetch(noTokenUrl);
expect(noTokenRes.status).toBe(401);
const noTokenBody = (await noTokenRes.json()) as { error: string };
expect(noTokenBody.error).toBe("Missing token");
});
});
12 changes: 2 additions & 10 deletions packages/cli/tests/cli/dev.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { describe, it } from "vitest";
import { fixture, type RunLiveHandle, setupCLITests } from "./testkit/index.js";

const waitForDevServer = async (
runLiveHandle: RunLiveHandle,
): Promise<string> => {
const pattern = /Dev server is available at (http\S+)/;
await runLiveHandle.waitForOutput(pattern);
const match = runLiveHandle.stdout.join("").match(pattern)!;
return match[1];
};
import { waitForDevServer } from "./testkit/dev-utils.js";
import { fixture, setupCLITests } from "./testkit/index.js";

describe("dev command", () => {
const t = setupCLITests();
Expand Down
13 changes: 13 additions & 0 deletions packages/cli/tests/cli/testkit/dev-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { RunLiveHandle } from "./CLITestkit";

export const waitForDevServer = async (
runLiveHandle: RunLiveHandle,
): Promise<string> => {
const pattern = /Dev server is available at (http\S+)/;
await runLiveHandle.waitForOutput(pattern);
const match = runLiveHandle.stdout.join("").match(pattern);
if (!match) {
throw new Error(`Can't find dev server url`);
}
return match[1];
};
Loading