-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
138 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
describe("The QueryBuilder", function () { | ||
|
||
var queryBuilder, q; | ||
|
||
var spaces = 2; | ||
function j(obj) { | ||
JSON.stringify(obj, null, spaces); | ||
} | ||
|
||
beforeEach(module("bawApp.services.queryBuilder")); | ||
|
||
beforeEach(inject(["QueryBuilder", function (QueryBuilder) { | ||
queryBuilder = QueryBuilder; | ||
q = queryBuilder.create(); | ||
|
||
}])); | ||
|
||
|
||
it("should be able to be created", function() { | ||
var q = queryBuilder.create(); | ||
|
||
expect(q instanceof RootQuery).toBeTrue(); | ||
}); | ||
|
||
it("a query combinator should return itself", function() { | ||
var actual = q.and(q.eq("field", 3.0)); | ||
|
||
expect(actual).toBe(q); | ||
}); | ||
|
||
it("will throw if a combinator is passed a non-query object", function() { | ||
expect(function() { | ||
q.combinator("and", [{}]); | ||
}).toThrow("A combinator only accepts Query objects"); | ||
}); | ||
|
||
it("a query operator should return a new instance of a Query", function() { | ||
var actual = q.eq("field", 3.0); | ||
|
||
expect(actual instanceof Query).toBeTrue(); | ||
expect(q instanceof RootQuery).toBeTrue(); | ||
expect(actual instanceof RootQuery).toBeFalse(); | ||
|
||
|
||
expect(actual).not.toBe(q); | ||
}); | ||
|
||
it("should be able to do basic equality", function() { | ||
var expected = { | ||
filter: { | ||
and: { | ||
field: { | ||
eq: 3.0 | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var actual = q.and(q.eq("field", 3.0)); | ||
|
||
|
||
expect(actual.toJSON(spaces)).toBe(j(expected)); | ||
}); | ||
|
||
|
||
|
||
|
||
// var actual = q.and( | ||
// q.eq("fieldA", 3.0), | ||
// q.or( | ||
// q.lt("fieldA", 30.0).ge("fieldB", 0.0) | ||
// ) | ||
// ); | ||
}); |