This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Test coverage for Gateways Controllers #1167
Merged
nullstyle
merged 40 commits into
stellar-deprecated:master
from
gterzian:gateway-ctrls-tests
Mar 2, 2015
Merged
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
b6162b5
added test files
gterzian 57e4337
added test files to conf, first test passing
gterzian 13af3c2
mocking out gateway service
gterzian b8dd0b6
removing console.log
gterzian 651752c
test for no gateway found
gterzian 03df8ed
tests for GatewayListCtrl
gterzian 3040f40
added an else for clarity
gterzian 73e271b
putting service mocks into their own files
gterzian cdc8ab1
separate modules for each mock service
gterzian 75f5a23
renamed file for consistency
gterzian 859318a
add files to conf
gterzian 4774ae0
excluding underscore
gterzian ed2e06f
adding removing gateway to mocks
gterzian cbcf38f
remove log statement
gterzian f5e718b
mocking out the stellar network
gterzian fd0d4dd
mocking out some functionalities of the network
gterzian 4dcc25d
align stuff
gterzian 2b352fa
tests for remove gateway
gterzian 066668e
remove redundant mockBackend
gterzian 38f56aa
no returning promise anymore
gterzian 831a9d2
better writing
gterzian 77c7229
comments
gterzian 80565e5
removing whitespace
gterzian 7e5307b
we're only mocking out search function of gateways service
gterzian 49ab28a
better english
gterzian b0832d9
removing timeout dep
gterzian 7038c7c
extra assertion
gterzian 1293166
added comment on gateway status when removing, test for adding
gterzian b4dfa8b
test for retry adding
gterzian feb50a7
added a change to the gateway service to set status of gateway in ses…
gterzian cc5ed43
test for cancel adding a gateway
gterzian d5f2c06
keeping things compact
gterzian cdc1453
test for currencyNames, updated mocks
gterzian c7b50c5
test for adding non existing gateway
gterzian 7c1eb48
moving the add gateway stuff into a separate suite for more targetted…
gterzian 049be10
comments and update of mocks
gterzian a0ad7fc
removed the un-necessary timeout
gterzian 716c08b
better suite description
gterzian 5f1354c
checking that alerts were shown
gterzian 52ab668
fix alignment
gterzian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
angular.module('mockGateway', []) | ||
.factory('Gateways', ['$q', function($q) { | ||
var gateway = { | ||
search: function (domain) { | ||
var found = { | ||
domain: domain, | ||
currencies: ['usd', 'cny'] | ||
}; | ||
var deferred = $q.defer(); | ||
setTimeout(function() { | ||
if (domain === 'failing-gateway') { | ||
deferred.reject(found); | ||
} | ||
else { | ||
deferred.resolve(found); | ||
}; | ||
}, 10); | ||
return deferred.promise; | ||
}, | ||
}; | ||
return gateway | ||
}]); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
angular.module('mockSession', []) | ||
.factory('session', [function() { | ||
var session_data = { | ||
keychainData : { | ||
updateToken: true | ||
}, | ||
mainData: { | ||
email: '', | ||
gateways: { | ||
'test-gateway': { | ||
domain: 'test-gateway', | ||
currencies: ['usd', 'cny'] | ||
}, | ||
'removing-gateway': { | ||
domain: 'removing-gateway', | ||
currencies: ['usd', 'cny'], | ||
} | ||
} | ||
} | ||
}; | ||
return {get: function () {return session_data}, syncWallet: function () {}} | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
angular.module('mockStellarNetwork', []) | ||
.factory('StellarNetwork', [function() { | ||
var transaction = { | ||
trustSet: function () {}, | ||
setFlags: function () {}, | ||
submit: function () {}, | ||
on: function (event, callback) { | ||
if (event === 'success'){ | ||
callback('ok') | ||
}; | ||
} | ||
} | ||
var network = { | ||
remote: { | ||
transaction: function () {return transaction} | ||
} | ||
}; | ||
return network | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
test/unit/specs/controllers/add-gateway-controller-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
describe('Controller: AddGatewayCtrl, mocking out search', function () { | ||
|
||
// load the controller's module | ||
beforeEach(module('stellarClient')); | ||
|
||
//load the mocks for services | ||
beforeEach(module('mockSession')); | ||
beforeEach(module('mockGateway')); | ||
|
||
var AddGatewayCtrl, scope; | ||
|
||
// Initialize the controller and a mock scope | ||
beforeEach(inject(function ($controller, $rootScope) { | ||
scope = $rootScope.$new(); | ||
AddGatewayCtrl = $controller('AddGatewayCtrl', { | ||
$scope: scope | ||
}); | ||
})); | ||
|
||
it('Initially, the search params should always be reset', function () { | ||
expect(scope.gatewaySearch).to.equal(''); | ||
expect(scope.searchStatus).to.equal(''); | ||
expect(scope.foundGateway).to.equal(null); | ||
expect(scope.fromActionLink).to.equal(false); | ||
}); | ||
|
||
it('If an empty search is triggered, nothing should happen', function () { | ||
expect(scope.gatewaySearch).to.equal(''); | ||
scope.loadCurrencies(); | ||
expect(scope.foundGateway).to.equal(null); | ||
}); | ||
|
||
it('When searching for a gateway that had already been added, the searchStatus should reflect that', function () { | ||
scope.gateways = {'test-gateway': true}; | ||
scope.gatewaySearch = 'test-gateway' | ||
scope.loadCurrencies(); | ||
expect(scope.searchStatus).to.equal('already_added'); | ||
}); | ||
|
||
it('If a gateway is found, the result should be added to foundGateway', function () { | ||
scope.gateways = {}; | ||
scope.gatewaySearch = 'test-gateway' | ||
var promise = scope.loadCurrencies(); | ||
promise.then(function (){ | ||
expect(scope.foundGateway).to.equal({domain: 'test gateway', curencies: ['usd', 'cny']}); | ||
expect(scope.searchStatus).to.equal('found'); | ||
}); | ||
}); | ||
|
||
it('If no gateway is found, the search status should resolve to not_found', function () { | ||
scope.gateways = {}; | ||
scope.gatewaySearch = 'failing-gateway' | ||
var promise = scope.loadCurrencies(); | ||
promise.then(function (){ | ||
expect(scope.foundGateway).to.equal(null); | ||
expect(scope.searchStatus).to.equal('not_found'); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/unit/specs/controllers/gateway-list-controller-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
describe('Controller: GatewayListCtrl', function () { | ||
|
||
// load the controller's module | ||
beforeEach(module('stellarClient')); | ||
|
||
//load the mocks for services | ||
beforeEach(module('mockSession')); | ||
beforeEach(module('mockGateway')); | ||
|
||
var GatewayListCtrl, scope; | ||
|
||
// Initialize the controller and a mock scope | ||
beforeEach(inject(function ($controller, $rootScope) { | ||
scope = $rootScope.$new(); | ||
GatewayListCtrl = $controller('GatewayListCtrl', { | ||
$scope: scope | ||
}); | ||
})); | ||
|
||
it('If there are any gateways, hasGateways should resolve to true', function () { | ||
scope.gateways = ['one_gateway', 'two_gateway'] | ||
expect(scope.hasGateways()).to.equal(true); | ||
}); | ||
|
||
it("If there aren't any gateways, hasGateways should resolve to false", function () { | ||
scope.gateways = [] | ||
expect(scope.hasGateways()).to.equal(false); | ||
}); | ||
|
||
}); |
61 changes: 61 additions & 0 deletions
61
test/unit/specs/controllers/gateway-list-item-controller-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
describe('Controller: GatewayListItemCtrl', function () { | ||
|
||
// load the controller's module | ||
beforeEach(module('stellarClient')); | ||
|
||
//load the mocks for services | ||
beforeEach(module('mockSession')); | ||
beforeEach(module('mockStellarNetwork')); | ||
|
||
var GatewayListItemCtrl, scope, rootScope, inner_session; | ||
|
||
// Initialize the controller and a mock scope | ||
beforeEach(inject(function ($controller, $rootScope, session) { | ||
rootScope = $rootScope; | ||
inner_session = session; | ||
scope = $rootScope.$new(); | ||
GatewayListItemCtrl = $controller('GatewayListItemCtrl', { | ||
$scope: scope | ||
}); | ||
})); | ||
|
||
it('You should be able to remove the current gateway', function () { | ||
scope.gateway = { | ||
domain: 'removing-gateway', | ||
currencies: ['usd', 'cny'], | ||
}; | ||
expect(inner_session.get().mainData.gateways['removing-gateway'].domain).to.equal(scope.gateway.domain); | ||
scope.remove(); | ||
expect(scope.gateway.status).to.equal('removing') | ||
expect(inner_session.get().mainData.gateways['removing-gateway'].status).to.equal('removing'); | ||
rootScope.$apply(); | ||
expect(inner_session.get().mainData.gateways['removing-gateway']).to.equal(undefined); | ||
//note we're not actually removing the gateway from the scope, we're only removing it from the session | ||
expect(scope.gateway.status).to.equal('removing') | ||
}); | ||
|
||
it('You should be able to retry adding a gateway', function () { | ||
scope.gateway = { | ||
domain: 'new-gateway', | ||
currencies: ['usd', 'cny'], | ||
}; | ||
expect(inner_session.get().mainData.gateways['new-gateway']).to.equal(undefined); | ||
scope.retryAdd(); | ||
expect(inner_session.get().mainData.gateways['new-gateway'].status).to.equal('adding'); | ||
rootScope.$apply(); | ||
expect(inner_session.get().mainData.gateways['new-gateway'].status).to.equal('added'); | ||
}); | ||
|
||
it('You should be able to cancel adding a gateway', function () { | ||
scope.gateway = { | ||
domain: 'test-gateway', | ||
currencies: ['usd', 'cny'] | ||
}; | ||
expect(inner_session.get().mainData.gateways['test-gateway']).to.exists; | ||
scope.cancelAdd(); | ||
expect(inner_session.get().mainData.gateways['test-gateway']).to.be.undefined; | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this just matches what goes on in the 'add' method. Without this the tests would not pass (unless I would beforehand set the status of the gateway in the mocked out session to 'removing')