This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): Refactor inject tests, made them all pass again
- Loading branch information
Showing
22 changed files
with
1,289 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
|
||
module.exports = (http) => { | ||
describe('/bitswap', () => { | ||
let api | ||
|
||
before(() => { | ||
api = http.api.server.select('API') | ||
}) | ||
|
||
it('/wantlist', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bitswap/wantlist' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
expect(res.result).to.have.property('Keys') | ||
// TODO test that there actual values in there | ||
done() | ||
}) | ||
}) | ||
|
||
it('/stat', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bitswap/stat' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
|
||
expect(res.result).to.have.keys([ | ||
'BlocksReceived', | ||
'Wantlist', | ||
'Peers', | ||
'DupBlksReceived', | ||
'DupDataReceived' | ||
]) | ||
// TODO test that there actual values in there | ||
done() | ||
}) | ||
}) | ||
|
||
it.skip('/unwant', () => { | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const fs = require('fs') | ||
const FormData = require('form-data') | ||
const streamToPromise = require('stream-to-promise') | ||
|
||
module.exports = (http) => { | ||
describe('/block', () => { | ||
let api | ||
|
||
before(() => { | ||
api = http.api.server.select('API') | ||
}) | ||
|
||
describe('/block/put', () => { | ||
it('returns 400 if no node is provided', (done) => { | ||
const form = new FormData() | ||
const headers = form.getHeaders() | ||
|
||
streamToPromise(form).then((payload) => { | ||
api.inject({ | ||
method: 'POST', | ||
url: '/api/v0/block/put', | ||
headers: headers, | ||
payload: payload | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(400) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('updates value', (done) => { | ||
const form = new FormData() | ||
const filePath = 'test/test-data/hello' | ||
form.append('data', fs.createReadStream(filePath)) | ||
const headers = form.getHeaders() | ||
const expectedResult = { | ||
Key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', | ||
Size: 12 | ||
} | ||
|
||
streamToPromise(form).then((payload) => { | ||
api.inject({ | ||
method: 'POST', | ||
url: '/api/v0/block/put', | ||
headers: headers, | ||
payload: payload | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
expect(res.result).to.deep.equal(expectedResult) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/block/get', () => { | ||
it('returns 400 for request without argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/get' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(400) | ||
expect(res.result).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns 500 for request with invalid argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/get?arg=invalid' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(500) | ||
expect(res.result.Code).to.equal(0) | ||
expect(res.result.Message).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns value', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/get?arg=QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
expect(res.result) | ||
.to.equal('hello world\n') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/block/stat', () => { | ||
it('returns 400 for request without argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/stat' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(400) | ||
expect(res.result).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns 500 for request with invalid argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/stat?arg=invalid' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(500) | ||
expect(res.result.Code).to.equal(0) | ||
expect(res.result.Message).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns value', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/stat?arg=QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
expect(res.result.Key) | ||
.to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') | ||
expect(res.result.Size).to.equal(12) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/block/del', () => { | ||
it('returns 400 for request without argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/del' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(400) | ||
expect(res.result).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns 500 for request with invalid argument', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/del?arg=invalid' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(500) | ||
expect(res.result.Code).to.equal(0) | ||
expect(res.result.Message).to.be.a('string') | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns 200', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/block/del?arg=QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' | ||
}, (res) => { | ||
expect(res.statusCode).to.equal(200) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
|
||
module.exports = (http) => { | ||
describe('/bootstrap', () => { | ||
let api | ||
|
||
before(() => { | ||
api = http.api.server.select('API') | ||
}) | ||
|
||
it('/list', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bootstrap/list' | ||
}, (res) => { | ||
expect(res.result).to.deep.equal(defaultList) | ||
done() | ||
}) | ||
}) | ||
|
||
it('/list alias', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bootstrap' | ||
}, (res) => { | ||
expect(res.result).to.deep.equal(defaultList) | ||
done() | ||
}) | ||
}) | ||
|
||
it.skip('/add', (done) => { // TODO | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bootstrap/add', | ||
payload: { | ||
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' | ||
} | ||
}, (res) => { | ||
// TODO assess | ||
}) | ||
}) | ||
|
||
it.skip('/rm', (done) => { // TODO | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bootstrap/rm', | ||
payload: { | ||
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' | ||
} | ||
}, (res) => { | ||
// TODO assess | ||
}) | ||
}) | ||
|
||
it.skip('/list confirm it changed', (done) => { // TODO | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/bootstrap/list' | ||
}, (res) => { | ||
// TODO assess | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
const defaultList = [ | ||
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', | ||
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', | ||
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', | ||
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', | ||
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', | ||
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', | ||
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', | ||
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', | ||
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' | ||
] |
Oops, something went wrong.