import { TestBed } from '@angular/core/testing'; import { UserService } from './user.service'; import {HttpClient} from '@angular/common/http'; import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; describe('UserService', () => { let httpClient: HttpClient; let httpTestingController: HttpTestingController; let service: UserService; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule] }); httpClient = TestBed.inject(HttpClient); httpTestingController = TestBed.inject(HttpTestingController); service = TestBed.inject(UserService); }); it('should be created', () => { expect(service).toBeTruthy(); }); it('should return user for available id', () => { expect(service.getUserById('1')).toEqual({ id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male' }); }); it('should not return user for unavailable id', () => { expect(service.getUserById('9999999999')).toBeUndefined(); }); it('should return action for available id', () => { expect(service.getActionById('1')).toEqual({ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false }); }); it('should not return action for unavailable id', () => { expect(service.getActionById('9999999999')).toBeUndefined(); }); it('should switch action approval from false to true', () => { service.approveAction('1'); expect(service.getActionById('1')).toEqual({ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: true }); }); it('should switch action approval from true to false', () => { service.revokeAction('2'); expect(service.getActionById('2')).toEqual({ id: 2, user: 'Christine', role: 'admin', action: 'Change user phone number', approval: false }); }); });