@pinata/sdk 1.2.1 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.babelrc +1 -1
  2. package/.eslintrc +7 -7
  3. package/.husky/pre-commit +6 -0
  4. package/.nvmrc +1 -1
  5. package/README.md +3 -3
  6. package/lib/pinata-sdk.js +494 -468
  7. package/lib/pinata-sdk.min.js +5 -5
  8. package/package.json +83 -71
  9. package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
  10. package/src/commands/data/index.ts +4 -0
  11. package/src/commands/data/pinList/pinList.ts +77 -0
  12. package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
  13. package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
  14. package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
  15. package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
  16. package/src/commands/pinning/index.ts +8 -0
  17. package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
  18. package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +27 -11
  19. package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +14 -19
  20. package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
  21. package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
  22. package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
  23. package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
  24. package/src/{constants.js → constants.ts} +0 -0
  25. package/src/index.ts +120 -0
  26. package/src/third-party/base-path-converter.d.ts +3 -0
  27. package/src/third-party/is-ipfs.d.ts +5 -0
  28. package/src/third-party/recursive-fs.d.ts +5 -0
  29. package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
  30. package/src/util/{validators.js → validators.ts} +14 -33
  31. package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
  32. package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
  33. package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
  34. package/test/commands/data/pinlist-sample-api.ts +540 -0
  35. package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
  36. package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
  37. package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
  38. package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
  39. package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +5 -7
  40. package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
  41. package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
  42. package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
  43. package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
  44. package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
  45. package/test/util/validators.test.ts +234 -0
  46. package/tsconfig.json +2 -2
  47. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
  48. package/types/commands/data/index.d.ts +4 -0
  49. package/types/commands/data/pinList/pinList.d.ts +45 -8
  50. package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
  51. package/types/commands/data/testAuthentication.d.ts +5 -7
  52. package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
  53. package/types/commands/pinning/hashMetadata.d.ts +3 -9
  54. package/types/commands/pinning/index.d.ts +8 -0
  55. package/types/commands/pinning/pinByHash.d.ts +14 -9
  56. package/types/commands/pinning/pinFileToIPFS.d.ts +25 -1
  57. package/types/commands/pinning/pinFromFS.d.ts +3 -9
  58. package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
  59. package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
  60. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
  61. package/types/commands/pinning/unpin.d.ts +2 -8
  62. package/types/constants.d.ts +2 -2
  63. package/types/index.d.ts +37 -165
  64. package/types/util/errorResponse.d.ts +1 -1
  65. package/types/util/validators.d.ts +20 -37
  66. package/webpack.config.js +50 -53
  67. package/src/commands/data/pinList/pinList.js +0 -34
  68. package/src/commands/pinning/hashPinPolicy.js +0 -51
  69. package/src/commands/pinning/userPinPolicy.js +0 -40
  70. package/src/index.js +0 -307
  71. package/test/commands/data/pinlist-sample-api.js +0 -540
  72. package/test/commands/pinning/hashPinPolicy.test.js +0 -65
  73. package/test/commands/pinning/userPinPolicy.test.js +0 -80
  74. package/test/util/validators.test.js +0 -234
