-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test: add sdk embed and backend vitest coverage #1835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createEmbedUrl } from "./cap-embed"; | ||
|
|
||
| describe("createEmbedUrl", () => { | ||
| it("builds the default embed URL with required SDK parameters", () => { | ||
| const url = createEmbedUrl({ | ||
| videoId: "video-123", | ||
| publicKey: "pk_live_123", | ||
| }); | ||
|
|
||
| expect(url).toBe("https://cap.so/embed/video-123?sdk=1&pk=pk_live_123"); | ||
| }); | ||
|
|
||
| it("includes optional playback and branding parameters", () => { | ||
| const url = new URL( | ||
| createEmbedUrl({ | ||
| apiBase: "https://app.example.com", | ||
| videoId: "video-123", | ||
| publicKey: "pk_live_123", | ||
| autoplay: true, | ||
| branding: { | ||
| logoUrl: "https://cdn.example.com/logo.svg", | ||
| accentColor: "#ff00aa", | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(url.origin).toBe("https://app.example.com"); | ||
| expect(url.pathname).toBe("/embed/video-123"); | ||
| expect(url.searchParams.get("sdk")).toBe("1"); | ||
| expect(url.searchParams.get("pk")).toBe("pk_live_123"); | ||
| expect(url.searchParams.get("autoplay")).toBe("1"); | ||
| expect(url.searchParams.get("logo")).toBe( | ||
| "https://cdn.example.com/logo.svg", | ||
| ); | ||
| expect(url.searchParams.get("accent")).toBe("#ff00aa"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| collectPasswordHashes, | ||
| resolveEffectiveVideoRules, | ||
| } from "./EffectiveVideoRules"; | ||
|
|
||
| describe("resolveEffectiveVideoRules", () => { | ||
| it("lets space settings override video and organization defaults", () => { | ||
| const rules = resolveEffectiveVideoRules({ | ||
| videoSettings: { | ||
| disableCaptions: false, | ||
| disableComments: true, | ||
| }, | ||
| organizationSettings: { | ||
| disableCaptions: true, | ||
| disableTranscript: true, | ||
| }, | ||
| spaces: [ | ||
| { | ||
| id: "space-1", | ||
| name: "Engineering", | ||
| settings: { | ||
| disableCaptions: true, | ||
| disableSummary: true, | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| expect(rules.settings).toMatchObject({ | ||
| disableCaptions: true, | ||
| disableComments: true, | ||
| disableSummary: true, | ||
| disableTranscript: true, | ||
| }); | ||
| expect(rules.inheritedSettings.disableCaptions).toEqual([ | ||
| { id: "space-1", name: "Engineering" }, | ||
| ]); | ||
| expect(rules.inheritedSettings.disableSummary).toEqual([ | ||
| { id: "space-1", name: "Engineering" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("collects inherited password sources from flags and hashes", () => { | ||
| const rules = resolveEffectiveVideoRules({ | ||
| spaces: [ | ||
| { id: "space-1", name: "Flagged", hasPassword: true }, | ||
| { id: "space-2", name: "Has hash", password: "hash-2" }, | ||
| { id: "space-3", name: "Open" }, | ||
| ], | ||
| }); | ||
|
|
||
| expect(rules.hasInheritedPassword).toBe(true); | ||
| expect(rules.inheritedPasswordSources).toEqual([ | ||
| { id: "space-1", name: "Flagged" }, | ||
| { id: "space-2", name: "Has hash" }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("collectPasswordHashes", () => { | ||
| it("keeps the video password first and removes empty space passwords", () => { | ||
| expect( | ||
| collectPasswordHashes({ | ||
| videoPassword: "video-hash", | ||
| spacePasswords: [ | ||
| { password: "space-hash" }, | ||
| { password: "" }, | ||
| { password: null }, | ||
| {}, | ||
| ], | ||
| }), | ||
| ).toEqual(["video-hash", "space-hash"]); | ||
| }); | ||
| }); | ||
|
Comment on lines
+61
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Only the "happy path" (a truthy Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/web-backend/src/Videos/EffectiveVideoRules.test.ts
Line: 61-75
Comment:
**No test for absent / null `videoPassword`**
Only the "happy path" (a truthy `videoPassword`) is covered. The function also handles `videoPassword` being `undefined` or `null` via `...(videoPassword ? [videoPassword] : [])`. Adding a test case where `videoPassword` is omitted or `null` would confirm the guard works, especially if the function signature changes in the future.
How can I resolve this? If you propose a fix, please make it concise. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
videoSettingsandorganizationSettingsnot coveredThe test name promises to exercise "space settings override video and organization defaults," but the branch where
videoSettingsexplicitly sets a flag tofalsewhileorganizationSettingssets the same flag totrue(with no space override) is never reached. FordisableCaptions, the space provides an override so thevideoSettings?.[key] ?? organizationSettings?.[key]line is bypassed entirely.Because of
??, an explicitfalseinvideoSettingscorrectly shadows the org-leveltrue. If that operator were ever changed to||, this test suite would still pass — making it possible to silently invert the intended "video setting wins" precedence. Consider adding a case where a space array is empty (or excludes a key),videoSettings.someKey = false, andorganizationSettings.someKey = true, and asserting that the result isfalse.Prompt To Fix With AI