mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-22 23:23:54 +08:00
fix(tasks): SyncbackCategory does not need organizationUnit
This commit is contained in:
parent
98a2464e0f
commit
4810775924
2 changed files with 16 additions and 15 deletions
|
@ -13,15 +13,13 @@ describe "SyncbackCategoryTask", ->
|
|||
nameOf = (fn) ->
|
||||
fn.calls[0].args[0].body.display_name
|
||||
|
||||
makeTask = (orgUnit) ->
|
||||
Category = if orgUnit is "label" then Label else Folder
|
||||
category = new Category
|
||||
makeTask = (CategoryClass) ->
|
||||
category = new CategoryClass
|
||||
displayName: "important emails"
|
||||
accountId: "account 123"
|
||||
clientId: "local-444"
|
||||
new SyncbackCategoryTask
|
||||
category: category
|
||||
organizationUnit: orgUnit
|
||||
|
||||
beforeEach ->
|
||||
spyOn(NylasAPI, "makeRequest").andCallFake ->
|
||||
|
@ -29,28 +27,28 @@ describe "SyncbackCategoryTask", ->
|
|||
spyOn(DatabaseStore, "persistModel")
|
||||
|
||||
it "sends API req to /labels if user uses labels", ->
|
||||
task = makeTask "label"
|
||||
task = makeTask(Label)
|
||||
task.performRemote({})
|
||||
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels"
|
||||
|
||||
it "sends API req to /folders if user uses folders", ->
|
||||
task = makeTask "folder"
|
||||
task = makeTask(Folder)
|
||||
task.performRemote({})
|
||||
expect(pathOf(NylasAPI.makeRequest)).toBe "/folders"
|
||||
|
||||
it "sends the account id", ->
|
||||
task = makeTask "label"
|
||||
task = makeTask(Label)
|
||||
task.performRemote({})
|
||||
expect(accountIdOf(NylasAPI.makeRequest)).toBe "account 123"
|
||||
|
||||
it "sends the display name in the body", ->
|
||||
task = makeTask "label"
|
||||
task = makeTask(Label)
|
||||
task.performRemote({})
|
||||
expect(nameOf(NylasAPI.makeRequest)).toBe "important emails"
|
||||
|
||||
it "adds server id to the category, then saves the category", ->
|
||||
waitsForPromise ->
|
||||
task = makeTask "label"
|
||||
task = makeTask(Label)
|
||||
task.performRemote({})
|
||||
.then ->
|
||||
expect(DatabaseStore.persistModel).toHaveBeenCalled()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
CategoryStore = require '../stores/category-store'
|
||||
DatabaseStore = require '../stores/database-store'
|
||||
Label = require '../models/label'
|
||||
Folder = require '../models/folder'
|
||||
{generateTempId} = require '../models/utils'
|
||||
Task = require './task'
|
||||
NylasAPI = require '../nylas-api'
|
||||
|
@ -7,11 +9,14 @@ NylasAPI = require '../nylas-api'
|
|||
|
||||
module.exports = class SyncbackCategoryTask extends Task
|
||||
|
||||
constructor: ({@category, @organizationUnit}={}) ->
|
||||
constructor: ({@category}={}) ->
|
||||
super
|
||||
|
||||
label: ->
|
||||
"Creating new #{@organizationUnit}..."
|
||||
if @category instanceof Label
|
||||
"Creating new label..."
|
||||
else
|
||||
"Creating new folder..."
|
||||
|
||||
performLocal: ->
|
||||
# When we send drafts, we don't update anything in the app until
|
||||
|
@ -19,8 +24,6 @@ module.exports = class SyncbackCategoryTask extends Task
|
|||
# already sent when they haven't!
|
||||
if not @category
|
||||
return Promise.reject(new Error("Attempt to call SyncbackCategoryTask.performLocal without @category."))
|
||||
else if @organizationUnit isnt "label" and @organizationUnit isnt "folder"
|
||||
return Promise.reject(new Error("Attempt to call SyncbackCategoryTask.performLocal with @organizationUnit which wasn't 'folder' or 'label'."))
|
||||
|
||||
if @_shouldChangeBackwards()
|
||||
DatabaseStore.unpersistModel @category
|
||||
|
@ -28,9 +31,9 @@ module.exports = class SyncbackCategoryTask extends Task
|
|||
DatabaseStore.persistModel @category
|
||||
|
||||
performRemote: ->
|
||||
if @organizationUnit is "label"
|
||||
if @category instanceof Label
|
||||
path = "/labels"
|
||||
else if @organizationUnit is "folder"
|
||||
else
|
||||
path = "/folders"
|
||||
|
||||
NylasAPI.makeRequest
|
||||
|
|
Loading…
Reference in a new issue