Fix broken tests.

This commit is contained in:
Spencer Ofwiti 2021-06-24 19:34:02 +03:00
parent e0a44046da
commit 7e93aea96f
2 changed files with 47 additions and 21 deletions

View File

@ -1,6 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { TokenService } from '@app/_services/token.service';
import {Token} from '@app/_models';
describe('TokenService', () => {
let service: TokenService;
@ -15,10 +16,27 @@ describe('TokenService', () => {
});
it('should return token for available token', () => {
expect(service.getTokenBySymbol('RSV')).toEqual({ name: 'Reserve', symbol: 'RSV' });
const token: Token = {
name: 'Giftable Reserve',
symbol: 'GRZ',
address: '0xa686005CE37Dce7738436256982C3903f2E4ea8E',
supply: '1000000001000000000000000000',
decimals: '18',
reserves: {},
};
service.addToken(token);
service.getTokenBySymbol('GRZ').then(tokenSubject => {
tokenSubject.subscribe(returnedToken => {
expect(returnedToken).toEqual(token);
});
});
});
it('should not return token for unavailable token', () => {
expect(service.getTokenBySymbol('ABC')).toBeUndefined();
service.getTokenBySymbol('ABC').then(tokenSubject => {
tokenSubject.subscribe(returnedToken => {
expect(returnedToken).toBeUndefined();
});
});
});
});

View File

@ -23,38 +23,46 @@ describe('UserService', () => {
});
it('should return action for available id', () => {
expect(service.getActionById('1')).toEqual({
id: 1,
user: 'Tom',
role: 'enroller',
action: 'Disburse RSV 100',
approval: false,
service.getActionById('1').subscribe(returnedAction => {
expect(returnedAction.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();
service.getActionById('9999999999').subscribe(returnedAction => {
expect(returnedAction.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,
service.getActionById('1').subscribe(returnedAction => {
expect(returnedAction.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,
service.getActionById('2').subscribe(returnedAction => {
expect(returnedAction.toEqual({
id: 2,
user: 'Christine',
role: 'admin',
action: 'Change user phone number',
approval: false,
}));
});
});
});