@@ -1,540 +0,0 @@
1
- import { baseUrl } from '../../../src/constants';
2
-
3
- export const fakeHeaders = {
4
- headers: {
5
- pinata_api_key: "anykey",
6
- pinata_secret_api_key: "anysecret",
7
- },
8
- withCredentials: true,
9
- };
10
- export const statusOk = {
11
- status: 200,
12
- };
13
- export const APIData = {
14
- rows: [
15
- {
16
- id: "b0fbdba0-de78-4736-9211-632633deb7be",
17
- ipfs_pin_hash: "QmRLzdxyiT3waRz1i2J1CU4w868VAkcVpAcQ5vAWEmcNHD",
18
- size: 52960,
19
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
20
- date_pinned: "2022-10-05T22:46:53.843Z",
21
- date_unpinned: null,
22
- metadata: {
23
- name: "pin20.png",
24
- keyvalues: null,
25
- },
26
- regions: [
27
- {
28
- regionId: "FRA1",
29
- currentReplicationCount: 1,
30
- desiredReplicationCount: 1,
31
- },
32
- {
33
- regionId: "NYC1",
34
- currentReplicationCount: 1,
35
- desiredReplicationCount: 1,
36
- },
37
- ],
38
- },
39
- {
40
- id: "e5a59111-760c-4f24-8b98-fbb6918d578f",
41
- ipfs_pin_hash: "QmQ7M5otCbU3GdRizPNrktBfjP2kxxWMCAsT8X83GfQM6h",
42
- size: 35318,
43
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
44
- date_pinned: "2022-10-05T22:46:44.534Z",
45
- date_unpinned: null,
46
- metadata: {
47
- name: "pin19.png",
48
- keyvalues: null,
49
- },
50
- regions: [
51
- {
52
- regionId: "FRA1",
53
- currentReplicationCount: 1,
54
- desiredReplicationCount: 1,
55
- },
56
- {
57
- regionId: "NYC1",
58
- currentReplicationCount: 1,
59
- desiredReplicationCount: 1,
60
- },
61
- ],
62
- },
63
- {
64
- id: "efb2394a-ba19-4df7-9042-7c30e64cd377",
65
- ipfs_pin_hash: "QmRz8F1KiLfw8SHfshhVjjwnSGjQrqspYjHUSBYFhrF6rD",
66
- size: 66956,
67
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
68
- date_pinned: "2022-10-05T22:46:33.390Z",
69
- date_unpinned: null,
70
- metadata: {
71
- name: "pin18.png",
72
- keyvalues: null,
73
- },
74
- regions: [
75
- {
76
- regionId: "FRA1",
77
- currentReplicationCount: 1,
78
- desiredReplicationCount: 1,
79
- },
80
- {
81
- regionId: "NYC1",
82
- currentReplicationCount: 1,
83
- desiredReplicationCount: 1,
84
- },
85
- ],
86
- },
87
- {
88
- id: "1b004592-e84b-4cb3-81ec-07850ba8186b",
89
- ipfs_pin_hash: "QmauuvrS18r487tLtFHjZoqXFc3xrZLDBQqnpKycs9LPau",
90
- size: 84599,
91
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
92
- date_pinned: "2022-10-05T22:46:24.204Z",
93
- date_unpinned: null,
94
- metadata: {
95
- name: "pin17.png",
96
- keyvalues: null,
97
- },
98
- regions: [
99
- {
100
- regionId: "FRA1",
101
- currentReplicationCount: 1,
102
- desiredReplicationCount: 1,
103
- },
104
- {
105
- regionId: "NYC1",
106
- currentReplicationCount: 1,
107
- desiredReplicationCount: 1,
108
- },
109
- ],
110
- },
111
- {
112
- id: "e1cb1fe1-9d82-4553-90b2-8888d998ff54",
113
- ipfs_pin_hash: "QmV9S3Jx1abuA13VwD44CKRRnD7mdhbP4HL9HvjZdYpMZm",
114
- size: 360611,
115
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
116
- date_pinned: "2022-10-05T22:46:14.291Z",
117
- date_unpinned: null,
118
- metadata: {
119
- name: "pin16.png",
120
- keyvalues: null,
121
- },
122
- regions: [
123
- {
124
- regionId: "FRA1",
125
- currentReplicationCount: 1,
126
- desiredReplicationCount: 1,
127
- },
128
- {
129
- regionId: "NYC1",
130
- currentReplicationCount: 1,
131
- desiredReplicationCount: 1,
132
- },
133
- ],
134
- },
135
- {
136
- id: "38c0008a-5996-4166-b409-fe1fb699b62f",
137
- ipfs_pin_hash: "QmcC1qN1ALkeTrd4wVPgP2R6UsTKBRb7PNL91GwSUYAc2q",
138
- size: 329724,
139
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
140
- date_pinned: "2022-10-05T22:45:56.523Z",
141
- date_unpinned: null,
142
- metadata: {
143
- name: "pin15.png",
144
- keyvalues: null,
145
- },
146
- regions: [
147
- {
148
- regionId: "FRA1",
149
- currentReplicationCount: 1,
150
- desiredReplicationCount: 1,
151
- },
152
- {
153
- regionId: "NYC1",
154
- currentReplicationCount: 1,
155
- desiredReplicationCount: 1,
156
- },
157
- ],
158
- },
159
- {
160
- id: "90cddd06-5531-4234-adf5-680fd7c59a62",
161
- ipfs_pin_hash: "QmVMM2ogFUFZMnRtcsAj4zgBbAv8MYKRetD3iMNXjHWDqh",
162
- size: 49229,
163
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
164
- date_pinned: "2022-10-05T22:45:43.837Z",
165
- date_unpinned: null,
166
- metadata: {
167
- name: "pin14.png",
168
- keyvalues: null,
169
- },
170
- regions: [
171
- {
172
- regionId: "FRA1",
173
- currentReplicationCount: 1,
174
- desiredReplicationCount: 1,
175
- },
176
- {
177
- regionId: "NYC1",
178
- currentReplicationCount: 1,
179
- desiredReplicationCount: 1,
180
- },
181
- ],
182
- },
183
- {
184
- id: "40aff586-32a5-4142-9973-d35a0d596941",
185
- ipfs_pin_hash: "QmWTnoGJ7AP2c3USkX42SpG4YdiiWNuQNvcpxR3uy7ZWfM",
186
- size: 76626,
187
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
188
- date_pinned: "2022-10-05T22:45:33.758Z",
189
- date_unpinned: null,
190
- metadata: {
191
- name: "pin13.png",
192
- keyvalues: null,
193
- },
194
- regions: [
195
- {
196
- regionId: "FRA1",
197
- currentReplicationCount: 1,
198
- desiredReplicationCount: 1,
199
- },
200
- {
201
- regionId: "NYC1",
202
- currentReplicationCount: 1,
203
- desiredReplicationCount: 1,
204
- },
205
- ],
206
- },
207
- {
208
- id: "38814347-144f-4140-9838-f7fce4d11f21",
209
- ipfs_pin_hash: "QmZmUm6smWQqSquvWJr51e14fC6nT4HHsCWXcWKXnhNQH9",
210
- size: 139412,
211
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
212
- date_pinned: "2022-10-05T22:45:23.063Z",
213
- date_unpinned: null,
214
- metadata: {
215
- name: "pin12.png",
216
- keyvalues: null,
217
- },
218
- regions: [
219
- {
220
- regionId: "FRA1",
221
- currentReplicationCount: 1,
222
- desiredReplicationCount: 1,
223
- },
224
- {
225
- regionId: "NYC1",
226
- currentReplicationCount: 1,
227
- desiredReplicationCount: 1,
228
- },
229
- ],
230
- },
231
- {
232
- id: "381335b2-f64e-4c95-b5e6-63a6110bf639",
233
- ipfs_pin_hash: "QmVcwfTjRki1o7WvCkfMVVfv9oRj3kaFnfWLq62TuAEqD9",
234
- size: 146257,
235
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
236
- date_pinned: "2022-10-05T22:45:12.268Z",
237
- date_unpinned: null,
238
- metadata: {
239
- name: "pin11.png",
240
- keyvalues: null,
241
- },
242
- regions: [
243
- {
244
- regionId: "FRA1",
245
- currentReplicationCount: 1,
246
- desiredReplicationCount: 1,
247
- },
248
- {
249
- regionId: "NYC1",
250
- currentReplicationCount: 1,
251
- desiredReplicationCount: 1,
252
- },
253
- ],
254
- },
255
- {
256
- id: "b1ce6263-b1fb-4831-8c74-6f71b31e72c6",
257
- ipfs_pin_hash: "QmSWCZLFjGuWYjxDCvPcyqwA35kdH5RYExex3U2DXrXcfH",
258
- size: 89932,
259
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
260
- date_pinned: "2022-10-05T22:45:02.143Z",
261
- date_unpinned: null,
262
- metadata: {
263
- name: "pin10.png",
264
- keyvalues: null,
265
- },
266
- regions: [
267
- {
268
- regionId: "FRA1",
269
- currentReplicationCount: 1,
270
- desiredReplicationCount: 1,
271
- },
272
- {
273
- regionId: "NYC1",
274
- currentReplicationCount: 1,
275
- desiredReplicationCount: 1,
276
- },
277
- ],
278
- },
279
- {
280
- id: "65f89885-9a9c-47f5-8442-63942296f3f3",
281
- ipfs_pin_hash: "QmZpTaAAxUdscD6mMkYADYHVRbekhHvXyL6MCCRc4hcM4t",
282
- size: 121532,
283
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
284
- date_pinned: "2022-10-05T22:44:50.487Z",
285
- date_unpinned: null,
286
- metadata: {
287
- name: "pin9.png",
288
- keyvalues: null,
289
- },
290
- regions: [
291
- {
292
- regionId: "FRA1",
293
- currentReplicationCount: 1,
294
- desiredReplicationCount: 1,
295
- },
296
- {
297
- regionId: "NYC1",
298
- currentReplicationCount: 1,
299
- desiredReplicationCount: 1,
300
- },
301
- ],
302
- },
303
- {
304
- id: "d74055a9-4b6b-439e-99c0-b4b908d027c7",
305
- ipfs_pin_hash: "QmdKakBkbCpdeLTf3NMR382it4kZdo848FTvbSGNmmAmSi",
306
- size: 80314,
307
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
308
- date_pinned: "2022-10-05T22:44:38.972Z",
309
- date_unpinned: null,
310
- metadata: {
311
- name: "pin8.png",
312
- keyvalues: null,
313
- },
314
- regions: [
315
- {
316
- regionId: "FRA1",
317
- currentReplicationCount: 1,
318
- desiredReplicationCount: 1,
319
- },
320
- {
321
- regionId: "NYC1",
322
- currentReplicationCount: 1,
323
- desiredReplicationCount: 1,
324
- },
325
- ],
326
- },
327
- {
328
- id: "53a56f84-89c7-4947-979e-8f6e8d584151",
329
- ipfs_pin_hash: "QmfLTuCn3iyhgL6iyZqGNovnAkv5ip5oAPFWmPTYXkmFgb",
330
- size: 115132,
331
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
332
- date_pinned: "2022-10-05T22:44:28.357Z",
333
- date_unpinned: null,
334
- metadata: {
335
- name: "pin7.png",
336
- keyvalues: null,
337
- },
338
- regions: [
339
- {
340
- regionId: "FRA1",
341
- currentReplicationCount: 1,
342
- desiredReplicationCount: 1,
343
- },
344
- {
345
- regionId: "NYC1",
346
- currentReplicationCount: 1,
347
- desiredReplicationCount: 1,
348
- },
349
- ],
350
- },
351
- {
352
- id: "7ce5f037-b991-4bcb-b888-6f1dd2f4005c",
353
- ipfs_pin_hash: "QmaDVCBZ9sMQ7AFAqGqWqLymcetJBMsH9TuxwmqqZaVRss",
354
- size: 68293,
355
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
356
- date_pinned: "2022-10-05T22:44:16.939Z",
357
- date_unpinned: null,
358
- metadata: {
359
- name: "pin6.png",
360
- keyvalues: null,
361
- },
362
- regions: [
363
- {
364
- regionId: "FRA1",
365
- currentReplicationCount: 1,
366
- desiredReplicationCount: 1,
367
- },
368
- {
369
- regionId: "NYC1",
370
- currentReplicationCount: 1,
371
- desiredReplicationCount: 1,
372
- },
373
- ],
374
- },
375
- {
376
- id: "b6d9d849-51e4-4ea4-ae01-8c1cc000d0ad",
377
- ipfs_pin_hash: "QmNsq42HSV4CAvNLuwe9ZjPkUYQoGiwxXdfyRRLx7Njd7f",
378
- size: 82560,
379
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
380
- date_pinned: "2022-10-05T22:44:05.743Z",
381
- date_unpinned: null,
382
- metadata: {
383
- name: "pin5.png",
384
- keyvalues: null,
385
- },
386
- regions: [
387
- {
388
- regionId: "FRA1",
389
- currentReplicationCount: 1,
390
- desiredReplicationCount: 1,
391
- },
392
- {
393
- regionId: "NYC1",
394
- currentReplicationCount: 1,
395
- desiredReplicationCount: 1,
396
- },
397
- ],
398
- },
399
- {
400
- id: "ae45ab56-aa22-4ffd-8116-96a5b6bc6fc8",
401
- ipfs_pin_hash: "QmT8fjVvMZKEDgPZ3JcYqsZvdZLB1S8qT3FE777BE1R3RL",
402
- size: 38428,
403
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
404
- date_pinned: "2022-10-05T22:43:47.227Z",
405
- date_unpinned: null,
406
- metadata: {
407
- name: "pin4.png",
408
- keyvalues: null,
409
- },
410
- regions: [
411
- {
412
- regionId: "FRA1",
413
- currentReplicationCount: 1,
414
- desiredReplicationCount: 1,
415
- },
416
- {
417
- regionId: "NYC1",
418
- currentReplicationCount: 1,
419
- desiredReplicationCount: 1,
420
- },
421
- ],
422
- },
423
- {
424
- id: "86ee7b32-b723-4ef0-97ef-7efb4386ebcf",
425
- ipfs_pin_hash: "QmZCZwCqKG8tsLCeUCCeevdKAQJy53uLCwDuXptg1E9xUa",
426
- size: 113338,
427
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
428
- date_pinned: "2022-10-05T22:42:09.658Z",
429
- date_unpinned: null,
430
- metadata: {
431
- name: "pin3.png",
432
- keyvalues: null,
433
- },
434
- regions: [
435
- {
436
- regionId: "FRA1",
437
- currentReplicationCount: 1,
438
- desiredReplicationCount: 1,
439
- },
440
- {
441
- regionId: "NYC1",
442
- currentReplicationCount: 1,
443
- desiredReplicationCount: 1,
444
- },
445
- ],
446
- },
447
- {
448
- id: "76bb512a-52de-41ab-9008-22b0b0965a59",
449
- ipfs_pin_hash: "QmSgwD6mjitrh59koPLpswMtwUZnuASi7durphHuXUQnex",
450
- size: 23661,
451
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
452
- date_pinned: "2022-10-05T22:41:57.767Z",
453
- date_unpinned: null,
454
- metadata: {
455
- name: "pin2.png",
456
- keyvalues: null,
457
- },
458
- regions: [
459
- {
460
- regionId: "FRA1",
461
- currentReplicationCount: 1,
462
- desiredReplicationCount: 1,
463
- },
464
- {
465
- regionId: "NYC1",
466
- currentReplicationCount: 1,
467
- desiredReplicationCount: 1,
468
- },
469
- ],
470
- },
471
- {
472
- id: "0b5ba870-1230-47ba-8298-6de92978ff3f",
473
- ipfs_pin_hash: "QmNdoq9LuNmKYCKTWsCaowLWCZxv6K5payarU8i5TB4Bo6",
474
- size: 6850,
475
- user_id: "6002b716-edbd-40ee-8f64-c50e452ccc3a",
476
- date_pinned: "2022-10-05T22:41:45.109Z",
477
- date_unpinned: null,
478
- metadata: {
479
- name: "pin1.png",
480
- keyvalues: null,
481
- },
482
- regions: [
483
- {
484
- regionId: "FRA1",
485
- currentReplicationCount: 0,
486
- desiredReplicationCount: 1,
487
- },
488
- {
489
- regionId: "NYC1",
490
- currentReplicationCount: 1,
491
- desiredReplicationCount: 1,
492
- },
493
- ],
494
- },
495
- ],
496
- };
497
-
498
- export const pinListAxiosMockPages = {
499
- firstPage: {
500
- url: `${baseUrl}/data/pinList?includeCount=false&pageLimit=10&`,
501
- headers: fakeHeaders,
502
- response: {
503
- ...statusOk,
504
- data: {
505
- rows: APIData.rows.slice(0, 10),
506
- },
507
- },
508
- },
509
- secondPage: {
510
- url: `${baseUrl}/data/pinList?includeCount=false&pageLimit=10&pageOffset=10&`,
511
- headers: fakeHeaders,
512
- response: {
513
- ...statusOk,
514
- data: {
515
- rows: APIData.rows.slice(10, 20),
516
- },
517
- },
518
- },
519
- thirdPageEmpty: {
520
- url: `${baseUrl}/data/pinList?includeCount=false&pageLimit=10&pageOffset=20&`,
521
- headers: fakeHeaders,
522
- response: {
523
- ...statusOk,
524
- data: {
525
- rows: [],
526
- },
527
- },
528
- },
529
- firstPageEmpty: {
530
- url: `${baseUrl}/data/pinList?includeCount=false&pageLimit=10&`,
531
- headers: fakeHeaders,
532
-
533
- response: {
534
- ...statusOk,
535
- data: {
536
- rows: [],
537
- },
538
- },
539
- },
540
- };
@@ -1,65 +0,0 @@
1
- import axios from 'axios';
2
- import hashPinPolicy from'../../../src/commands/pinning/hashPinPolicy';
3
-
4
- jest.mock('axios');
5
-
6
- //common values
7
- const badHash = 'test';
8
- const goodHash = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
9
- const newPinPolicy = {
10
- regions: [
11
- {
12
- id: 'FRA1',
13
- desiredReplicationCount: 2
14
- },
15
- {
16
- id: 'NYC1',
17
- desiredReplicationCount: 2
18
- }
19
- ]
20
- };
21
-
22
- test('No ipfsPinHash value provided should error', () => {
23
- expect(() => {
24
- hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, null, newPinPolicy);
25
- }).toThrow();
26
- });
27
-
28
- test('Invalid ipfsPinHash value is provided', () => {
29
- expect(() => {
30
- hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHash, newPinPolicy);
31
- }).toThrow();
32
- });
33
-
34
- test('No newPinPolicy value provided should error', () => {
35
- expect(() => {
36
- hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash);
37
- }).toThrow();
38
- });
39
-
40
- test('200 status is returned', () => {
41
- const goodStatus = {
42
- status: 200,
43
- data: 'testData'
44
- };
45
- axios.put.mockResolvedValue(goodStatus);
46
- expect.assertions(1);
47
- expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).resolves.toEqual(goodStatus.data);
48
- });
49
-
50
- test('Result other than 200 status is returned', () => {
51
- const badStatus = {
52
- status: 700
53
- };
54
- axios.put.mockResolvedValue(badStatus);
55
- expect.assertions(1);
56
- expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
57
- });
58
-
59
- test('Rejection handled', () => {
60
- axios.put.mockRejectedValue('test error');
61
- expect.assertions(1);
62
- expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).rejects.toEqual('test error');
63
- });
64
-
65
-
@@ -1,80 +0,0 @@
1
- import axios from "axios";
2
- import userPinPolicy from "../../../src/commands/pinning/userPinPolicy";
3
-
4
- jest.mock("axios");
5
-
6
- //common values
7
- const newPinPolicy = {
8
- regions: [
9
- {
10
- id: "FRA1",
11
- desiredReplicationCount: 2,
12
- },
13
- {
14
- id: "NYC1",
15
- desiredReplicationCount: 2,
16
- },
17
- ],
18
- };
19
-
20
- test("No newPinPolicy value provided should error", () => {
21
- expect(() => {
22
- userPinPolicy({
23
- pinataApiKey: "test",
24
- pinataSecretApiKey: "test",
25
- });
26
- }).toThrow();
27
- });
28
-
29
- test("200 status is returned", () => {
30
- const goodStatus = {
31
- status: 200,
32
- data: "testData",
33
- };
34
- axios.put.mockResolvedValue(goodStatus);
35
- expect.assertions(1);
36
- expect(
37
- userPinPolicy(
38
- {
39
- pinataApiKey: "test",
40
- pinataSecretApiKey: "test",
41
- },
42
- newPinPolicy
43
- )
44
- ).resolves.toEqual(goodStatus.data);
45
- });
46
-
47
- test("Result other than 200 status is returned", () => {
48
- const badStatus = {
49
- status: 700,
50
- };
51
- axios.put.mockResolvedValue(badStatus);
52
- expect.assertions(1);
53
- expect(
54
- userPinPolicy(
55
- {
56
- pinataApiKey: "test",
57
- pinataSecretApiKey: "test",
58
- },
59
- newPinPolicy
60
- )
61
- ).rejects.toEqual(
62
- Error(
63
- `unknown server response while changing pin policy for user: ${badStatus}`
64
- )
65
- );
66
- });
67
-
68
- test("Rejection handled", () => {
69
- axios.put.mockRejectedValue("test error");
70
- expect.assertions(1);
71
- expect(
72
- userPinPolicy(
73
- {
74
- pinataApiKey: "test",
75
- pinataSecretApiKey: "test",
76
- },
77
- newPinPolicy
78
- )
79
- ).rejects.toEqual("test error");
80
- });