-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_test.js
122 lines (117 loc) · 4.34 KB
/
index_test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import test from "ava";
import {
breakdownIpfs,
anyIpfsToNativeIpfs,
ifIpfsConvertToNativeIpfs,
} from "../src/index.js";
function ipfsTest(t, ipfsUri, breakdown, nativeUriString) {
t.deepEqual(breakdownIpfs(ipfsUri), breakdown);
t.is(anyIpfsToNativeIpfs(ipfsUri), nativeUriString);
t.is(ifIpfsConvertToNativeIpfs(ipfsUri), nativeUriString);
}
[
[
"https://soundxyz.mypinata.cloud/ipfs/QmXHfjwQ1MKmZLmzMNWc51brBTxFRWyjXKtLLysj2e5FcU",
{ cid: "QmXHfjwQ1MKmZLmzMNWc51brBTxFRWyjXKtLLysj2e5FcU", path: "" },
"ipfs://QmXHfjwQ1MKmZLmzMNWc51brBTxFRWyjXKtLLysj2e5FcU",
],
[
"https://neume.infura-ipfs.io/ipfs/bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
{
cid: "bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
path: "",
},
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
],
[
"https://neume.infura-ipfs.io/ipfs/bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/path/to/",
{
cid: "bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
path: "/path/to/",
},
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/path/to/",
],
[
"https://ipfs.fleek.co/ipfs/bafybeiamien6u7hqvnij4ylfz76hcv3ojshzmdklsfguz42krrs6mpaubm/",
{
cid: "bafybeiamien6u7hqvnij4ylfz76hcv3ojshzmdklsfguz42krrs6mpaubm",
path: "/",
},
"ipfs://bafybeiamien6u7hqvnij4ylfz76hcv3ojshzmdklsfguz42krrs6mpaubm/",
],
[
"https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link",
{
cid: "bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
path: "",
},
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
],
[
"https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.cf-ipfs.com/wiki/Vincent_van_Gogh.html",
{
cid: "bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
path: "/wiki/Vincent_van_Gogh.html",
},
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/Vincent_van_Gogh.html",
],
[
"https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.cf-ipfs.com/wiki/Vincent_van_Gogh.html/#1850",
{
cid: "bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
path: "/wiki/Vincent_van_Gogh.html/#1850",
},
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/Vincent_van_Gogh.html/#1850",
],
[
"https://ipfs.io/ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq#1850",
{
cid: "bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
path: "#1850",
},
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq#1850",
],
[
"https://ipfs.io/ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/#1850",
{
cid: "bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq",
path: "/#1850",
},
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/#1850",
],
[
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/path/to/",
{
cid: "bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
path: "/path/to/",
},
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/path/to/",
],
[
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/",
{
cid: "bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e",
path: "/",
},
"ipfs://bafybeihehacot7c5dj7y5qhwgaj7q6gdxfrjfmxcltl6wmtrjxzcn6cs7e/",
],
].forEach((args) =>
test(`valid anyIpfsToNativeIpfs - ${args[0]}`, ipfsTest, ...args)
);
[
"https://neume-ipfs.network",
"https://ipfs.fleek.co/ipfs/\"bafybeigtut2quijmcaxj3d4w473nqnaodizzsl5sjjh5z3wntm7qfh5ci4\"",
"https://\'bafybeigtut2quijmcaxj3d4w473nqnaodizzsl5sjjh5z3wntm7qfh5ci4ipfs.ipfs.cf-ipfs.com/",
"ipfs://bafybeigtut2quijmcaxj3d4w473nqnaodizzsl5sjjh5z3wntm7qfh5ci4ipfs:/path"
].forEach((arg) =>
test(`anyIpfsToNativeIpfs should throw error on invalid IPFS URI - ${arg}`, (t) => {
t.throws(() => anyIpfsToNativeIpfs(arg), {
message: `Couldn't breakdown ${arg} to CID and path`,
});
})
)
test("anyIpfsToNativeIpfs should throw error on non string URI", (t) => {
t.throws(() => anyIpfsToNativeIpfs(undefined), {
message: "Given IPFS URI should be of type string",
});
});