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

Commit

Permalink
test: add HTTP API tests for resolve with cid-base option
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw committed Nov 16, 2018
1 parent c95af53 commit 613bf0c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/http-api/inject/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const expect = require('chai').expect
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
const multibase = require('multibase')

module.exports = (http) => {
describe('resolve', () => {
let api

before(() => {
api = http.api.server.select('API')
})

it('should resolve a path and return a base2 encoded CID', done => {
const form = new FormData()
form.append('data', Buffer.from('TEST' + Date.now()))
const headers = form.getHeaders()

streamToPromise(form).then((payload) => {
api.inject({
method: 'POST',
url: '/api/v0/add',
headers: headers,
payload: payload
}, (res) => {
expect(res.statusCode).to.equal(200)
const hash = JSON.parse(res.result).Hash

api.inject({
method: 'POST',
url: `/api/v0/resolve?arg=/ipfs/${hash}&cid-base=base2`
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(multibase.isEncoded(res.result.Path.replace('/ipfs/', ''))).to.deep.equal('base2')
done()
})
})
})
})

it('should not resolve a path for invalid cid-base option', done => {
const form = new FormData()
form.append('data', Buffer.from('TEST' + Date.now()))
const headers = form.getHeaders()

streamToPromise(form).then((payload) => {
api.inject({
method: 'POST',
url: '/api/v0/add',
headers: headers,
payload: payload
}, (res) => {
expect(res.statusCode).to.equal(200)
const hash = JSON.parse(res.result).Hash

api.inject({
method: 'POST',
url: `/api/v0/resolve?arg=/ipfs/${hash}&cid-base=invalid`
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result.Message).to.include('child "cid-base" fails')
done()
})
})
})
})
})
}

0 comments on commit 613bf0c

Please sign in to comment.