@@ -10,13 +10,15 @@ const API = require('../../src/http')
10
10
const loadFixture = require ( 'aegir/fixtures' )
11
11
const os = require ( 'os' )
12
12
const path = require ( 'path' )
13
+ const fileType = require ( 'file-type' )
13
14
14
15
const bigFile = loadFixture ( __dirname , '../../node_modules/interface-ipfs-core/test/fixtures/15mb.random' , 'ipfs' )
15
16
const directoryContent = {
16
17
'index.html' : loadFixture ( __dirname , './test-folder/index.html' , 'ipfs' ) ,
17
18
'nested-folder/hello.txt' : loadFixture ( __dirname , './test-folder/nested-folder/hello.txt' , 'ipfs' ) ,
18
19
'nested-folder/ipfs.txt' : loadFixture ( __dirname , './test-folder/nested-folder/ipfs.txt' , 'ipfs' ) ,
19
- 'nested-folder/nested.html' : loadFixture ( __dirname , './test-folder/nested-folder/nested.html' , 'ipfs' )
20
+ 'nested-folder/nested.html' : loadFixture ( __dirname , './test-folder/nested-folder/nested.html' , 'ipfs' ) ,
21
+ 'cat-folder/cat.jpg' : loadFixture ( __dirname , './test-folder/cat-folder/cat.jpg' , 'ipfs' )
20
22
}
21
23
22
24
describe ( 'HTTP Gateway' , ( ) => {
@@ -38,17 +40,17 @@ describe('HTTP Gateway', () => {
38
40
}
39
41
} )
40
42
43
+ const content = ( name ) => ( {
44
+ path : `test-folder/${ name } ` ,
45
+ content : directoryContent [ name ]
46
+ } )
47
+
48
+ const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
49
+
41
50
series ( [
42
51
( cb ) => http . api . start ( true , cb ) ,
43
52
( cb ) => {
44
53
gateway = http . api . server . select ( 'Gateway' )
45
- const content = ( name ) => ( {
46
- path : `test-folder/${ name } ` ,
47
- content : directoryContent [ name ]
48
- } )
49
-
50
- const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
51
-
52
54
const expectedRootMultihash = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi'
53
55
54
56
const dirs = [
@@ -79,6 +81,32 @@ describe('HTTP Gateway', () => {
79
81
expect ( file . hash ) . to . equal ( expectedMultihash )
80
82
cb ( )
81
83
} )
84
+ } ,
85
+ ( cb ) => {
86
+ const expectedMultihash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
87
+
88
+ http . api . node . files . add ( Buffer . from ( 'hello world' + '\n' ) , ( err , res ) => {
89
+ expect ( err ) . to . not . exist ( )
90
+ const file = res [ 0 ]
91
+ expect ( file . path ) . to . equal ( expectedMultihash )
92
+ expect ( file . hash ) . to . equal ( expectedMultihash )
93
+ cb ( )
94
+ } )
95
+ } ,
96
+ ( cb ) => {
97
+ const expectedMultihash = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ'
98
+
99
+ let dir = [
100
+ content ( 'cat-folder/cat.jpg' )
101
+ ]
102
+
103
+ http . api . node . files . add ( dir , ( err , res ) => {
104
+ expect ( err ) . to . not . exist ( )
105
+ const file = res [ 1 ]
106
+ expect ( file . path ) . to . equal ( 'test-folder/cat-folder' )
107
+ expect ( file . hash ) . to . equal ( expectedMultihash )
108
+ cb ( )
109
+ } )
82
110
}
83
111
] , done )
84
112
} )
@@ -142,6 +170,11 @@ describe('HTTP Gateway', () => {
142
170
} , ( res ) => {
143
171
expect ( res . statusCode ) . to . equal ( 200 )
144
172
expect ( res . headers [ 'content-type' ] ) . to . equal ( 'image/jpeg' )
173
+
174
+ let fileSignature = fileType ( res . rawPayload )
175
+ expect ( fileSignature . mime ) . to . equal ( 'image/jpeg' )
176
+ expect ( fileSignature . ext ) . to . equal ( 'jpg' )
177
+
145
178
done ( )
146
179
} )
147
180
} )
@@ -155,6 +188,11 @@ describe('HTTP Gateway', () => {
155
188
} , ( res ) => {
156
189
expect ( res . statusCode ) . to . equal ( 200 )
157
190
expect ( res . headers [ 'content-type' ] ) . to . equal ( 'text/html; charset=utf-8' )
191
+
192
+ // check if the cat picture is in the payload as a way to check
193
+ // if this is an index of this directory
194
+ let listedFile = res . payload . match ( / \/ i p f s \/ Q m W 2 W Q i 7 j 6 c 7 U g J T a r A c t p 7 t D N i k E 4 B 2 q X t F C f L P d s g a T Q \/ c a t \. j p g / g)
195
+ expect ( listedFile ) . to . have . lengthOf ( 1 )
158
196
done ( )
159
197
} )
160
198
} )
0 commit comments