fix(tasks): SyncbackCategory does not need organizationUnit

This commit is contained in:
Ben Gotow 2015-10-21 11:07:08 -07:00
parent 98a2464e0f
commit 4810775924
2 changed files with 16 additions and 15 deletions

View file

@ -13,15 +13,13 @@ describe "SyncbackCategoryTask", ->
nameOf = (fn) -> nameOf = (fn) ->
fn.calls[0].args[0].body.display_name fn.calls[0].args[0].body.display_name
makeTask = (orgUnit) -> makeTask = (CategoryClass) ->
Category = if orgUnit is "label" then Label else Folder category = new CategoryClass
category = new Category
displayName: "important emails" displayName: "important emails"
accountId: "account 123" accountId: "account 123"
clientId: "local-444" clientId: "local-444"
new SyncbackCategoryTask new SyncbackCategoryTask
category: category category: category
organizationUnit: orgUnit
beforeEach -> beforeEach ->
spyOn(NylasAPI, "makeRequest").andCallFake -> spyOn(NylasAPI, "makeRequest").andCallFake ->
@ -29,28 +27,28 @@ describe "SyncbackCategoryTask", ->
spyOn(DatabaseStore, "persistModel") spyOn(DatabaseStore, "persistModel")
it "sends API req to /labels if user uses labels", -> it "sends API req to /labels if user uses labels", ->
task = makeTask "label" task = makeTask(Label)
task.performRemote({}) task.performRemote({})
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels" expect(pathOf(NylasAPI.makeRequest)).toBe "/labels"
it "sends API req to /folders if user uses folders", -> it "sends API req to /folders if user uses folders", ->
task = makeTask "folder" task = makeTask(Folder)
task.performRemote({}) task.performRemote({})
expect(pathOf(NylasAPI.makeRequest)).toBe "/folders" expect(pathOf(NylasAPI.makeRequest)).toBe "/folders"
it "sends the account id", -> it "sends the account id", ->
task = makeTask "label" task = makeTask(Label)
task.performRemote({}) task.performRemote({})
expect(accountIdOf(NylasAPI.makeRequest)).toBe "account 123" expect(accountIdOf(NylasAPI.makeRequest)).toBe "account 123"
it "sends the display name in the body", -> it "sends the display name in the body", ->
task = makeTask "label" task = makeTask(Label)
task.performRemote({}) task.performRemote({})
expect(nameOf(NylasAPI.makeRequest)).toBe "important emails" expect(nameOf(NylasAPI.makeRequest)).toBe "important emails"
it "adds server id to the category, then saves the category", -> it "adds server id to the category, then saves the category", ->
waitsForPromise -> waitsForPromise ->
task = makeTask "label" task = makeTask(Label)
task.performRemote({}) task.performRemote({})
.then -> .then ->
expect(DatabaseStore.persistModel).toHaveBeenCalled() expect(DatabaseStore.persistModel).toHaveBeenCalled()

View file

@ -1,5 +1,7 @@
CategoryStore = require '../stores/category-store' CategoryStore = require '../stores/category-store'
DatabaseStore = require '../stores/database-store' DatabaseStore = require '../stores/database-store'
Label = require '../models/label'
Folder = require '../models/folder'
{generateTempId} = require '../models/utils' {generateTempId} = require '../models/utils'
Task = require './task' Task = require './task'
NylasAPI = require '../nylas-api' NylasAPI = require '../nylas-api'
@ -7,11 +9,14 @@ NylasAPI = require '../nylas-api'
module.exports = class SyncbackCategoryTask extends Task module.exports = class SyncbackCategoryTask extends Task
constructor: ({@category, @organizationUnit}={}) -> constructor: ({@category}={}) ->
super super
label: -> label: ->
"Creating new #{@organizationUnit}..." if @category instanceof Label
"Creating new label..."
else
"Creating new folder..."
performLocal: -> performLocal: ->
# When we send drafts, we don't update anything in the app until # 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! # already sent when they haven't!
if not @category if not @category
return Promise.reject(new Error("Attempt to call SyncbackCategoryTask.performLocal without @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() if @_shouldChangeBackwards()
DatabaseStore.unpersistModel @category DatabaseStore.unpersistModel @category
@ -28,9 +31,9 @@ module.exports = class SyncbackCategoryTask extends Task
DatabaseStore.persistModel @category DatabaseStore.persistModel @category
performRemote: -> performRemote: ->
if @organizationUnit is "label" if @category instanceof Label
path = "/labels" path = "/labels"
else if @organizationUnit is "folder" else
path = "/folders" path = "/folders"
NylasAPI.makeRequest NylasAPI.makeRequest