Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { WalletService } from './wallet.service';
import * as sinon from 'sinon';
import { FileWallet } from 'composer-common';
import { Logger } from 'composer-common';

describe('WalletService', () => {

Expand All @@ -23,6 +24,37 @@ describe('WalletService', () => {
});
});

describe('getWallet', () => {
beforeEach(() => {
// webpack can't handle dymanically creating a logger
Logger.setFunctionalLogger({
log: sinon.stub()
});
});

it('should get a wallet', fakeAsync(inject([WalletService], (service: WalletService) => {
service['fileWallets'] = mockFileWallets;
mockFileWallets.has.returns(true);

service.getWallet('identity1');

tick();

mockFileWallets.set.should.not.have.been.called;
mockFileWallets.get.should.have.been.calledWith('identity1');
})));

it('should create a new wallet if it doesn\'t already exist', fakeAsync(inject([WalletService], (service: WalletService) => {
service['fileWallets'] = mockFileWallets;

service.getWallet('secrectIdentity');

tick();

mockFileWallets.set.should.have.been.calledWith('secrectIdentity');
})));
});

describe('removeFromWallet', () => {
it('should remove an identity from the wallet', fakeAsync(inject([WalletService], (service: WalletService) => {
let mockGetWallet = sinon.stub(service, 'getWallet').returns(mockFileWallet);
Expand Down