-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscopie.spec.js
35 lines (33 loc) · 926 Bytes
/
scopie.spec.js
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
/* eslint-disable jest/no-conditional-expect, jest/no-conditional-in-test, no-unused-vars */
import scenarios from './scenarios.json';
import { isAllowed, validateScopes } from './scopie';
describe('is allowed', () => {
it.each(scenarios.isAllowedTests)(
'$id',
({
id, rules, scopes, variables, error, result,
}) => {
expect.assertions(1);
const testFn = () => isAllowed(scopes, rules, variables);
if (error === undefined) {
expect(testFn()).toBe(result);
} else {
expect(testFn).toThrow(error);
}
},
);
});
describe('is valid', () => {
it.each(scenarios.validateScopesTests)(
'$id',
({ id, scopes, error }) => {
expect.assertions(1);
const err = validateScopes(scopes);
if (error === undefined) {
expect(err).toBeUndefined();
} else {
expect(err.message).toStrictEqual(error);
}
},
);
});