This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Set transition back to false when not needed to avoid being stuck in limbo #11763
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2367,8 +2367,8 @@ const yoDawg = (stateState) => { | |
return stateState | ||
} | ||
|
||
const checkBtcBatMigrated = (state, status) => { | ||
if (!status) { | ||
const checkBtcBatMigrated = (state, paymentsEnabled) => { | ||
if (!paymentsEnabled) { | ||
return state | ||
} | ||
|
||
|
@@ -2378,6 +2378,8 @@ const checkBtcBatMigrated = (state, status) => { | |
if (!isNewInstall && !hasUpgradedWallet) { | ||
state = migrationState.setTransitionStatus(state, true) | ||
module.exports.transitionWalletToBat() | ||
} else { | ||
state = migrationState.setTransitionStatus(state, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the big bug fix- if it's an existing install and hasn't upgraded yet, it needs to start (or in the case where you quit, restart) the transition process. Otherwise, it should hide the transition because that is no longer valid |
||
} | ||
|
||
return state | ||
|
@@ -2513,6 +2515,7 @@ const getMethods = () => { | |
privateMethods = { | ||
enable, | ||
addVisit, | ||
checkBtcBatMigrated, | ||
clearVisitsByPublisher: function () { | ||
visitsByPublisher = {} | ||
}, | ||
|
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ const sinon = require('sinon') | |
const mockery = require('mockery') | ||
const settings = require('../../../../../js/constants/settings') | ||
const appActions = require('../../../../../js/actions/appActions') | ||
const migrationState = require('../../../../../app/common/state/migrationState') | ||
const batPublisher = require('bat-publisher') | ||
|
||
const defaultAppState = Immutable.fromJS({ | ||
ledger: {}, | ||
|
@@ -135,6 +137,16 @@ describe('ledger api unit tests', function () { | |
ledgerClient.returns(lc) | ||
mockery.registerMock('bat-client', ledgerClient) | ||
|
||
// ledger publisher stubbing | ||
const lp = { | ||
ruleset: [], | ||
getPublisherProps: function (publisher) { | ||
return null | ||
}, | ||
Synopsis: batPublisher.Synopsis | ||
} | ||
mockery.registerMock('bat-publisher', lp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is basically what fixes the tests. Without |
||
|
||
// once everything is stubbed, load the ledger | ||
ledgerApi = require('../../../../../app/browser/api/ledger') | ||
}) | ||
|
@@ -148,16 +160,16 @@ describe('ledger api unit tests', function () { | |
}) | ||
|
||
describe('initialize', function () { | ||
let notificationsInitSpy | ||
let notificationsInitStub | ||
beforeEach(function () { | ||
notificationsInitSpy = sinon.spy(ledgerApi.notifications, 'init') | ||
notificationsInitStub = sinon.stub(ledgerApi.notifications, 'init') | ||
}) | ||
afterEach(function () { | ||
notificationsInitSpy.restore() | ||
notificationsInitStub.restore() | ||
}) | ||
it('calls notifications.init', function () { | ||
ledgerApi.initialize(defaultAppState, true) | ||
assert(notificationsInitSpy.calledOnce) | ||
assert(notificationsInitStub.calledOnce) | ||
}) | ||
}) | ||
|
||
|
@@ -277,8 +289,8 @@ describe('ledger api unit tests', function () { | |
ledgerApi.clearVisitsByPublisher() | ||
}) | ||
afterEach(function () { | ||
fakeClock.restore() | ||
ledgerApi.setSynopsis(undefined) | ||
fakeClock.restore() | ||
}) | ||
it('records a visit when over the PAYMENTS_MINIMUM_VISIT_TIME threshold', function () { | ||
const state = ledgerApi.initialize(stateWithLocation, true) | ||
|
@@ -322,6 +334,76 @@ describe('ledger api unit tests', function () { | |
}) | ||
}) | ||
|
||
describe('checkBtcBatMigrated', function () { | ||
let transitionWalletToBatStub | ||
before(function () { | ||
transitionWalletToBatStub = sinon.stub(ledgerApi, 'transitionWalletToBat') | ||
}) | ||
after(function () { | ||
transitionWalletToBatStub.restore() | ||
}) | ||
describe('when not a new install and wallet has not been upgraded', function () { | ||
let result | ||
before(function () { | ||
const notMigratedYet = defaultAppState.merge(Immutable.fromJS({ | ||
firstRunTimestamp: 12345, | ||
migrations: { | ||
batMercuryTimestamp: 34512, | ||
btc2BatTimestamp: 34512, | ||
btc2BatNotifiedTimestamp: 34512, | ||
btc2BatTransitionPending: false | ||
} | ||
})) | ||
assert.equal(migrationState.inTransition(notMigratedYet), false) | ||
transitionWalletToBatStub.reset() | ||
result = ledgerApi.checkBtcBatMigrated(notMigratedYet, true) | ||
}) | ||
it('sets transition status to true', function () { | ||
assert(migrationState.inTransition(result)) | ||
}) | ||
it('calls transitionWalletToBat', function () { | ||
assert(transitionWalletToBatStub.calledOnce) | ||
}) | ||
}) | ||
|
||
describe('when a transition is already being shown', function () { | ||
it('sets transition to false if new install', function () { | ||
const stuckOnMigrate = defaultAppState.merge(Immutable.fromJS({ | ||
firstRunTimestamp: 12345, | ||
migrations: { | ||
batMercuryTimestamp: 12345, | ||
btc2BatTimestamp: 12345, | ||
btc2BatNotifiedTimestamp: 12345, | ||
btc2BatTransitionPending: true | ||
} | ||
})) | ||
assert(migrationState.isNewInstall(stuckOnMigrate)) | ||
assert.equal(migrationState.hasUpgradedWallet(stuckOnMigrate), false) | ||
assert(migrationState.inTransition(stuckOnMigrate)) | ||
|
||
const result = ledgerApi.checkBtcBatMigrated(stuckOnMigrate, true) | ||
assert.equal(migrationState.inTransition(result), false) | ||
}) | ||
it('sets transition to false if wallet has been upgraded', function () { | ||
const stuckOnMigrate = defaultAppState.merge(Immutable.fromJS({ | ||
firstRunTimestamp: 12345, | ||
migrations: { | ||
batMercuryTimestamp: 34512, | ||
btc2BatTimestamp: 54321, | ||
btc2BatNotifiedTimestamp: 34512, | ||
btc2BatTransitionPending: true | ||
} | ||
})) | ||
assert.equal(migrationState.isNewInstall(stuckOnMigrate), false) | ||
assert(migrationState.hasUpgradedWallet(stuckOnMigrate)) | ||
assert(migrationState.inTransition(stuckOnMigrate)) | ||
|
||
const result = ledgerApi.checkBtcBatMigrated(stuckOnMigrate, true) | ||
assert.equal(migrationState.inTransition(result), false) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('transitionWalletToBat', function () { | ||
describe('when client is not busy', function () { | ||
before(function () { | ||
|
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.
renamed the variable to be more meaningful (and also match other places in the file)