fix(attachments): fixes + specs for download on-receive option

This commit is contained in:
Ben Gotow 2016-02-19 18:54:20 -08:00
parent 840b48c2df
commit f1cd1056cc
3 changed files with 26 additions and 6 deletions

View file

@ -3,6 +3,7 @@ path = require 'path'
{shell} = require 'electron'
NylasAPI = require '../../src/flux/nylas-api'
File = require '../../src/flux/models/file'
Message = require '../../src/flux/models/message'
FileDownloadStore = require '../../src/flux/stores/file-download-store'
AccountStore = require '../../src/flux/stores/account-store'
@ -112,6 +113,23 @@ describe "FileDownloadStore", ->
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
expect(downloaded).toBe(false)
describe "_newMailReceived", ->
it "should fetch attachments if the setting is on-receive", ->
spyOn(FileDownloadStore, '_fetch')
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
return 'on-receive' if key is 'core.attachments.downloadPolicy'
return null
FileDownloadStore._newMailReceived(message: [new Message(files: [new File()])])
expect(FileDownloadStore._fetch).toHaveBeenCalled()
it "should not fetch attachments otherwise", ->
spyOn(FileDownloadStore, '_fetch')
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
return 'on-read' if key is 'core.attachments.downloadPolicy'
return null
FileDownloadStore._newMailReceived(message: [new Message(files: [new File()])])
expect(FileDownloadStore._fetch).not.toHaveBeenCalled()
describe "_runDownload", ->
beforeEach ->
spyOn(FileDownloadStore.Download.prototype, 'run').andCallFake -> Promise.resolve(@)

View file

@ -140,11 +140,11 @@ FileDownloadStore = Reflux.createStore
########### PRIVATE ####################################################
_newMailReceived: (incoming) =>
return unless NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-receive'
for message in incoming
for file in message.files
@_fetch(file)
_newMailReceived: (incoming) ->
if NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-receive'
for message in incoming['message']
for file in message.files
@_fetch(file)
# Returns a promise with a Download object, allowing other actions to be
# daisy-chained to the end of the download operation.

View file

@ -259,7 +259,9 @@ class MessageStore extends NylasStore
startedAFetch
_fetchExpandedAttachments: (items) ->
return unless NylasEnv.config.get('core.attachments.downloadPolicy') is 'on-read'
policy = NylasEnv.config.get('core.attachments.downloadPolicy')
return if policy is 'manually'
for item in items
continue unless @_itemsExpanded[item.id]
for file in item.files