WIP: 6: Get Data from a Server k) Search by name
[examples/angular-tour-of-heroes] / app / vorgang.service.spec.ts
1 import { TestBed } from '@angular/core/testing';
2 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
3
4 import { VorgangService } from './vorgang.service';
5
6 describe('VorgangService', () => {
7   let service: VorgangService;
8   let httpMock: HttpTestingController;
9
10   beforeEach(() => {
11     TestBed.configureTestingModule({
12       imports: [ HttpClientTestingModule ],
13       providers: [ VorgangService ]
14     });
15     service = TestBed.inject(VorgangService);
16     httpMock = TestBed.inject(HttpTestingController);
17   });
18
19   afterEach(() => {
20     // After every test, assert that there are no more pending requests.
21     httpMock.verify();
22   });
23
24   it('should be created', () => {
25     expect(service).toBeTruthy();
26   });
27
28   describe('#getUrlSave', () => {
29     it ('should reate valid url for save', () => {
30       const expectedUrl = 'http://localhost:1991/las/VBID/save';
31
32       expect(service.getUrlSave('VBID')).toBe(expectedUrl);
33     });
34   });
35
36   describe('#create', () => {
37     it('should return Vorgang', () => {
38       const expectedVorgang = require('../mock/vorgang.json');
39
40       service.create({ type: null, vbId: 'greetings', vorgangId: '1' , zustand: 'Hello world!'}).subscribe(
41         vorgang => expect(vorgang).toEqual(expectedVorgang),
42         fail
43       );
44
45       const req = httpMock.expectOne(service.getUrlSave(expectedVorgang.vbId));
46       expect(req.request.method).toBe('POST');
47       req.flush(expectedVorgang);
48     });
49   });
50 });