-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathnew-video-defaults.test.ts
More file actions
64 lines (51 loc) · 1.75 KB
/
Copy pathnew-video-defaults.test.ts
File metadata and controls
64 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { type DbClient, resolveNewVideoDefaults } from "@cap/web-backend";
import type { Organisation } from "@cap/web-domain";
import { beforeEach, describe, expect, it, vi } from "vitest";
const env = vi.hoisted(() => ({ defaultPublic: true }));
vi.mock("@cap/env", async (importOriginal) => ({
...(await importOriginal<typeof import("@cap/env")>()),
serverEnv: () => ({ CAP_VIDEOS_DEFAULT_PUBLIC: env.defaultPublic }),
}));
type OrganizationRow = {
settings: { defaultVideoPublic?: boolean } | null;
defaultVideoPassword: string | null;
};
const dbReturning = (rows: OrganizationRow[]) =>
({
select: () => ({ from: () => ({ where: async () => rows }) }),
}) as unknown as DbClient;
const orgId = "org-1" as Organisation.OrganisationId;
describe("resolveNewVideoDefaults", () => {
beforeEach(() => {
env.defaultPublic = true;
});
it("falls back to the env default when the organization row is missing", async () => {
expect(await resolveNewVideoDefaults(dbReturning([]), orgId)).toEqual({
public: true,
password: null,
});
env.defaultPublic = false;
expect(await resolveNewVideoDefaults(dbReturning([]), orgId)).toEqual({
public: false,
password: null,
});
});
it("prefers the organization setting over the env default", async () => {
const db = dbReturning([
{ settings: { defaultVideoPublic: false }, defaultVideoPassword: null },
]);
expect(await resolveNewVideoDefaults(db, orgId)).toEqual({
public: false,
password: null,
});
});
it("passes the stored password hash through", async () => {
const db = dbReturning([
{ settings: null, defaultVideoPassword: "hashed-password" },
]);
expect(await resolveNewVideoDefaults(db, orgId)).toEqual({
public: true,
password: "hashed-password",
});
});
});