Skip to content
Closed
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
4 changes: 3 additions & 1 deletion packages/sdk-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"scripts": {
"build": "tsup",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {},
Expand All @@ -39,6 +40,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"tsup": "^8.0.0",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"vitest": "^3.2.0"
}
}
44 changes: 44 additions & 0 deletions packages/sdk-embed/src/vanilla/cap-embed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { createEmbedUrl } from "./cap-embed";

describe("createEmbedUrl", () => {
it("builds a default Cap embed URL", () => {
const url = new URL(
createEmbedUrl({
videoId: "video_123",
publicKey: "pk_test_123",
}),
);

expect(url.origin).toBe("https://cap.so");
expect(url.pathname).toBe("/embed/video_123");
expect(url.searchParams.get("sdk")).toBe("1");
expect(url.searchParams.get("pk")).toBe("pk_test_123");
expect(url.searchParams.has("autoplay")).toBe(false);
});

it("includes optional playback and branding parameters", () => {
const url = new URL(
createEmbedUrl({
apiBase: "https://app.example.com",
videoId: "video_456",
publicKey: "pk_live_456",
autoplay: true,
branding: {
logoUrl: "https://cdn.example.com/logo.svg",
accentColor: "#ff3366",
},
}),
);

expect(url.origin).toBe("https://app.example.com");
expect(url.pathname).toBe("/embed/video_456");
expect(url.searchParams.get("sdk")).toBe("1");
expect(url.searchParams.get("pk")).toBe("pk_live_456");
expect(url.searchParams.get("autoplay")).toBe("1");
Comment on lines +34 to +38
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The second test exercises publicKey and sdk params but never asserts their values. pk and sdk could silently regress (e.g., a rename or removal) while this test still passes. Adding the two assertions closes that blind spot without any extra setup.

Suggested change
expect(url.origin).toBe("https://app.example.com");
expect(url.pathname).toBe("/embed/video_456");
expect(url.searchParams.get("autoplay")).toBe("1");
expect(url.origin).toBe("https://app.example.com");
expect(url.pathname).toBe("/embed/video_456");
expect(url.searchParams.get("sdk")).toBe("1");
expect(url.searchParams.get("pk")).toBe("pk_live_456");
expect(url.searchParams.get("autoplay")).toBe("1");
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/sdk-embed/src/vanilla/cap-embed.test.ts
Line: 34-36

Comment:
The second test exercises `publicKey` and `sdk` params but never asserts their values. `pk` and `sdk` could silently regress (e.g., a rename or removal) while this test still passes. Adding the two assertions closes that blind spot without any extra setup.

```suggestion
		expect(url.origin).toBe("https://app.example.com");
		expect(url.pathname).toBe("/embed/video_456");
		expect(url.searchParams.get("sdk")).toBe("1");
		expect(url.searchParams.get("pk")).toBe("pk_live_456");
		expect(url.searchParams.get("autoplay")).toBe("1");
```

How can I resolve this? If you propose a fix, please make it concise.

expect(url.searchParams.get("logo")).toBe(
"https://cdn.example.com/logo.svg",
);
expect(url.searchParams.get("accent")).toBe("#ff3366");
});
});
4 changes: 3 additions & 1 deletion packages/sdk-recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "tsup",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {},
Expand All @@ -35,6 +36,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"tsup": "^8.0.0",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"vitest": "^3.2.0"
}
}
42 changes: 42 additions & 0 deletions packages/sdk-recorder/src/core/mime-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { getSupportedMimeType } from "./mime-types";

const originalMediaRecorder = globalThis.MediaRecorder;

afterEach(() => {
if (originalMediaRecorder) {
globalThis.MediaRecorder = originalMediaRecorder;
} else {
delete (globalThis as { MediaRecorder?: typeof MediaRecorder })
.MediaRecorder;
}
});

const setSupportedMimeTypes = (mimeTypes: ReadonlyArray<string>) => {
globalThis.MediaRecorder = {
isTypeSupported: vi.fn((mimeType: string) => mimeTypes.includes(mimeType)),
} as unknown as typeof MediaRecorder;
};

describe("getSupportedMimeType", () => {
it("returns the first supported MIME type by preference order", () => {
setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]);

expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
});
Comment on lines +22 to +26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The test title claims it verifies "first supported MIME type by preference order", but the mock only marks vp8,opus and video/webm as supported — so vp9,opus is simply absent. The test never exercises the case where a higher-priority type wins over a lower-priority one that is also available. If someone accidentally swapped the first two entries in PREFERRED_MIME_TYPES, this test would still pass. Adding a case where both vp9,opus and vp8,opus are supported confirms the priority ordering is actually enforced.

