1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   | import { ISession } from '../shared/event.model' import { VoterService } from './voter.service' import { Observable } from 'rxjs/Rx'
  describe('VoterService', () => {
      let voterService: VoterService,         mockHttp;
      beforeEach(() => {         mockHttp = jasmine.createSpyObj('mockHttp', ['delete', 'post']);         voterService = new VoterService(mockHttp);     })
      describe('deleteVoter', () => {         it('should remove the voter from voters list', () => {             var session = { id: 6, voters: ['joe', 'john'] };             mockHttp.delete.and.returnValue(Observable.of(false));             voterService.deleteVoter(3, <ISession>session, 'joe');
              expect(session.voters.length).toBe(1)             expect(session.voters[0]).toBe('john')         })
          it('should call http.delete with right url', () => {             var session = { id: 6, voters: ['joe', 'john'] };             mockHttp.delete.and.returnValue(Observable.of(false));
              voterService.deleteVoter(3, <ISession>session, 'joe');
              expect(mockHttp.delete).toHaveBeenCalledWith(`/api/events/3/sessions/6/voters/joe`)         })     });
      describe('addVoter', () => {         it('should call http.post with right url', () => {             var session = { id: 6, voters: ['john'] };             mockHttp.post.and.returnValue(Observable.of(false));
              voterService.addVoter(3, <ISession>session, 'joe');
              expect(mockHttp.post).toHaveBeenCalledWith(`/api/events/3/sessions/6/voters/joe`, '{}', jasmine.any(Object));         })     })
  })
  |