mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
fix(specs): ContactStore spec fixes for new contact ranking support
This commit is contained in:
parent
d1be3ac0f2
commit
9107bc325e
|
@ -13,18 +13,23 @@ class ContactRankingsCache extends RefreshingJSONCache
|
|||
})
|
||||
|
||||
fetchData: (callback) =>
|
||||
return if atom.inSpecMode()
|
||||
|
||||
NylasAPI.makeRequest
|
||||
accountId: @_accountId
|
||||
path: "/contacts/rankings"
|
||||
returnsModel: false
|
||||
.then (json) =>
|
||||
# Convert rankings into the format needed for quick lookup
|
||||
return unless json and json instanceof Array
|
||||
|
||||
# Convert rankings into the format needed for quick lookup
|
||||
rankings = {}
|
||||
for [email, rank] in json
|
||||
rankings[email.toLowerCase()] = rank
|
||||
callback(rankings)
|
||||
|
||||
.catch (err) =>
|
||||
console.warn("Request for Contact Rankings failed for account #{@_accountId}. #{err}")
|
||||
console.warn("Request for Contact Rankings failed for
|
||||
account #{@_accountId}. #{err}")
|
||||
|
||||
|
||||
module.exports = ContactRankingsCache
|
||||
module.exports = ContactRankingsCache
|
||||
|
|
|
@ -18,16 +18,20 @@ describe "NylasSyncWorker", ->
|
|||
|
||||
spyOn(DatabaseStore, 'persistJSONObject').andReturn(Promise.resolve())
|
||||
spyOn(DatabaseStore, 'findJSONObject').andCallFake (key) =>
|
||||
expected = "NylasSyncWorker:#{TEST_ACCOUNT_ID}"
|
||||
return throw new Error("Not stubbed! #{key}") unless key is expected
|
||||
Promise.resolve _.extend {}, {
|
||||
"contacts":
|
||||
busy: true
|
||||
complete: false
|
||||
"calendars":
|
||||
busy:false
|
||||
complete: true
|
||||
}
|
||||
if key is "NylasSyncWorker:#{TEST_ACCOUNT_ID}"
|
||||
return Promise.resolve _.extend {}, {
|
||||
"contacts":
|
||||
busy: true
|
||||
complete: false
|
||||
"calendars":
|
||||
busy:false
|
||||
complete: true
|
||||
}
|
||||
else if key.indexOf('ContactRankings') is 0
|
||||
return Promise.resolve([])
|
||||
else
|
||||
return throw new Error("Not stubbed! #{key}")
|
||||
|
||||
|
||||
@account = new Account(clientId: TEST_ACCOUNT_CLIENT_ID, serverId: TEST_ACCOUNT_ID, organizationUnit: 'label')
|
||||
@worker = new NylasSyncWorker(@api, @account)
|
||||
|
|
|
@ -3,6 +3,7 @@ proxyquire = require 'proxyquire'
|
|||
Contact = require '../../src/flux/models/contact'
|
||||
NylasAPI = require '../../src/flux/nylas-api'
|
||||
ContactStore = require '../../src/flux/stores/contact-store'
|
||||
ContactRankingStore = require '../../src/flux/stores/contact-ranking-store'
|
||||
DatabaseStore = require '../../src/flux/stores/database-store'
|
||||
AccountStore = require '../../src/flux/stores/account-store'
|
||||
|
||||
|
@ -54,20 +55,6 @@ describe "ContactStore", ->
|
|||
spyOn(DatabaseStore, "findAll").andCallFake ->
|
||||
where: -> Promise.resolve([@c3, @c1, @c2, @c4])
|
||||
|
||||
it "Holds the appropriate rankings on refresh and lowercased the emails", ->
|
||||
runs ->
|
||||
spyOn(ContactStore._rankingsCache, "trigger")
|
||||
ContactStore._rankingsCache.refresh()
|
||||
waitsFor ->
|
||||
ContactStore._rankingsCache.trigger.calls.length > 0
|
||||
runs ->
|
||||
rankings = ContactStore._rankingsCache.value()
|
||||
|
||||
expect(rankings).toEqual
|
||||
"evana@nylas.com": 10
|
||||
"evanb@nylas.com": 1
|
||||
"evanc@nylas.com": 0.1
|
||||
|
||||
it "triggers a sort on a contact refresh", ->
|
||||
spyOn(ContactStore, "_sortContactsCacheWithRankings")
|
||||
waitsForPromise ->
|
||||
|
@ -75,11 +62,11 @@ describe "ContactStore", ->
|
|||
expect(ContactStore._sortContactsCacheWithRankings).toHaveBeenCalled()
|
||||
|
||||
it "sorts the contact cache by the rankings", ->
|
||||
ContactStore._contactCache = [@c3, @c1, @c2, @c4]
|
||||
ContactStore._rankingsCache._value =
|
||||
spyOn(ContactRankingStore, 'value').andReturn
|
||||
"evana@nylas.com": 10
|
||||
"evanb@nylas.com": 1
|
||||
"evanc@nylas.com": 0.1
|
||||
ContactStore._contactCache = [@c3, @c1, @c2, @c4]
|
||||
ContactStore._sortContactsCacheWithRankings()
|
||||
expect(ContactStore._contactCache).toEqual [@c1, @c2, @c3, @c4]
|
||||
|
||||
|
|
Loading…
Reference in a new issue