-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnamespaces.test.ts
More file actions
104 lines (91 loc) · 4.61 KB
/
Copy pathnamespaces.test.ts
File metadata and controls
104 lines (91 loc) · 4.61 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { describe, it, expect } from 'vitest';
import {
UpdateNamespaceBodySchema,
UpdateNamespaceInputSchema,
UpdateNamespaceMemberRoleBodySchema,
LeaveNamespaceInputSchema,
DeleteNamespaceInputSchema,
RemoveNamespaceMemberInputSchema,
} from '../namespaces';
import {
ClearMustChangePasswordInputSchema,
ClearMustChangePasswordOutputSchema,
} from '../users';
describe('UpdateNamespace schemas', () => {
it('UpdateNamespaceBodySchema requires at least one field', () => {
expect(UpdateNamespaceBodySchema.safeParse({}).success).toBe(false);
expect(UpdateNamespaceBodySchema.safeParse({ displayName: 'Acme' }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ bio: '' }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ icon: 'Briefcase' }).success).toBe(true);
});
it('UpdateNamespaceInputSchema rejects { handle } with no edits', () => {
expect(UpdateNamespaceInputSchema.safeParse({ handle: 'acme' }).success).toBe(false);
});
it('UpdateNamespaceInputSchema accepts handle + one of the edit fields', () => {
expect(
UpdateNamespaceInputSchema.safeParse({ handle: 'acme', displayName: 'Acme' }).success,
).toBe(true);
});
it('UpdateNamespaceInputSchema rejects an empty displayName', () => {
const parsed = UpdateNamespaceInputSchema.safeParse({ handle: 'acme', displayName: '' });
expect(parsed.success).toBe(false);
});
it('UpdateNamespaceInputSchema accepts bio: "" to clear', () => {
expect(UpdateNamespaceInputSchema.safeParse({ handle: 'acme', bio: '' }).success).toBe(true);
});
it('accepts brand colors as #rrggbb hex and "" to clear', () => {
expect(UpdateNamespaceBodySchema.safeParse({ brandPrimaryColor: '#0d9488' }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ brandAccentColor: '#F59E0B' }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ brandPrimaryColor: '' }).success).toBe(true);
});
it('rejects malformed brand colors', () => {
expect(UpdateNamespaceBodySchema.safeParse({ brandPrimaryColor: 'teal' }).success).toBe(false);
expect(UpdateNamespaceBodySchema.safeParse({ brandPrimaryColor: '#fff' }).success).toBe(false);
expect(UpdateNamespaceBodySchema.safeParse({ brandAccentColor: '0d9488' }).success).toBe(false);
});
it('accepts a base64 image data URL logo and "" to clear, rejects non-images', () => {
const logo = 'data:image/png;base64,iVBORw0KGgo=';
expect(UpdateNamespaceBodySchema.safeParse({ logo }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ logo: '' }).success).toBe(true);
expect(UpdateNamespaceBodySchema.safeParse({ logo: 'https://example.com/a.png' }).success).toBe(false);
expect(UpdateNamespaceBodySchema.safeParse({ logo: 'data:text/html;base64,PHNjcmlwdD4=' }).success).toBe(false);
});
});
describe('UpdateNamespaceMemberRoleBodySchema', () => {
it('accepts admin / member only', () => {
expect(UpdateNamespaceMemberRoleBodySchema.safeParse({ role: 'admin' }).success).toBe(true);
expect(UpdateNamespaceMemberRoleBodySchema.safeParse({ role: 'member' }).success).toBe(true);
expect(UpdateNamespaceMemberRoleBodySchema.safeParse({ role: 'owner' }).success).toBe(false);
});
});
describe('ClearMustChangePassword schemas', () => {
it('input accepts empty object (user caller) and optional uid (apiKey caller)', () => {
expect(ClearMustChangePasswordInputSchema.safeParse({}).success).toBe(true);
expect(ClearMustChangePasswordInputSchema.safeParse({ uid: 'uid-marek' }).success).toBe(true);
});
it('input rejects unknown keys (strict)', () => {
expect(ClearMustChangePasswordInputSchema.safeParse({ extra: 'x' }).success).toBe(false);
});
it('output locks mustChangePassword to literal false', () => {
expect(
ClearMustChangePasswordOutputSchema.safeParse({
user: { uid: 'uid-marek', mustChangePassword: false },
}).success,
).toBe(true);
expect(
ClearMustChangePasswordOutputSchema.safeParse({
user: { uid: 'uid-marek', mustChangePassword: true },
}).success,
).toBe(false);
});
});
describe('Path-param input schemas', () => {
it('LeaveNamespace / DeleteNamespace / RemoveNamespaceMember require a valid handle', () => {
expect(LeaveNamespaceInputSchema.safeParse({ handle: 'acme' }).success).toBe(true);
expect(DeleteNamespaceInputSchema.safeParse({ handle: 'acme' }).success).toBe(true);
expect(
RemoveNamespaceMemberInputSchema.safeParse({ handle: 'acme', uid: 'uid-x' }).success,
).toBe(true);
expect(RemoveNamespaceMemberInputSchema.safeParse({ handle: 'acme', uid: '' }).success).toBe(false);
});
});