Skip to content

Commit

Permalink
#611 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Nov 30, 2021
1 parent d7deaa3 commit 8d7db5e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ describe('The CalEventFormController controller', function() {
sendCounter: sinon.spy(function() {
return $q.when(true);
}),
removeEvent: sinon.stub().returns($q.when())
removeEvent: sinon.stub().returns($q.when()),
moveEvent: sinon.stub().returns($q.when(true))
};

calendarHomeId = 'calendarHomeId';
Expand Down Expand Up @@ -1223,9 +1224,6 @@ describe('The CalEventFormController controller', function() {
scope.event = {
title: 'oldtitle',
path: '/path/to/event',
rrule: {
equals: _.constant(false)
},
etag: '123123',
clone: _.constant(editedEvent)
};
Expand Down Expand Up @@ -1258,6 +1256,7 @@ describe('The CalEventFormController controller', function() {
});

calEventServiceMock.modifyEvent = sinon.stub().returns($q.when(true));
calEventServiceMock.moveEvent = sinon.stub().returns($q.when(true));
scope.modifyEvent();
scope.$digest();

Expand Down Expand Up @@ -1297,6 +1296,56 @@ describe('The CalEventFormController controller', function() {
expect(restoreSpy).to.not.have.been.called;
expect(calOpenEventFormMock).to.have.been.calledWith(sinon.match.any, scope.editedEvent);
});

it('should attempt to move the event to another calendar if the organizer changed it', function() {
const fakeEvent = {
start: start,
end: end,
title: 'oldtitle',
path: '/calendars/owner/id.json',
etag: '123123'
};

scope.event = CalendarShell.fromIncompleteShell(fakeEvent);
initController();

scope.editedEvent = CalendarShell.fromIncompleteShell({ ...fakeEvent, title: 'new title' });
scope.selectedCalendar.uniqueId = '/calendars/owner/id2.json';
scope.calendarHomeId = 'owner';

scope.modifyEvent();
scope.$digest();

expect(calEventServiceMock.moveEvent).to.have.been.calledWith(
'/calendars/owner/id.json',
`/calendars/owner/id2/${scope.editedEvent.uid}.ics`
);
});

it('should attempt to move the event to another calendar when the other fields were left intact', function() {
const fakeEvent = {
start: start,
end: end,
title: 'oldtitle',
path: '/calendars/owner/id.json',
etag: '123123'
};

scope.event = CalendarShell.fromIncompleteShell(fakeEvent);
initController();

scope.editedEvent = CalendarShell.fromIncompleteShell(fakeEvent);
scope.selectedCalendar.uniqueId = '/calendars/owner/id2.json';
scope.calendarHomeId = 'owner';

scope.modifyEvent();
scope.$digest();

expect(calEventServiceMock.moveEvent).to.have.been.calledWith(
'/calendars/owner/id.json',
`/calendars/owner/id2/${scope.editedEvent.uid}.ics`
);
});
});

describe('as an attendee', function() {
Expand Down
18 changes: 18 additions & 0 deletions src/esn.calendar.libs/app/services/calendar-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,22 @@ describe('The calendar module apis', function() {
});
});

describe('The moveEvent request', function() {
it('should send a MOVE request with the correct headers', function() {
const originalEventPath = '/calendars/user/calendar1/event.json';
const destinationEventPath = '/calendars/user/calendar2/event.json';
const expectedHeaders = {
Destination: destinationEventPath,
Overwrite: 'F',
Authorization: 'Bearer jwt',
Accept: 'application/json, text/plain, */*'
};

this.$httpBackend.expect('MOVE', originalEventPath, null, expectedHeaders)
.respond(201, {});

this.calendarAPI.moveEvent(originalEventPath, destinationEventPath);
this.$httpBackend.flush();
});
});
});
11 changes: 11 additions & 0 deletions src/esn.calendar.libs/app/services/event-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2041,4 +2041,15 @@ describe('The calEventService service', function() {
self.$rootScope.$digest();
});
});

describe('the moveEvent function', function() {
it('should call the calendarAPI.moveEvent function', function() {
const spy = sinon.stub(self.calendarAPI, 'moveEvent').returns($q.when());

self.calEventService.moveEvent('/path/to/event.ics', '/path/to/new/event.ics')
.then(function() {
expect(spy).to.have.been.calledWith('/path/to/event.ics', '/path/to/new/event.ics');
});
});
});
});

0 comments on commit 8d7db5e

Please sign in to comment.