Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 7cae803

Browse files
ya7yadaviddias
authored andcommitted
test: fix failing gateway tests with this one simple trick! (#1006)
* fix failing tests with this one simple trick! * adding files to make tests self-contained * changes requested by VictorBjelkholm #968
1 parent 94cec9b commit 7cae803

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

test/gateway/index.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ const API = require('../../src/http')
1010
const loadFixture = require('aegir/fixtures')
1111
const os = require('os')
1212
const path = require('path')
13+
const fileType = require('file-type')
1314

1415
const bigFile = loadFixture(__dirname, '../../node_modules/interface-ipfs-core/test/fixtures/15mb.random', 'ipfs')
1516
const directoryContent = {
1617
'index.html': loadFixture(__dirname, './test-folder/index.html', 'ipfs'),
1718
'nested-folder/hello.txt': loadFixture(__dirname, './test-folder/nested-folder/hello.txt', 'ipfs'),
1819
'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')
2022
}
2123

2224
describe('HTTP Gateway', () => {
@@ -38,17 +40,17 @@ describe('HTTP Gateway', () => {
3840
}
3941
})
4042

43+
const content = (name) => ({
44+
path: `test-folder/${name}`,
45+
content: directoryContent[name]
46+
})
47+
48+
const emptyDir = (name) => ({ path: `test-folder/${name}` })
49+
4150
series([
4251
(cb) => http.api.start(true, cb),
4352
(cb) => {
4453
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-
5254
const expectedRootMultihash = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi'
5355

5456
const dirs = [
@@ -79,6 +81,32 @@ describe('HTTP Gateway', () => {
7981
expect(file.hash).to.equal(expectedMultihash)
8082
cb()
8183
})
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+
})
82110
}
83111
], done)
84112
})
@@ -142,6 +170,11 @@ describe('HTTP Gateway', () => {
142170
}, (res) => {
143171
expect(res.statusCode).to.equal(200)
144172
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+
145178
done()
146179
})
147180
})
@@ -155,6 +188,11 @@ describe('HTTP Gateway', () => {
155188
}, (res) => {
156189
expect(res.statusCode).to.equal(200)
157190
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(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g)
195+
expect(listedFile).to.have.lengthOf(1)
158196
done()
159197
})
160198
})
433 KB
Loading

0 commit comments

Comments
 (0)