2020-11-25 08:51:15 +01:00
|
|
|
import { TestBed } from '@angular/core/testing';
|
|
|
|
|
2021-02-17 13:49:04 +01:00
|
|
|
import { UserService } from '@app/_services/user.service';
|
2020-11-25 08:51:15 +01:00
|
|
|
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', () => {
|
2021-02-17 13:49:04 +01:00
|
|
|
expect(service.getAccountById(1)).toEqual({
|
2020-11-25 08:51:15 +01:00
|
|
|
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', () => {
|
2021-02-17 13:49:04 +01:00
|
|
|
expect(service.getAccountById(9999999999)).toBeUndefined();
|
2020-11-25 08:51:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|