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

Commit f857c37

Browse files
author
Alan Shaw
committed
test: add HTTP API test for ls with cid-base option
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 9b3d0a0 commit f857c37

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

test/http-api/inject/files.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = (http) => {
5959
expect(multibase.isEncoded(JSON.parse(res.result).Hash)).to.deep.equal('base64')
6060
done()
6161
})
62-
}).catch(err => console.error(err))
62+
})
6363
})
6464

6565
it('should add data without pinning and return a base64 encoded CID', (done) => {
@@ -78,7 +78,7 @@ module.exports = (http) => {
7878
expect(multibase.isEncoded(JSON.parse(res.result).Hash)).to.deep.equal('base64')
7979
done()
8080
})
81-
}).catch(err => console.error(err))
81+
})
8282
})
8383
})
8484

@@ -120,6 +120,37 @@ module.exports = (http) => {
120120

121121
describe('/get', () => {}) // TODO
122122

123-
describe('/ls', () => {}) // TODO
123+
describe('/ls', () => {
124+
it('should list directory contents and return a base64 encoded CIDs', (done) => {
125+
const form = new FormData()
126+
form.append('file', Buffer.from('TEST' + Date.now()), { filename: 'data.txt' })
127+
const headers = form.getHeaders()
128+
129+
streamToPromise(form).then((payload) => {
130+
api.inject({
131+
method: 'POST',
132+
url: '/api/v0/add?wrap-with-directory=true',
133+
headers: headers,
134+
payload: payload
135+
}, (res) => {
136+
expect(res.statusCode).to.equal(200)
137+
138+
const files = res.result.trim().split('\n').map(r => JSON.parse(r))
139+
const dir = files[files.length - 1]
140+
141+
api.inject({
142+
method: 'POST',
143+
url: '/api/v0/ls?cid-base=base64&arg=' + dir.Hash
144+
}, (res) => {
145+
expect(res.statusCode).to.equal(200)
146+
res.result.Objects.forEach(item => {
147+
expect(multibase.isEncoded(item.Hash)).to.deep.equal('base64')
148+
})
149+
done()
150+
})
151+
})
152+
})
153+
})
154+
})
124155
})
125156
}

0 commit comments

Comments
 (0)