forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unit tests for the query parsers and functions * UT-1234 more update * update with more query instance * remove the comments between two quiry statment
- Loading branch information
1 parent
5c21868
commit edfed42
Showing
12 changed files
with
674 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ class Limit { | |
|
||
this.ast = ast; | ||
this.select = select; | ||
this.process(); | ||
} | ||
|
||
/** | ||
|
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
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 |
---|---|---|
|
@@ -40,7 +40,6 @@ class Where { | |
|
||
this.ast = ast; | ||
this.select = select; | ||
this.process(); | ||
} | ||
|
||
/** | ||
|
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,94 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Limit = require('../../lib/query/limit'); | ||
const parser = require('../../lib/query/parser'); | ||
|
||
const Select = require('../../lib/query/select'); | ||
|
||
require('chai').should(); | ||
const sinon = require('sinon'); | ||
|
||
describe('Limit', () => { | ||
|
||
// let modelManager; | ||
let sandbox; | ||
let mockSelect; | ||
|
||
const selectWhereLimit = parser.parse('SELECT org.acme.Driver WHERE (prop = "value") LIMIT 10', { startRule: 'SelectStatement' }); | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
mockSelect = sinon.createStubInstance(Select); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#constructor', () => { | ||
|
||
it('should throw when null select provided', () => { | ||
(() => { | ||
new Limit(null, null); | ||
}).should.throw(/Invalid Select or AST/); | ||
}); | ||
|
||
it('should throw when null ast provided', () => { | ||
(() => { | ||
new Limit(mockSelect, null); | ||
}).should.throw(/Invalid Select or AST/); | ||
}); | ||
|
||
}); | ||
|
||
describe('#accept', () => { | ||
|
||
it('should call the visitor', () => { | ||
let l = new Limit(mockSelect, selectWhereLimit.limit); | ||
let visitor = { | ||
visit: sinon.stub() | ||
}; | ||
l.accept(visitor, ['some', 'args']); | ||
sinon.assert.calledOnce(visitor.visit); | ||
sinon.assert.calledWith(visitor.visit, l, ['some', 'args']); | ||
}); | ||
}); | ||
|
||
describe('#getSelect', () => { | ||
|
||
it('should return the select', () => { | ||
const l = new Limit(mockSelect, selectWhereLimit.limit); | ||
l.getSelect().should.equal(mockSelect); | ||
}); | ||
|
||
}); | ||
|
||
describe('#validate', () => { | ||
|
||
// TODO no validation method implemented yet | ||
|
||
}); | ||
|
||
describe('#getAST', () => { | ||
|
||
it('should return the limit clause', () => { | ||
const l = new Limit(mockSelect, selectWhereLimit.limit); | ||
l.getAST().type.should.equal('Literal'); | ||
l.getAST().value.should.equal(10); | ||
}); | ||
}); | ||
}); |
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,95 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const OrderBy = require('../../lib/query/orderby'); | ||
const parser = require('../../lib/query/parser'); | ||
const Select = require('../../lib/query/select'); | ||
const sinon = require('sinon'); | ||
|
||
describe('OrderBy', () => { | ||
|
||
let sandbox; | ||
let mockSelect; | ||
|
||
const selectWhereOrderBy = parser.parse('SELECT org.acme.Driver WHERE (prop = "value") ORDER BY [id ASC]', { startRule: 'SelectStatement' }); | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
mockSelect = sinon.createStubInstance(Select); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('#constructor', () => { | ||
|
||
it('should throw when null select provided', () => { | ||
(() => { | ||
new OrderBy(null, null); | ||
}).should.throw(/Invalid Select or AST/); | ||
}); | ||
|
||
it('should throw when null ast provided', () => { | ||
(() => { | ||
new OrderBy(mockSelect, null); | ||
}).should.throw(/Invalid Select or AST/); | ||
}); | ||
|
||
it('should throw when invalid ast provided', () => { | ||
(() => { | ||
new OrderBy(mockSelect, 'force failure'); | ||
}).should.throw(/Invalid AST/); | ||
}); | ||
}); | ||
|
||
describe('#accept', () => { | ||
|
||
it('should call the visitor', () => { | ||
let o = new OrderBy(mockSelect, selectWhereOrderBy.orderBy); | ||
let visitor = { | ||
visit: sinon.stub() | ||
}; | ||
o.accept(visitor, ['some', 'args']); | ||
sinon.assert.calledOnce(visitor.visit); | ||
sinon.assert.calledWith(visitor.visit, o, ['some', 'args']); | ||
}); | ||
}); | ||
|
||
describe('#getSelect', () => { | ||
|
||
it('should return the select', () => { | ||
const o = new OrderBy(mockSelect, selectWhereOrderBy.orderBy); | ||
o.getSelect().should.equal(mockSelect); | ||
}); | ||
|
||
}); | ||
|
||
describe('#validate', () => { | ||
|
||
// TODO no validation method implemented yet | ||
|
||
}); | ||
|
||
describe('#getSortCriteria', () => { | ||
|
||
it('should return the sort critera', () => { | ||
const o = new OrderBy(mockSelect, selectWhereOrderBy.orderBy); | ||
o.should.be.an.instanceOf(OrderBy); | ||
o.getSortCriteria().should.have.lengthOf(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.