forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstants.test.ts
More file actions
48 lines (38 loc) · 1.81 KB
/
constants.test.ts
File metadata and controls
48 lines (38 loc) · 1.81 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
import { buildWizardPath, getOrgAggregateScopeKey, ROUTES } from './constants';
const BASE = `${ROUTES.HOME_PATH}${ROUTES.ASSIGN_ROLE_WIZARD_PATH}`;
describe('buildWizardPath', () => {
it('returns the base path when called with no arguments', () => {
expect(buildWizardPath()).toBe(BASE);
});
it('returns the base path when called with an empty options object', () => {
expect(buildWizardPath({})).toBe(BASE);
});
it('appends ?users= when only users is provided', () => {
expect(buildWizardPath({ users: 'alice' })).toBe(`${BASE}?users=alice`);
});
it('appends ?from= when only from is provided', () => {
expect(buildWizardPath({ from: '/authz/libraries/lib:123/alice' }))
.toBe(`${BASE}?from=%2Fauthz%2Flibraries%2Flib%3A123%2Falice`);
});
it('appends both users and from when both are provided', () => {
const result = buildWizardPath({ users: 'alice', from: '/authz/libraries/lib:123/alice' });
const parsed = new URL(result, 'http://x');
expect(parsed.pathname).toBe(BASE);
expect(parsed.searchParams.get('users')).toBe('alice');
expect(parsed.searchParams.get('from')).toBe('/authz/libraries/lib:123/alice');
});
it('omits the query string when users and from are both empty strings', () => {
expect(buildWizardPath({ users: '', from: '' })).toBe(BASE);
});
});
describe('getOrgAggregateScopeKey', () => {
it('returns course wildcard scope for course context', () => {
expect(getOrgAggregateScopeKey('course', 'MIT')).toBe('course-v1:MIT+*');
});
it('returns library wildcard scope for library context', () => {
expect(getOrgAggregateScopeKey('library', 'MIT')).toBe('lib:MIT:*');
});
it('throws for an unknown contextType', () => {
expect(() => getOrgAggregateScopeKey('unknown', 'MIT')).toThrow('Unknown contextType: "unknown"');
});
});