-
Notifications
You must be signed in to change notification settings - Fork 2
/
validate-identifier.spec.js
82 lines (81 loc) · 3.59 KB
/
validate-identifier.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
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
import { describe, expect, test } from "vitest";
import { validateId } from "./validate-identifier.js";
describe("Test @id's that should be valid", () => {
test(`LICENCE.md should be valid`, () => {
expect(validateId({ id: "LICENCE.md", type: "File" }).isValid).toBeTruthy;
expect(validateId({ id: "LICENCE.md", type: "File, Licence" }).isValid).toBeTruthy;
expect(validateId({ id: "LICENCE.md", type: ["File", "Licence"] }).isValid).toBeTruthy;
});
test(`/path/to/file should be valid`, () => {
expect(validateId({ id: "/path/to/file", type: "Dataset" }).isValid).toBeTruthy;
});
test(`./ should be valid`, () => {
expect(validateId({ id: "./", type: "Dataset" }).isValid).toBeTruthy;
});
test(`../ should be valid`, () => {
expect(validateId({ id: "../", type: "Dataset" }).isValid).toBeTruthy;
});
test(`_:xxx should be valid`, () => {
expect(validateId({ id: "_:xxx", type: "Dataset" }).isValid).toBeTruthy;
});
test(`#xxx should be valid`, () => {
expect(validateId({ id: "#xxx", type: "Dataset" }).isValid).toBeTruthy;
});
test(`http://schema.org/name should be valid`, () => {
expect(validateId({ id: "http://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
});
test(`https://schema.org/name should be valid`, () => {
expect(validateId({ id: "https://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
});
test(`ftp://schema.org/name should be valid`, () => {
expect(validateId({ id: "ftp://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
});
test(`ftps://schema.org/name should be valid`, () => {
expect(validateId({ id: "ftps://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
});
test(`arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html`, () => {
expect(
validateId({
id: "arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html",
type: "Dataset",
}).isValid
).toBeTruthy;
});
test(`arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/`, () => {
expect(
validateId({
id: "arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/",
type: "Dataset",
}).isValid
).toBeTruthy;
});
test(`arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/`, () => {
expect(
validateId({
id: "arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/",
type: "Dataset",
}).isValid
).toBeTruthy;
});
test(`arcp://name,gallery.example.org/`, () => {
expect(validateId({ id: "arcp://name,gallery.example.org/a", type: "Dataset" }).isValid)
.toBeTruthy;
});
});
describe("Test @id's that should NOT be valid", () => {
test(`no id passed`, () => {
expect(validateId({})).toEqual({ isValid: false });
});
test(`aaa should not be valid`, () => {
expect(validateId({ id: "aaa", type: "Person" }).message).toEqual(
"Invalid identifier 'aaa'. See https://describo.github.io/documentation/component/identifiers.html for more information."
);
});
test(`32a423d6-52ab-47e3-a9cd-54f418a48571 should not be valid`, () => {
expect(
validateId({ id: "32a423d6-52ab-47e3-a9cd-54f418a48571", type: "Person" }).message
).toEqual(
`Invalid identifier '32a423d6-52ab-47e3-a9cd-54f418a48571'. See https://describo.github.io/documentation/component/identifiers.html for more information.`
);
});
});