Mailspring/packages/client-app/spec/auto-update-manager-spec.coffee

63 lines
2.2 KiB
CoffeeScript
Raw Normal View History

AutoUpdateManager = require('../src/browser/auto-update-manager').default
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 @accounts
2017-01-16 09:06:23 +08:00
if key is 'env'
return 'production'
onDidChange: (key, callback) =>
callback()
describe "with attached commit version", ->
it "correctly sets the feedURL", ->
2017-07-05 14:32:52 +08:00
m = new AutoUpdateManager("3.222.1-abc", @config, @specMode)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedURL, true)
expect(query.arch).toBe process.arch
expect(query.platform).toBe process.platform
expect(query.version).toBe "3.222.1-abc"
describe "with no attached commit", ->
it "correctly sets the feedURL", ->
2017-07-05 14:32:52 +08:00
m = new AutoUpdateManager("3.222.1", @config, @specMode)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedURL, true)
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", ->
it "should use anonymous", ->
2017-07-05 14:32:52 +08:00
m = new AutoUpdateManager("3.222.1", @config, @specMode)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedURL, true)
expect(query.id).toEqual('anonymous')
describe "when an update identity is already set", ->
it "should send it and not save any changes", ->
@nylasIdentityId = "test-nylas-id"
2017-07-05 14:32:52 +08:00
m = new AutoUpdateManager("3.222.1", @config, @specMode)
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", ->
2017-07-05 14:32:52 +08:00
m = new AutoUpdateManager("3.222.1", @config, @specMode)
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()
{query} = url.parse(m.feedURL, true)
expect(query.id).toEqual(@nylasIdentityId)