add disclaimer controller test

This commit is contained in:
Matias Alejo Garcia 2016-06-05 16:27:49 -03:00
parent 229802f0ca
commit 7781b93a88
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
5 changed files with 122 additions and 22 deletions

View File

@ -25,14 +25,14 @@
</div>
<div class="row">
<div class="onGoingProcess" ng-show="creatingProfile">
<div class="onGoingProcess" ng-show="disclaimer.creatingProfile">
<div class="onGoingProcess-content" ng-style="{'background-color':'#222'}">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
<span translate>Creating Wallet...</span>
</div>
</div>
<div class="start-button columns button-box">
<button ng-disabled="creatingProfile" ng-click="disclaimer.accept()" class="button black expand round size-12 text-spacing m0" translate>
<button ng-disabled="disclaimer.creatingProfile" ng-click="disclaimer.accept()" class="button black expand round size-12 text-spacing m0" translate>
I AGREE. GET STARTED
</button>
</div>

View File

@ -4,45 +4,53 @@ angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go) {
var self = this;
self.tries = 0;
$scope.creatingProfile = true;
self.creatingProfile = true;
var create = function(noWallet) {
profileService.create({
noWallet: noWallet
}, function(err) {
var create = function(opts) {
opts = opts || {};
$log.debug('Creating profile');
profileService.create(opts, function(err) {
console.log('[disclaimer.js.13]', err); //TODO
if (err) {
$log.warn(err);
$scope.error = err;
$scope.$apply();
$timeout(function() {
return $timeout(function() {
$log.warn('Retrying to create profile......');
if (self.tries == 3) {
self.tries == 0;
create(true);
return create({
noWallet: true
});
} else {
self.tries += 1;
create(false);
return create();
}
}, 3000);
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
};
$scope.error = "";
self.creatingProfile = false;
console.log('[disclaimer.js.33]'); //TODO
});
};
this.init = function() {
this.init = function(opts) {
$ionicSideMenuDelegate.canDragContent(false);
self.lang = uxLanguage.currentLanguage;
profileService.getProfile(function(err, profile) {
if (!profile) {
create(false);
console.log('[disclaimer.js.43]'); //TODO
create(opts);
console.log('[disclaimer.js.46]'); //TODO
} else {
$log.debug('There is a profile already');
$scope.creatingProfile = false;
$log.info('There is already a profile');
self.creatingProfile = false;
profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.');

View File

@ -224,6 +224,7 @@ angular.module('copayApp.services')
root._seedWallet = function(opts, cb) {
opts = opts || {};
$log.debug('seedWallet', opts);
var walletClient = bwcService.getClient(null, opts);
var network = opts.networkName || 'livenet';
@ -291,13 +292,15 @@ angular.module('copayApp.services')
return cb(null, Profile.create());
}
root._seedWallet({}, function(err, walletClient) {
root._seedWallet(opts, function(err, walletClient) {
if (err) return cb(err);
var walletName = gettextCatalog.getString('Personal Wallet');
var me = gettextCatalog.getString('me');
walletClient.createWallet(walletName, me, 1, 1, {
network: 'livenet'
network: 'livenet',
walletPrivKey: opts.walletPrivKey,
}, function(err) {
if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb);
var p = Profile.create({
@ -559,16 +562,24 @@ angular.module('copayApp.services')
};
root.create = function(opts, cb) {
$log.info('Creating profile');
$log.info('Creating profile', opts);
var defaults = configService.getDefaults();
console.log('[profileService.js.567]'); //TODO
configService.get(function(err) {
console.log('[profileService.js.570]'); //TODO
root._createNewProfile(opts, function(err, p) {
if (err) return cb(err);
console.log('[profileService.js.574]'); //TODO
root.bindProfile(p, function(err) {
console.log('[profileService.js.577]'); //TODO
// ignore NONAGREEDDISCLAIMER
storageService.storeNewProfile(p, function(err) {
console.log('[profileService.js.581]'); //TODO
return cb(err);
});
});

View File

@ -0,0 +1,78 @@
describe.only('disclaimerController', function() {
var walletService;
var storeProfile;
var fixtures = {
'8dc332881e99c908c655147dc6bc605e102b0bd3cf2dbee02ed2a0f4daf2925a': {
"walletId": "eddaef15-f412-462f-9d3e-a793a7f6f6ba"
},
'654145bc3f15f03a8b1ccf55aa1bdcd1cfd5bbe3de90e909fd4e7f9f69ec4d79': {
"copayerId": "1a91ead1b6d13da882a25377a20e460df557e77008ea4f60eecbf984f786cf03",
"wallet": {
"version": "1.0.0",
"createdOn": 1465152783,
"id": "eddaef15-f412-462f-9d3e-a793a7f6f6ba",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"/gaG7FIkhCiwsWKZUR0sL/cxH+zHMK0=\"}",
"m": 1,
"n": 1,
"status": "complete",
"publicKeyRing": [{
"xPubKey": "xpub6Cb7MYAX7mJR28MfFueCsoDVVHhoWkQxRC4viAeHanYwRNgDo5xMF42xmAeExzfyPXX3GaALNA8hWFMekVYvDF2BALommUhMgZ52szh88fd",
"requestPubKey": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd"
}],
"copayers": [{
"version": 2,
"createdOn": 1465152783,
"xPubKey": "xpub6Cb7MYAX7mJR28MfFueCsoDVVHhoWkQxRC4viAeHanYwRNgDo5xMF42xmAeExzfyPXX3GaALNA8hWFMekVYvDF2BALommUhMgZ52szh88fd",
"id": "1a91ead1b6d13da882a25377a20e460df557e77008ea4f60eecbf984f786cf03",
"name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"wwZd+2LQgYR6cA==\"}",
"requestPubKey": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd",
"signature": "3045022100ac3f31ef145eabde6a125958aa9d63c2bd4aa27717d7f6905c3e3ff1e733ee8e02206a43200b775ee5c8f7a85c4d3309d155240d5de46a7d9c5e60045bf49779f40b",
"requestPubKeys": [{
"key": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd",
"signature": "3045022100ac3f31ef145eabde6a125958aa9d63c2bd4aa27717d7f6905c3e3ff1e733ee8e02206a43200b775ee5c8f7a85c4d3309d155240d5de46a7d9c5e60045bf49779f40b"
}],
"customData": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"9l63hoVnA71LshCC5xbOTHA+ivBzux7u8SAci56p4aaVIF4qzXQhQKFX+sAFGfBjULm/E1st6awdXnxbAgjbF7D0zsbBFLFOSCw+ko5Xc6o=\"}"
}],
"pubKey": "026d95bb5cc2a30c19e22379ae78b4757aaa2dd0ccbd15a1db054fb50cb98ed361",
"network": "livenet",
"derivationStrategy": "BIP44",
"addressType": "P2PKH",
"addressManager": {
"version": 2,
"derivationStrategy": "BIP44",
"receiveAddressIndex": 0,
"changeAddressIndex": 0,
"copayerIndex": 2147483647
},
"scanStatus": null
}
},
}; // TODO: Read from file
beforeEach(function(done) {
mocks.init(fixtures, 'disclaimerController', {
initController: true,
noDisclaimer: true,
}, done);
})
afterEach(function(done) {
mocks.clear({}, done);
});
// it('should be defined', function() {
// should.exist(ctrl);
// });
it('should create the initial profile', function(done) {
localStorage.clear();
ctrl.init({
walletPrivKey: 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy',
mnemonic: 'tunnel fork scare industry noble snow tank bullet over gesture nuclear next',
});
setTimeout(function() {
done();
}, 1000);
});
});

View File

@ -220,6 +220,9 @@ mocks.init = function(fixtures, controllerName, opts, done) {
noWallet: true
}, function(err) {
should.not.exist(err, err);
if (opts.noDisclaimer){
return done();
};
_profileService_.setDisclaimerAccepted(function() {
if (!opts.initController)
startController();