2016-05-07 03:00:45 +08:00
|
|
|
AutoUpdateManager = require('../src/browser/auto-update-manager').default
|
2015-10-04 05:45:39 +08:00
|
|
|
url = require 'url'
|
2015-06-12 03:08:47 +08:00
|
|
|
|
|
|
|
describe "AutoUpdateManager", ->
|
|
|
|
beforeEach ->
|
2016-06-03 09:56:03 +08:00
|
|
|
@nylasIdentityId = null
|
2016-08-19 04:17:40 +08:00
|
|
|
@accounts = [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}]
|
2015-11-03 03:56:11 +08:00
|
|
|
@specMode = true
|
2017-02-10 05:29:50 +08:00
|
|
|
@databaseReader =
|
|
|
|
getJSONBlob: => {
|
|
|
|
id: @nylasIdentityId
|
|
|
|
}
|
2015-10-04 05:45:39 +08:00
|
|
|
@config =
|
|
|
|
set: jasmine.createSpy('config.set')
|
|
|
|
get: (key) =>
|
|
|
|
if key is 'nylas.accounts'
|
2016-08-19 04:17:40 +08:00
|
|
|
return @accounts
|
2017-01-16 09:06:23 +08:00
|
|
|
if key is 'env'
|
2017-01-16 06:10:16 +08:00
|
|
|
return 'production'
|
2016-08-19 04:17:40 +08:00
|
|
|
onDidChange: (key, callback) =>
|
|
|
|
callback()
|
2015-06-12 03:08:47 +08:00
|
|
|
|
|
|
|
describe "with attached commit version", ->
|
|
|
|
it "correctly sets the feedURL", ->
|
2017-02-10 05:29:50 +08:00
|
|
|
m = new AutoUpdateManager("3.222.1-abc", @config, @specMode, @databaseReader)
|
2015-10-04 05:45:39 +08:00
|
|
|
spyOn(m, "setupAutoUpdater")
|
2015-06-12 03:08:47 +08:00
|
|
|
|
2015-11-24 14:09:17 +08:00
|
|
|
{query} = url.parse(m.feedURL, true)
|
2015-10-04 05:45:39 +08:00
|
|
|
expect(query.arch).toBe process.arch
|
|
|
|
expect(query.platform).toBe process.platform
|
|
|
|
expect(query.version).toBe "3.222.1-abc"
|
2015-06-12 03:08:47 +08:00
|
|
|
|
2015-10-04 05:45:39 +08:00
|
|
|
describe "with no attached commit", ->
|
2015-06-12 03:08:47 +08:00
|
|
|
it "correctly sets the feedURL", ->
|
2017-02-10 05:29:50 +08:00
|
|
|
m = new AutoUpdateManager("3.222.1", @config, @specMode, @databaseReader)
|
2015-10-04 05:45:39 +08:00
|
|
|
spyOn(m, "setupAutoUpdater")
|
2015-11-24 14:09:17 +08:00
|
|
|
{query} = url.parse(m.feedURL, true)
|
2015-10-04 05:45:39 +08:00
|
|
|
expect(query.arch).toBe process.arch
|
|
|
|
expect(query.platform).toBe process.platform
|
|
|
|
expect(query.version).toBe "3.222.1"
|
|
|
|
|
|
|
|
describe "when an update identity is not present", ->
|
2016-06-03 09:56:03 +08:00
|
|
|
it "should use anonymous", ->
|
2017-02-10 05:29:50 +08:00
|
|
|
m = new AutoUpdateManager("3.222.1", @config, @specMode, @databaseReader)
|
2015-10-04 05:45:39 +08:00
|
|
|
spyOn(m, "setupAutoUpdater")
|
2015-11-24 14:09:17 +08:00
|
|
|
{query} = url.parse(m.feedURL, true)
|
2016-06-03 09:56:03 +08:00
|
|
|
expect(query.id).toEqual('anonymous')
|
2015-10-04 05:45:39 +08:00
|
|
|
|
|
|
|
describe "when an update identity is already set", ->
|
|
|
|
it "should send it and not save any changes", ->
|
2016-06-03 09:56:03 +08:00
|
|
|
@nylasIdentityId = "test-nylas-id"
|
2017-02-10 05:29:50 +08:00
|
|
|
m = new AutoUpdateManager("3.222.1", @config, @specMode, @databaseReader)
|
2015-10-04 05:45:39 +08:00
|
|
|
spyOn(m, "setupAutoUpdater")
|
2015-11-24 14:09:17 +08:00
|
|
|
{query} = url.parse(m.feedURL, true)
|
2016-06-03 09:56:03 +08:00
|
|
|
expect(query.id).toEqual(@nylasIdentityId)
|
2016-08-19 04:17:40 +08:00
|
|
|
|
|
|
|
describe "when an update identity is added", ->
|
|
|
|
it "should update the feed URL", ->
|
2017-02-10 05:29:50 +08:00
|
|
|
m = new AutoUpdateManager("3.222.1", @config, @specMode, @databaseReader)
|
2016-08-19 04:17:40 +08:00
|
|
|
spyOn(m, "setupAutoUpdater")
|
|
|
|
{query} = url.parse(m.feedURL, true)
|
|
|
|
expect(query.id).toEqual('anonymous')
|
|
|
|
@nylasIdentityId = '1'
|
2017-02-10 05:29:50 +08:00
|
|
|
m.updateFeedURL()
|
2016-08-19 04:17:40 +08:00
|
|
|
{query} = url.parse(m.feedURL, true)
|
|
|
|
expect(query.id).toEqual(@nylasIdentityId)
|