Skip to content

Commit

Permalink
move filter tests into single test file and scope other filter tests (h…
Browse files Browse the repository at this point in the history
…yperledger-archives#2467)

Signed-off-by: Nick Lincoln <[email protected]>
  • Loading branch information
nklincoln authored and cazfletch committed Oct 25, 2017
1 parent bc93f33 commit 0553288
Show file tree
Hide file tree
Showing 3 changed files with 517 additions and 166 deletions.
134 changes: 0 additions & 134 deletions packages/composer-rest-server/test/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,140 +185,6 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
]);
});
});
it('should return the asset with a specified id', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"ISINCode":"ISIN_1"}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the asset with a specified non-id property', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.dayCountFraction":"EOM"}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the assets with a specified non-id property in a different format', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter[where][bond.dayCountFraction]=EOM`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the asset with multiple specified non-id properties', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.dayCountFraction":"EOM", "bond.faceAmount":1000}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the asset with multiple specified non-id properties including a datetime', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.dayCountFraction":"EOM", "bond.maturity":"2018-02-27T21:03:52.000Z"}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the assets with a range of specified properties for a datetime value', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.maturity":{"between":["2018-02-27T21:03:52.000Z", "2018-12-27T21:03:52.000Z"]}}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0],
assetData[1]
]);
});
});

it('should return the assets with a range of specified properties for a number value', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.faceAmount":{"between":[1000, 1500]}}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return the assets with a range of specified properties for a string value', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"bond.dayCountFraction":{"between":["EOM", "EOY"]}}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0],
assetData[1]
]);
});
});

it('should return the assets with a combination of the or operator with mutiple properties', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"or":[{"bond.dayCountFraction":"EOM"}, {"bond.maturity":"2018-12-27T21:03:52.000Z"}, {"bond.faceAmount":1000}]}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0],
assetData[1]
]);
});
});

it('should return the assets with a combination of the and operator with mutiple properties', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"and":[{"bond.dayCountFraction":"EOM"},{"bond.maturity":{"lt":"2018-12-27T21:03:52.000Z"}}]}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

it('should return a 500 if the and|or operator has more than three properties which is a limitation of pouchdb', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"and":[{"bond.dayCountFraction":"EOM"},{"bond.faceAmount":{"lt":2000}}, {"bond.paymentFrequency.period":"YEAR"}]}}`)
.then(() => {
throw new Error('should not get here');
})
.catch((err) => {
err.response.should.have.status(500);
});
});

it('should return the assets with a nested of the \'and\' and the \'or\' operator with mutiple properties', () => {
return chai.request(app)
.get(`/api/${prefix}BondAsset?filter={"where":{"and":[{"bond.dayCountFraction":"EOM"},{"or":[{"bond.maturity":"2018-12-27T21:03:52.000Z"}, {"bond.faceAmount":1000}]}]}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0]
]);
});
});

});

Expand Down
Loading

0 comments on commit 0553288

Please sign in to comment.