Skip to content

Commit

Permalink
Wrote extra unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Sep 7, 2014
1 parent 1af485d commit 15acfa5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/app/recordings/recentRecordings/recentRecordings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ angular.module("bawApp.recordings.recentRecordings", [])
}
];

Site.getSitesByIds([1,2,3,4]);

function audioRecordingsFormat(wrapper) {
$scope.recentRecordings = wrapper.data;
// format return objects for display
Expand Down
14 changes: 12 additions & 2 deletions src/components/services/queryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,18 @@ qb.factory("QueryBuilder", ["conf.constants", function(constants) {
var q = new RootQuery();

if (queryComposer) {
var result = queryComposer.call(q, q);
q.compose(result);
if (angular.isFunction(queryComposer)) {
var result = queryComposer.call(q, q);

if (!(result instanceof Query) || result.root !== q) {
throw new Error("The create callback must return a child instance of Query passed to the callback");
}

q.compose(result);
}
else {
throw new Error("The create callback must be a function");
}
}

return q;
Expand Down
26 changes: 25 additions & 1 deletion src/components/services/queryBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ describe("The QueryBuilder", function () {
expect(q instanceof queryBuilder.RootQuery).toBeTrue();
});

it("should validate create's callback", function() {
// should work without exception
var q = queryBuilder.create();

expect(Object.keys(q.filter).length).toBe(0);

expect(function(){
queryBuilder.create(1234);
}).toThrowError(Error, "The create callback must be a function");

expect(function() {
queryBuilder.create(function() {});
}).toThrowError(Error, "The create callback must return a child instance of Query passed to the callback");

expect(function() {
queryBuilder.create(function() {return queryBuilder.create();});
}).toThrowError(Error, "The create callback must return a child instance of Query passed to the callback");
});

it("should implement the expected interface", function () {
var queryInterface = validCombinators.concat(validOperators);
var rootInterface = queryInterface.concat(rootOperators);
Expand Down Expand Up @@ -122,7 +141,7 @@ describe("The QueryBuilder", function () {
expect(actual.toJSON(spaces)).toBe(j(expected));
});

it("should ensure .end and .compose are the same", function() {
it("should ensure .end and .compose and .create are the same", function() {
var expected = {
filter: {
fieldA: {
Expand All @@ -143,6 +162,11 @@ describe("The QueryBuilder", function () {
q = queryBuilder.create();
var actualEnd = q.eq("fieldA", 3.0).or(q.field("fieldB").lt(6.0).gt(3.0)).end();
expect(actualEnd.toJSON(spaces)).toBe(j(expected));

var actualCreate = queryBuilder.create(function(q) {
return q.eq("fieldA", 3.0).or(q.field("fieldB").lt(6.0).gt(3.0));
});
expect(actualCreate.toJSON(spaces)).toBe(j(expected));
});

it("should ensure not is arity:1 only", function () {
Expand Down
3 changes: 2 additions & 1 deletion src/components/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
var url = paths.api.routes.site.filterAbsolute;
siteIds = _.uniq(siteIds);
var query = QueryBuilder.create(function(q) {
return q.in("id", siteIds);
return q.in("id", siteIds)
.project({include: ["id", "name"]});
});
return $http.post(url, query.toJSON());
};
Expand Down

0 comments on commit 15acfa5

Please sign in to comment.