-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.ts
More file actions
54 lines (40 loc) · 1.71 KB
/
tests.ts
File metadata and controls
54 lines (40 loc) · 1.71 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
import { getOperationId } from "./src/utils/getOperationId.ts";
import { isOperationLink } from "./src/utils/isOperationLink.ts";
let k = 0;
function test(actual: unknown, expected: unknown) {
let n = `00${++k}`.slice(-3);
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
console.log(n);
console.log(`Expected: ${JSON.stringify(expected, null, 2)}`);
console.log(`Actual: ${JSON.stringify(actual, null, 2)}`);
throw new Error("Unexpected value");
}
console.log(`${n} Passed`);
}
const validOperationHrefs = [
"https://cloud-api.yandex.net/v1/disk/operations?id=a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operations/?id=a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operations/a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operations/a0b1c2/",
];
const invalidOperationHrefs = [
"https://cloud-api.yandex.net/v1/disk/operationsx?id=a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operationsx/?id=a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operationsx/a0b1c2",
"https://cloud-api.yandex.net/v1/disk/operationsx/a0b1c2/",
"https://example.com/a0b1c2/",
];
test(isOperationLink(null), false);
test(isOperationLink({}), false);
// Should be `{ href: string }`, not just `string`
test(
isOperationLink("https://cloud-api.yandex.net/v1/disk/operations?id=a0b1c2"),
false,
);
for (let href of validOperationHrefs) test(isOperationLink({ href }), true);
for (let href of invalidOperationHrefs) test(isOperationLink({ href }), false);
for (let href of validOperationHrefs)
test(getOperationId({ method: "GET", href, templated: false }), "a0b1c2");
for (let href of invalidOperationHrefs)
test(getOperationId({ method: "GET", href, templated: false }), "");
console.log("\nPassed");