@pinata/sdk 1.1.23 → 1.1.24
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.
package/package.json
CHANGED
|
@@ -24,8 +24,8 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
|
|
|
24
24
|
|
|
25
25
|
const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
|
|
26
26
|
|
|
27
|
-
if (!(readStream instanceof stream.Readable)) {
|
|
28
|
-
reject(new Error('readStream is not a readable stream'));
|
|
27
|
+
if (!(readStream instanceof stream.Readable || readStream instanceof NodeFormData)) {
|
|
28
|
+
reject(new Error('readStream is not a readable stream or form data'));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
if (options) {
|
|
@@ -41,7 +41,7 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
|
|
|
41
41
|
|
|
42
42
|
axios.post(
|
|
43
43
|
endpoint,
|
|
44
|
-
data,
|
|
44
|
+
readStream instanceof NodeFormData ? readStream : data,
|
|
45
45
|
{
|
|
46
46
|
withCredentials: true,
|
|
47
47
|
maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import pinFileToIPFS from'../../../src/commands/pinning/pinFileToIPFS';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import NodeFormData from 'form-data';
|
|
4
5
|
jest.mock('axios');
|
|
5
6
|
|
|
6
7
|
//common values
|
|
7
8
|
const nonStream = 'test';
|
|
8
9
|
const validStream = fs.createReadStream('./pinata.png');
|
|
10
|
+
const validFormData = new NodeFormData();
|
|
11
|
+
validFormData.append('file', validStream, {filepath: 'test/filepath'});
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
test('non-readableStream is passed in', () => {
|
|
12
|
-
expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream'));
|
|
14
|
+
test('non-readableStream and non-formData is passed in', () => {
|
|
15
|
+
expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
|
|
13
16
|
|
|
14
17
|
return undefined;
|
|
15
18
|
});
|
|
16
19
|
|
|
17
|
-
test('200 status is returned', () => {
|
|
20
|
+
test('200 status is returned with valid stream', () => {
|
|
18
21
|
const goodStatus = {
|
|
19
22
|
status: 200,
|
|
20
23
|
data: 'testData'
|
|
@@ -24,6 +27,16 @@ test('200 status is returned', () => {
|
|
|
24
27
|
expect(pinFileToIPFS('test', 'test', validStream)).resolves.toEqual(goodStatus.data);
|
|
25
28
|
});
|
|
26
29
|
|
|
30
|
+
test('200 status is returned with valid form data', () => {
|
|
31
|
+
const goodStatus = {
|
|
32
|
+
status: 200,
|
|
33
|
+
data: 'testData'
|
|
34
|
+
};
|
|
35
|
+
axios.post.mockResolvedValue(goodStatus);
|
|
36
|
+
expect.assertions(1);
|
|
37
|
+
expect(pinFileToIPFS('test', 'test', validFormData)).resolves.toEqual(goodStatus.data);
|
|
38
|
+
});
|
|
39
|
+
|
|
27
40
|
test('Result other than 200 status is returned', () => {
|
|
28
41
|
const badStatus = {
|
|
29
42
|
status: 700
|