Suggested change
it("returns the first supported MIME type by preference order", () => {
setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]);
expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
});
it("returns the first supported MIME type by preference order", () => {
setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]);
expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
});
it("prefers vp9,opus over vp8,opus when both are supported", () => {
setSupportedMimeTypes([
"video/webm;codecs=vp9,opus",
"video/webm;codecs=vp8,opus",
]);
expect(getSupportedMimeType()).toBe("video/webm;codecs=vp9,opus");
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/sdk-recorder/src/core/mime-types.test.ts
Line: 22-26

Comment:
The test title claims it verifies "first supported MIME type by preference order", but the mock only marks `vp8,opus` and `video/webm` as supported — so `vp9,opus` is simply absent. The test never exercises the case where a higher-priority type wins over a lower-priority one that is also available. If someone accidentally swapped the first two entries in `PREFERRED_MIME_TYPES`, this test would still pass. Adding a case where both `vp9,opus` and `vp8,opus` are supported confirms the priority ordering is actually enforced.

```suggestion
	it("returns the first supported MIME type by preference order", () => {
		setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]);

		expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
	});

	it("prefers vp9,opus over vp8,opus when both are supported", () => {
		setSupportedMimeTypes([
			"video/webm;codecs=vp9,opus",
			"video/webm;codecs=vp8,opus",
		]);

		expect(getSupportedMimeType()).toBe("video/webm;codecs=vp9,opus");
	});
```

How can I resolve this? If you propose a fix, please make it concise.


it("prefers vp9,opus over vp8,opus when both are supported", () => {
setSupportedMimeTypes([
"video/webm;codecs=vp9,opus",
"video/webm;codecs=vp8,opus",
]);

expect(getSupportedMimeType()).toBe("video/webm;codecs=vp9,opus");
});

it("falls back to an empty string when no preferred types are supported", () => {
setSupportedMimeTypes([]);

expect(getSupportedMimeType()).toBe("");
});
});
4 changes: 3 additions & 1 deletion packages/web-domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"scripts": {
"build": "tsdown",
"test": "vitest run",
"generate-openapi": "node scripts/generate-openapi.ts"
},
"dependencies": {
Expand All @@ -18,6 +19,7 @@
"effect": "^3.18.4"
},
"devDependencies": {
"@effect/platform-node": "^0.98.3"
"@effect/platform-node": "^0.98.3",
"vitest": "^3.2.0"
}
}
44 changes: 44 additions & 0 deletions packages/web-domain/src/ImageUpload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Option } from "effect";
import { describe, expect, it } from "vitest";
import { extractFileKey } from "./ImageUpload";

const unwrap = <A>(option: Option.Option<A>) =>
Option.isSome(option) ? option.value : undefined;

describe("extractFileKey", () => {
it("keeps existing image keys unchanged", () => {
expect(unwrap(extractFileKey("users/user-1/avatar.png", false))).toBe(
"users/user-1/avatar.png",
);
});

it("extracts keys from virtual-hosted S3 URLs", () => {
expect(
unwrap(
extractFileKey("https://assets.cap.so/users/user-1/avatar.png", false),
),
).toBe("users/user-1/avatar.png");
});

it("drops the bucket segment for path-style S3 URLs", () => {
expect(
unwrap(
extractFileKey(
"https://s3.us-east-1.amazonaws.com/cap-bucket/users/user-1/avatar.png",
true,
),
),
).toBe("users/user-1/avatar.png");
});

it("ignores Google profile image URLs", () => {
expect(
Option.isNone(
extractFileKey(
"https://lh3.googleusercontent.com/a/profile-image",
false,
),
),
).toBe(true);
});
});
63 changes: 63 additions & 0 deletions packages/web-domain/src/Video.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, it } from "vitest";
import {
M3U8Source,
Mp4Source,
normalizeSegmentEntry,
SegmentsSource,
} from "./Video";

describe("video source file keys", () => {
it("builds deterministic keys for MP4 sources", () => {
const source = new Mp4Source({ ownerId: "owner-1", videoId: "video-1" });

expect(source.getFileKey()).toBe("owner-1/video-1/result.mp4");
});

it("builds deterministic keys for HLS playlist sources", () => {
const source = new M3U8Source({
ownerId: "owner-1",
videoId: "video-1",
subpath: "combined-source/stream.m3u8",
});

expect(source.getPlaylistFileKey()).toBe(
"owner-1/video-1/combined-source/stream.m3u8",
);
});

it("builds deterministic keys for segmented desktop recordings", () => {
const source = new SegmentsSource({
ownerId: "owner-1",
videoId: "video-1",
});

expect(source.getManifestKey()).toBe(
"owner-1/video-1/segments/manifest.json",
);
expect(source.getVideoInitKey()).toBe(
"owner-1/video-1/segments/video/init.mp4",
);
expect(source.getAudioInitKey()).toBe(
"owner-1/video-1/segments/audio/init.mp4",
);
expect(source.getVideoSegmentKey(7)).toBe(
"owner-1/video-1/segments/video/segment_007.m4s",
);
expect(source.getAudioSegmentKey(12)).toBe(
"owner-1/video-1/segments/audio/segment_012.m4s",
);
});
});

describe("normalizeSegmentEntry", () => {
it("uses the legacy default duration for numeric manifest entries", () => {
expect(normalizeSegmentEntry(4)).toEqual({ index: 4, duration: 3.0 });
});

it("preserves explicit segment durations", () => {
expect(normalizeSegmentEntry({ index: 2, duration: 1.5 })).toEqual({
index: 2,
duration: 1.5,
});
});
});
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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