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 { TestBed } from '@angular/core/testing';
import { TokenService } from '@app/_services/token.service'; import { TokenService } from '@app/_services/token.service';
import {Token} from '@app/_models';
describe('TokenService', () => { describe('TokenService', () => {
let service: TokenService; let service: TokenService;
@ -15,10 +16,27 @@ describe('TokenService', () => {
}); });
it('should return token for available token', () => { 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', () => { 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', () => { it('should return action for available id', () => {
expect(service.getActionById('1')).toEqual({ service.getActionById('1').subscribe(returnedAction => {
id: 1, expect(returnedAction.toEqual({
user: 'Tom', id: 1,
role: 'enroller', user: 'Tom',
action: 'Disburse RSV 100', role: 'enroller',
approval: false, action: 'Disburse RSV 100',
approval: false,
}));
}); });
}); });
it('should not return action for unavailable id', () => { 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', () => { it('should switch action approval from false to true', () => {
service.approveAction('1'); service.approveAction('1');
expect(service.getActionById('1')).toEqual({ service.getActionById('1').subscribe(returnedAction => {
id: 1, expect(returnedAction.toEqual({
user: 'Tom', id: 1,
role: 'enroller', user: 'Tom',
action: 'Disburse RSV 100', role: 'enroller',
approval: true, action: 'Disburse RSV 100',
approval: true,
}));
}); });
}); });
it('should switch action approval from true to false', () => { it('should switch action approval from true to false', () => {
service.revokeAction('2'); service.revokeAction('2');
expect(service.getActionById('2')).toEqual({ service.getActionById('2').subscribe(returnedAction => {
id: 2, expect(returnedAction.toEqual({
user: 'Christine', id: 2,
role: 'admin', user: 'Christine',
action: 'Change user phone number', role: 'admin',
approval: false, action: 'Change user phone number',
approval: false,
}));
}); });
}); });
}); });