1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { UserFormModel } from '../../core/auth/user-form/user-form.model';
6 import { UserService } from './user.service';
8 describe('UserService', () => {
9 let service: UserService;
10 let httpTesting: HttpTestingController;
13 providers: [UserService],
14 imports: [HttpClientTestingModule]
18 service = TestBed.get(UserService);
19 httpTesting = TestBed.get(HttpTestingController);
26 it('should be created', () => {
27 expect(service).toBeTruthy();
30 it('should call create', () => {
31 const user = new UserFormModel();
32 user.username = 'user0';
33 user.password = 'pass0';
35 user.email = 'user0@email.com';
36 user.roles = ['administrator'];
37 service.create(user).subscribe();
38 const req = httpTesting.expectOne('api/user');
39 expect(req.request.method).toBe('POST');
40 expect(req.request.body).toEqual(user);
43 it('should call delete', () => {
44 service.delete('user0').subscribe();
45 const req = httpTesting.expectOne('api/user/user0');
46 expect(req.request.method).toBe('DELETE');
49 it('should call update', () => {
50 const user = new UserFormModel();
51 user.username = 'user0';
52 user.password = 'pass0';
54 user.email = 'user0@email.com';
55 user.roles = ['administrator'];
56 service.update(user).subscribe();
57 const req = httpTesting.expectOne('api/user/user0');
58 expect(req.request.body).toEqual(user);
59 expect(req.request.method).toBe('PUT');
62 it('should call get', () => {
63 service.get('user0').subscribe();
64 const req = httpTesting.expectOne('api/user/user0');
65 expect(req.request.method).toBe('GET');
68 it('should call list', () => {
69 service.list().subscribe();
70 const req = httpTesting.expectOne('api/user');
71 expect(req.request.method).toBe('GET');