Skip to content

Commit

Permalink
all changes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpavlov committed Aug 22, 2017
1 parent 2fe28f7 commit 75fb9dd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion org.civicrm.reqangular/src/common/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define([
return $q.all([
(function () {
var params = _.assign({}, filters, (additionalParams || {}), {
options: { sort: sort || 'id DESC' }
options: _.assign({}, filters.options, { sort: sort || 'id DESC' })
});

if (pagination) {
Expand Down
35 changes: 29 additions & 6 deletions org.civicrm.reqangular/test/services/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ define([
'use strict';

describe('api', function () {
var api, $httpBackend, $httpParamSerializer;
var api, $httpBackend, $httpParamSerializer, $rootScope;
var entity = 'entity';
var action = 'action';

beforeEach(module('common.apis'));

beforeEach(inject(function (_api_, _$httpBackend_, _$httpParamSerializer_) {
beforeEach(inject(function (_api_, _$httpBackend_, _$httpParamSerializer_, _$rootScope_) {
api = _api_;
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$rootScope = _$rootScope_;
}));

afterEach(function () {
$httpBackend.flush();
});

describe('sendGET', function () {
var promise;

afterEach(function () { $httpBackend.flush(); });

describe('when the API does not return an error', function () {
var returnValue = {
is_error: 0,
Expand Down Expand Up @@ -112,6 +111,8 @@ define([
describe('sendPOST', function () {
var promise;

afterEach(function () { $httpBackend.flush(); });

describe('when the API doesnt return an error', function () {
var returnValue = {
is_error: 0,
Expand Down Expand Up @@ -191,5 +192,27 @@ define([
return api.sendPOST(entity, action, params);
}
});

describe('getAll()', function () {
var returnValue = { is_error: 0, values: [{}] };

describe('when OR expression is passed', function () {
var orExpression = { or: [['field1', 'field2', 'field3']] };

beforeEach(function () {
spyOn(api, 'sendGET').and.returnValue(returnValue);
api.getAll(entity, { options: orExpression });
$rootScope.$digest();
});

it('uses this expression in the API call', function () {
expect(api.sendGET).toHaveBeenCalledWith(entity, 'get',
jasmine.objectContaining({
options: jasmine.objectContaining(orExpression)
}), undefined
);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ define([
* @return {Promise}
*/
function indexLeaveRequests (leaveRequestsList) {
var deferred = $q.defer();

leaveRequestsList.forEach(function (leaveRequest) {
var days = leaveRequestDays(leaveRequest);

Expand All @@ -175,9 +173,7 @@ define([
});
});

deferred.resolve();

return deferred.promise;
$q.resolve();
}

/**
Expand Down Expand Up @@ -248,9 +244,12 @@ define([
var toDate = moment(leaveRequest.to_date);

while (pointerDate.isSameOrBefore(toDate)) {
days.push(_.find(vm.month.days, function (day) {
return day.date === pointerDate.format('YYYY-MM-DD');
}));
// Ensure that pointerDate is in same month/year that component represents
if (pointerDate.month() === vm.month.index && pointerDate.year() === vm.month.year) {
days.push(_.find(vm.month.days, function (day) {
return day.date === pointerDate.format('YYYY-MM-DD');
}));
}

pointerDate.add(1, 'day');
}
Expand Down Expand Up @@ -315,9 +314,13 @@ define([
* @return {Promise}
*/
function loadMonthLeaveRequests () {
var range = { from: vm.month.days[0].date,
to: vm.month.days[vm.month.days.length - 1].date };

return LeaveRequest.all({
from_date: { from: vm.month.days[0].date },
to_date: { to: vm.month.days[vm.month.days.length - 1].date },
from_date: range,
to_date: range,
options: { or: [['from_date', 'to_date']] },
status_id: {'IN': [
leaveRequestStatusValueFromName(sharedSettings.statusNames.approved),
leaveRequestStatusValueFromName(sharedSettings.statusNames.adminApproved),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@
}));
});

it("uses the selected months' first and last day as date delimiters", function () {
it('loads all requests touching the specified month', function () {
var month = controller.month;
var range = { from: month.days[0].date,
to: month.days[month.days.length - 1].date };

expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual(jasmine.objectContaining({
from_date: { from: month.days[0].date },
to_date: { to: month.days[month.days.length - 1].date }
}));
expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual(
jasmine.objectContaining({ from_date: range, to_date: range }
));
});
});

Expand Down

0 comments on commit 75fb9dd

Please sign in to comment.