Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
12 changes: 12 additions & 0 deletions packages/composer-rest-server/test/data/bond-network/queries.qry
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ query findBondByFaceAmount {
description: "Find all bonds with a face amount greater than _$faceAmount"
statement: SELECT org.acme.bond.BondAsset WHERE (bond.faceAmount > _$faceAmount)
}
query findBondByPaymentFrequencyPeriod {
description: "Find all bonds with a payment frequecy period _$period"
statement: SELECT org.acme.bond.BondAsset WHERE (bond.paymentFrequency.period == _$period)
}
query findBondByPaymentFrequencyPeriodMultiplier {
description: "Find all bonds with a payment frequecy period multiplier _$multiplier"
statement: SELECT org.acme.bond.BondAsset WHERE (bond.paymentFrequency.periodMultiplier == _$multiplier)
}
query findBondByExchangeIdUnsupported {
description: "Find all bonds with a set of exchange id _$exchangeId is unsupported"
statement: SELECT org.acme.bond.BondAsset WHERE (bond.exchangeId == _$exchangeId)
}
101 changes: 83 additions & 18 deletions packages/composer-rest-server/test/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
$class: 'org.acme.bond.Bond',
dayCountFraction: 'EOM',
exchangeId: [
'NYSE'
'LDN'
],
faceAmount: 1000,
instrumentId: [
'AliceCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
maturity: '2018-02-27T21:03:52.000Z',
maturity: '2017-02-27T21:03:52.000Z',
parValue: 1000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
periodMultiplier: 6
periodMultiplier: 7
}
}
}, {
Expand All @@ -66,13 +66,13 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
instrumentId: [
'BobCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
maturity: '2018-02-27T21:03:52.000Z',
issuer: 'resource:org.acme.bond.Issuer#2',
maturity: '2017-02-27T21:03:52.000Z',
parValue: 1000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
periodMultiplier: 6
periodMultiplier: 7
}
}
}, {
Expand All @@ -84,39 +84,39 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
exchangeId: [
'NYSE'
],
faceAmount: 1000,
faceAmount: 500,
instrumentId: [
'CharlieCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
issuer: 'resource:org.acme.bond.Issuer#3',
maturity: '2018-02-27T21:03:52.000Z',
parValue: 1000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
periodMultiplier: 6
period: 'YEAR',
periodMultiplier: 1
}
}
}, {
// $class: 'org.acme.bond.BondAsset',
$class: 'org.acme.bond.BondAsset',
ISINCode: 'ISIN_4',
bond: {
$class: 'org.acme.bond.Bond',
dayCountFraction: 'EOM',
exchangeId: [
'NYSE'
],
faceAmount: 1000,
faceAmount: 500,
instrumentId: [
'DogeCorp'
],
issuer: 'resource:org.acme.bond.Issuer#1',
issuer: 'resource:org.acme.bond.Issuer#4',
maturity: '2018-02-27T21:03:52.000Z',
parValue: 1000,
paymentFrequency: {
$class: 'org.acme.bond.PaymentFrequency',
period: 'MONTH',
periodMultiplier: 6
period: 'YEAR',
periodMultiplier: 1
}
}
}];
Expand Down Expand Up @@ -164,14 +164,16 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
assetRegistry = assetRegistry_;
return assetRegistry.addAll([
serializer.fromJSON(assetData[0]),
serializer.fromJSON(assetData[1])
serializer.fromJSON(assetData[1]),
serializer.fromJSON(assetData[2]),
serializer.fromJSON(assetData[3])
]);
});
});

describe(`GET / namespaces[${namespaces}]`, () => {

it('should return all of the assets', () => {
it('should return all of the assets with a double type variable', () => {
return chai.request(app)
.get('/api/queries/findBondByFaceAmount?faceAmount=500')
.then((res) => {
Expand All @@ -182,7 +184,70 @@ const bfs_fs = BrowserFS.BFSRequire('fs');
]);
});
});

it('should return a 404 if query a double type vairable with a non-existing value', () => {
return chai.request(app)
.get('/api/queries/findBondByFaceAmount?faceAmount=10000')
.catch((err) => {
err.response.should.have.status(404);
});
});
it('should return all of the assets with an enum type variable', () => {
return chai.request(app)
.get('/api/queries/findBondByPaymentFrequencyPeriod?period=MONTH')
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0],
assetData[1],
]);
});
});
it('should return a 404 if query an enum type vairable with a non-existing value', () => {
return chai.request(app)
.get('/api/queries/findBondByPaymentFrequencyPeriod?period=QUARTER')
.catch((err) => {
err.response.should.have.status(404);
});
});
it('should return all of the assets with an integer type variable', () => {
return chai.request(app)
.get('/api/queries/findBondByPaymentFrequencyPeriodMultiplier?multiplier=7')
.then((res) => {
res.should.be.json;
res.body.should.deep.equal([
assetData[0],
assetData[1],
]);
});
});
it('should return a 404 if query an integer type vairable with a non-existing value', () => {
return chai.request(app)
.get('/api/queries/findBondByPaymentFrequencyPeriodMultiplier?multiplier=6')
.catch((err) => {
err.response.should.have.status(404);
});
});
it('should return a 404 if the query specified variable is an unsupported array type', () => {
return chai.request(app)
.get('/api/queries/findBondByExchangeIdUnsupported?exchangeId[]=LDN')
.catch((err) => {
err.response.should.have.status(404);
});
});
it('should return a 404 if the specified asset does not exist', () => {
return chai.request(app)
.get('/api/queries/findBondByMaturity?maturity=2019-02-27T21:03:52.000Z')
.catch((err) => {
err.response.should.have.status(404);
});
});
it('should return a 404 if the specified query does not exist', () => {
return chai.request(app)
.get('/api/queries/nonDefinedQuery?wombat=cuddly')
.catch((err) => {
err.response.should.have.status(404);
});
});
});
});
});