fix(autoupdater): Change feed URL when Nylas ID or accounts changes

Test Plan: Tested locally.

Reviewers: juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D3178
This commit is contained in:
Jackie Luo 2016-08-18 13:17:40 -07:00
parent afc20f255a
commit c908a1633c
2 changed files with 33 additions and 2 deletions

View file

@ -4,14 +4,17 @@ url = require 'url'
describe "AutoUpdateManager", ->
beforeEach ->
@nylasIdentityId = null
@accounts = [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}]
@specMode = true
@config =
set: jasmine.createSpy('config.set')
get: (key) =>
if key is 'nylas.accounts'
return [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}]
return @accounts
if key is 'nylas.identity.id'
return @nylasIdentityId
onDidChange: (key, callback) =>
callback()
describe "with attached commit version", ->
it "correctly sets the feedURL", ->
@ -46,3 +49,14 @@ describe "AutoUpdateManager", ->
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedURL, true)
expect(query.id).toEqual(@nylasIdentityId)
describe "when an update identity is added", ->
it "should update the feed URL", ->
m = new AutoUpdateManager("3.222.1", @config, @specMode)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedURL, true)
expect(query.id).toEqual('anonymous')
@nylasIdentityId = '1'
m._updateFeedURL()
{query} = url.parse(m.feedURL, true)
expect(query.id).toEqual(@nylasIdentityId)

View file

@ -24,6 +24,21 @@ export default class AutoUpdateManager extends EventEmitter {
this.config = config;
this.specMode = specMode;
this._updateFeedURL();
this.config.onDidChange(
'nylas.identity.id',
this._updateFeedURL
);
this.config.onDidChange(
'nylas.accounts',
this._updateFeedURL
);
process.nextTick(() => this.setupAutoUpdater());
}
_updateFeedURL = () => {
let updaterId = this.config.get("nylas.identity.id");
if (!updaterId) {
updaterId = "anonymous";
@ -46,7 +61,9 @@ export default class AutoUpdateManager extends EventEmitter {
this.feedURL = `https://edgehill.nylas.com/update-check?platform=${process.platform}&arch=${process.arch}&version=${this.version}&id=${updaterId}&emails=${updaterEmails}`;
}
process.nextTick(() => this.setupAutoUpdater());
if (autoUpdater) {
autoUpdater.setFeedURL(this.feedURL)
}
}
setupAutoUpdater() {