Skip to content

Commit

Permalink
Feature 2106 (hyperledger-archives#2229)
Browse files Browse the repository at this point in the history
* feature-2106 functions

* feature-2106 update

* #2106 adding unit test

* #2106 add more unit test for the filter parser

* #2106 the complete unit test for the filter parser

* #2106 update the fix for boolean the between test value

* #2106 updated code and unit test after the code review

* add system test to asset for the filter where syntax support #2106

* add system test for participants #feature-2106

* updated integration code for all and count #2106

* add the api count function test #2106

* add the api count function test for participants #2106

* update the api count function to handle the query #2106

* update to ensure the resolve method only for the id

* add a few test cases in whereCondition parser #2106
  • Loading branch information
fenglianxu authored and cazfletch committed Oct 5, 2017
1 parent e123790 commit b0e852e
Show file tree
Hide file tree
Showing 9 changed files with 939 additions and 46 deletions.
156 changes: 145 additions & 11 deletions packages/composer-rest-server/test/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
ISINCode: 'ISIN_2',
bond: {
$class: 'org.acme.bond.Bond',
dayCountFraction: 'EOM',
dayCountFraction: 'EOY',
exchangeId: [
'NYSE'
],
faceAmount: 1000,
faceAmount: 2000,
instrumentId: [
'BobCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
maturity: '2018-02-27T21:03:52.000Z',
parValue: 1000,
issuer: 'resource:org.acme.bond.Issuer#2',
maturity: '2018-12-27T21:03:52.000Z',
parValue: 2000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
periodMultiplier: 6
period: 'YEAR',
periodMultiplier: 1
}
}
}, {
Expand All @@ -87,13 +87,13 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
exchangeId: [
'NYSE'
],
faceAmount: 1000,
faceAmount: 3000,
instrumentId: [
'CharlieCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
maturity: '2018-02-27T21:03:52.000Z',
parValue: 1000,
parValue: 3000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
Expand All @@ -109,13 +109,13 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
exchangeId: [
'NYSE'
],
faceAmount: 1000,
faceAmount: 4000,
instrumentId: [
'DogeCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
maturity: '2018-02-27T21:03:52.000Z',
parValue: 1000,
parValue: 4000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
Expand Down Expand Up @@ -185,6 +185,140 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ enum CouponType {
participant Member identified by memberId {
o String memberId
o String name
o String lastName optional
}

participant Issuer extends Member {

}

enum PeriodEnum {
Expand Down
41 changes: 38 additions & 3 deletions packages/composer-rest-server/test/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
const participantData = [{
$class: 'org.acme.bond.Member',
memberId: 'MEMBER_1',
name: 'Alice'
name: 'Alice',
lastName: 'Stone'
}, {
$class: 'org.acme.bond.Member',
memberId: 'MEMBER_2',
name: 'Bob'
name: 'Bob',
lastName: 'Bond'
}, {
$class: 'org.acme.bond.Member',
memberId: 'MEMBER_3',
name: 'Charlie'
name: 'Charlie',
lastName: 'Chow'
}, {
// $class: 'org.acme.bond.Member',
memberId: 'MEMBER_4',
Expand Down Expand Up @@ -114,6 +117,38 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
});
});

it('should return all of the participants with a specified property value', () => {
return chai.request(app)
.get(`/api/${prefix}Member?filter={"where": {"name": "Bob"}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
participantData[1]
]);
});
});

it('should return all of the participants with a range of property value', () => {
return chai.request(app)
.get(`/api/${prefix}Member?filter={"where": {"lastName": {"between":["A", "C"]}}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
participantData[1]
]);
});
});

it('should return an empty with a specified property value does not exsit in the registry', () => {
return chai.request(app)
.get(`/api/${prefix}Member?filter={"where": {"lastName": "Chow"}}`)
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
]);
});
});

});

describe(`POST / namespaces[${namespaces}]`, () => {
Expand Down
Loading

0 comments on commit b0e852e

Please sign in to comment.