mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 16:14:01 +08:00
Fix specs for destroy and syncback category tasks
This commit is contained in:
parent
ad05cc05cc
commit
c5dc9544e1
3 changed files with 26 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
{DestroyCategoryTask,
|
{DestroyCategoryTask,
|
||||||
NylasAPI,
|
NylasAPI,
|
||||||
Task,
|
Task,
|
||||||
|
Category,
|
||||||
|
AccountStore,
|
||||||
APIError,
|
APIError,
|
||||||
Category,
|
Category,
|
||||||
DatabaseStore,
|
DatabaseStore,
|
||||||
|
@ -19,6 +21,11 @@ describe "DestroyCategoryTask", ->
|
||||||
nameOf = (fn) ->
|
nameOf = (fn) ->
|
||||||
fn.calls[0].args[0].body.display_name
|
fn.calls[0].args[0].body.display_name
|
||||||
|
|
||||||
|
makeAccount = ({usesFolders, usesLabels} = {}) ->
|
||||||
|
spyOn(AccountStore, "accountForId").andReturn {
|
||||||
|
usesFolders: -> usesFolders
|
||||||
|
usesLabels: -> usesLabels
|
||||||
|
}
|
||||||
makeTask = ->
|
makeTask = ->
|
||||||
category = new Category
|
category = new Category
|
||||||
displayName: "important emails"
|
displayName: "important emails"
|
||||||
|
@ -69,27 +76,32 @@ describe "DestroyCategoryTask", ->
|
||||||
spyOn(NylasAPI, "makeRequest").andCallFake -> Promise.resolve("null")
|
spyOn(NylasAPI, "makeRequest").andCallFake -> Promise.resolve("null")
|
||||||
|
|
||||||
it "sends API req to /labels if user uses labels", ->
|
it "sends API req to /labels if user uses labels", ->
|
||||||
|
makeAccount(usesLabels: true)
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote()
|
task.performRemote()
|
||||||
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels/server-444"
|
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels/server-444"
|
||||||
|
|
||||||
it "sends API req to /folders if user uses folders", ->
|
it "sends API req to /folders if user uses folders", ->
|
||||||
|
makeAccount(usesFolders: true)
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote()
|
task.performRemote()
|
||||||
expect(pathOf(NylasAPI.makeRequest)).toBe "/folders/server-444"
|
expect(pathOf(NylasAPI.makeRequest)).toBe "/folders/server-444"
|
||||||
|
|
||||||
it "sends DELETE request", ->
|
it "sends DELETE request", ->
|
||||||
|
makeAccount()
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote()
|
task.performRemote()
|
||||||
expect(methodOf(NylasAPI.makeRequest)).toBe "DELETE"
|
expect(methodOf(NylasAPI.makeRequest)).toBe "DELETE"
|
||||||
|
|
||||||
it "sends the account id", ->
|
it "sends the account id", ->
|
||||||
|
makeAccount()
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote()
|
task.performRemote()
|
||||||
expect(accountIdOf(NylasAPI.makeRequest)).toBe "account 123"
|
expect(accountIdOf(NylasAPI.makeRequest)).toBe "account 123"
|
||||||
|
|
||||||
describe "when request fails", ->
|
describe "when request fails", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
makeAccount()
|
||||||
spyOn(NylasEnv, 'emitError')
|
spyOn(NylasEnv, 'emitError')
|
||||||
spyOn(NylasAPI, 'makeRequest').andCallFake ->
|
spyOn(NylasAPI, 'makeRequest').andCallFake ->
|
||||||
Promise.reject(new APIError({statusCode: 403}))
|
Promise.reject(new APIError({statusCode: 403}))
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{NylasAPI,
|
{NylasAPI,
|
||||||
|
Category,
|
||||||
|
AccountStore,
|
||||||
DatabaseStore,
|
DatabaseStore,
|
||||||
SyncbackCategoryTask,
|
SyncbackCategoryTask,
|
||||||
DatabaseTransaction} = require "nylas-exports"
|
DatabaseTransaction} = require "nylas-exports"
|
||||||
|
@ -14,6 +16,12 @@ describe "SyncbackCategoryTask", ->
|
||||||
nameOf = (fn) ->
|
nameOf = (fn) ->
|
||||||
fn.calls[0].args[0].body.display_name
|
fn.calls[0].args[0].body.display_name
|
||||||
|
|
||||||
|
makeAccount = ({usesFolders, usesLabels} = {}) ->
|
||||||
|
spyOn(AccountStore, "accountForId").andReturn {
|
||||||
|
usesFolders: -> usesFolders
|
||||||
|
usesLabels: -> usesLabels
|
||||||
|
}
|
||||||
|
|
||||||
makeTask = ->
|
makeTask = ->
|
||||||
category = new Category
|
category = new Category
|
||||||
displayName: "important emails"
|
displayName: "important emails"
|
||||||
|
@ -29,26 +37,31 @@ describe "SyncbackCategoryTask", ->
|
||||||
spyOn(DatabaseTransaction.prototype, "persistModel")
|
spyOn(DatabaseTransaction.prototype, "persistModel")
|
||||||
|
|
||||||
it "sends API req to /labels if the account uses labels", ->
|
it "sends API req to /labels if the account uses labels", ->
|
||||||
|
makeAccount(usesLabels: true)
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote({})
|
task.performRemote({})
|
||||||
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels"
|
expect(pathOf(NylasAPI.makeRequest)).toBe "/labels"
|
||||||
|
|
||||||
it "sends API req to /folders if the account uses folders", ->
|
it "sends API req to /folders if the account uses folders", ->
|
||||||
|
makeAccount(usesFolders: true)
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
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", ->
|
||||||
|
makeAccount()
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
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", ->
|
||||||
|
makeAccount()
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
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", ->
|
||||||
|
makeAccount()
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
task = makeTask()
|
task = makeTask()
|
||||||
task.performRemote({})
|
task.performRemote({})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
CategoryStore = require '../stores/category-store'
|
CategoryStore = require '../stores/category-store'
|
||||||
DatabaseStore = require '../stores/database-store'
|
DatabaseStore = require '../stores/database-store'
|
||||||
|
AccountStore = require '../stores/account-store'
|
||||||
{generateTempId} = require '../models/utils'
|
{generateTempId} = require '../models/utils'
|
||||||
Task = require './task'
|
Task = require './task'
|
||||||
NylasAPI = require '../nylas-api'
|
NylasAPI = require '../nylas-api'
|
||||||
|
|
Loading…
Reference in a new issue