2015-07-16 23:54:20 +08:00
|
|
|
_ = require 'underscore'
|
2016-10-27 07:01:23 +08:00
|
|
|
Label = require('../../src/flux/models/label').default
|
2016-05-04 07:42:28 +08:00
|
|
|
Thread = require('../../src/flux/models/thread').default
|
2016-05-05 08:00:53 +08:00
|
|
|
Message = require('../../src/flux/models/message').default
|
2016-10-28 09:48:33 +08:00
|
|
|
Actions = require('../../src/flux/actions').default
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
NylasAPI = require('../../src/flux/nylas-api').default
|
2016-10-01 06:24:34 +08:00
|
|
|
DatabaseStore = require('../../src/flux/stores/database-store').default
|
2016-05-04 07:42:28 +08:00
|
|
|
ChangeLabelsTask = require('../../src/flux/tasks/change-labels-task').default
|
|
|
|
ChangeMailTask = require('../../src/flux/tasks/change-mail-task').default
|
2015-07-16 23:54:20 +08:00
|
|
|
|
fix(gmail-labels): Constraint so threads always belong to all,spam or trash
Summary:
- In Gmail all threads /must/ belong to either All Mail, Trash and Spam, and
they are mutually exclusive, so we need to make sure that any add/remove
label operation still guarantees that constraint
- Update ChangeLabelsTask to modify the set of labels to add and remove
based on this rule
- Update tasksFor archiving, moving to trash and moving to spam so they
don't affect any other labels in the thread, as gmail does.
- Removing from view /will/ remove any current labels, but will also
move between all mail and trash as needed
- Remove Inbox, Trash and Spam from the CategoryPicker, as Gmail does
Test Plan: - Unit tests
Reviewers: drew, evan, bengotow
Reviewed By: drew, evan, bengotow
Differential Revision: https://phab.nylas.com/D2715
2016-03-11 06:11:47 +08:00
|
|
|
{AccountStore, CategoryStore} = require 'nylas-exports'
|
2015-07-16 23:54:20 +08:00
|
|
|
{APIError} = require '../../src/flux/errors'
|
|
|
|
{Utils} = require '../../src/flux/models/utils'
|
|
|
|
|
2015-08-04 01:16:46 +08:00
|
|
|
testLabels = {}
|
|
|
|
testThreads = {}
|
2015-07-16 23:54:20 +08:00
|
|
|
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
xdescribe "ChangeLabelsTask", ->
|
2015-07-16 23:54:20 +08:00
|
|
|
beforeEach ->
|
2015-08-06 06:53:08 +08:00
|
|
|
# IMPORTANT: These specs do not run the performLocal logic of their superclass!
|
|
|
|
# Tests for that logic are in change-mail-task-spec.
|
2016-03-22 07:50:10 +08:00
|
|
|
spyOn(ChangeMailTask.prototype, 'performLocal').andCallFake =>
|
2015-08-06 06:53:08 +08:00
|
|
|
Promise.resolve()
|
|
|
|
|
fix(gmail-labels): Constraint so threads always belong to all,spam or trash
Summary:
- In Gmail all threads /must/ belong to either All Mail, Trash and Spam, and
they are mutually exclusive, so we need to make sure that any add/remove
label operation still guarantees that constraint
- Update ChangeLabelsTask to modify the set of labels to add and remove
based on this rule
- Update tasksFor archiving, moving to trash and moving to spam so they
don't affect any other labels in the thread, as gmail does.
- Removing from view /will/ remove any current labels, but will also
move between all mail and trash as needed
- Remove Inbox, Trash and Spam from the CategoryPicker, as Gmail does
Test Plan: - Unit tests
Reviewers: drew, evan, bengotow
Reviewed By: drew, evan, bengotow
Differential Revision: https://phab.nylas.com/D2715
2016-03-11 06:11:47 +08:00
|
|
|
spyOn(AccountStore, 'accountForItems').andReturn({id: 'a1'})
|
|
|
|
spyOn(CategoryStore, 'getTrashCategory').andReturn name: 'trash'
|
|
|
|
spyOn(CategoryStore, 'getInboxCategory').andReturn name: 'inbox'
|
|
|
|
spyOn(CategoryStore, 'getSpamCategory').andReturn name: 'spam'
|
|
|
|
spyOn(CategoryStore, 'getAllMailCategory').andReturn name: 'all'
|
|
|
|
|
2015-08-06 06:53:08 +08:00
|
|
|
spyOn(DatabaseStore, 'modelify').andCallFake (klass, items) =>
|
|
|
|
Promise.resolve items.map (item) =>
|
|
|
|
return testLabels[item] if testLabels[item]
|
|
|
|
return testThreads[item] if testThreads[item]
|
|
|
|
item
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-08-04 01:16:46 +08:00
|
|
|
testLabels = @testLabels =
|
|
|
|
"l1": new Label({name: 'inbox', id: 'l1', displayName: "INBOX"}),
|
|
|
|
"l2": new Label({name: 'drafts', id: 'l2', displayName: "MyDrafts"})
|
|
|
|
"l3": new Label({name: null, id: 'l3', displayName: "My Label"})
|
|
|
|
|
|
|
|
testThreads = @testThreads =
|
2016-01-23 08:55:29 +08:00
|
|
|
't1': new Thread(id: 't1', categories: [@testLabels['l1']])
|
|
|
|
't2': new Thread(id: 't2', categories: _.values(@testLabels))
|
|
|
|
't3': new Thread(id: 't3', categories: [@testLabels['l2'], @testLabels['l3']])
|
2015-08-04 01:16:46 +08:00
|
|
|
|
|
|
|
@basicThreadTask = new ChangeLabelsTask
|
|
|
|
labelsToAdd: ["l1", "l2"]
|
|
|
|
labelsToRemove: ["l3"]
|
2015-08-06 06:53:08 +08:00
|
|
|
threads: ['t1']
|
2015-08-04 01:16:46 +08:00
|
|
|
|
2015-08-04 05:46:19 +08:00
|
|
|
describe "description", ->
|
|
|
|
it "should include the name of the added label if it's the only mutation and it was provided as an object", ->
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: ["l1"], labelsToRemove: [], threads: ['t1'])
|
2016-06-02 05:36:57 +08:00
|
|
|
expect(task.description()).toEqual("Changed labels")
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(id: 'l1', displayName: 'LABEL')], labelsToRemove: [], threads: ['t1'])
|
2016-06-02 05:36:57 +08:00
|
|
|
expect(task.description()).toEqual("Added LABEL")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(id: 'l1', displayName: 'LABEL')], labelsToRemove: ['l2'], threads: ['t1', 't2'])
|
|
|
|
expect(task.description()).toEqual("Moved 2 threads to LABEL")
|
2015-08-04 05:46:19 +08:00
|
|
|
|
|
|
|
it "should include the name of the removed label if it's the only mutation and it was provided as an object", ->
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [], labelsToRemove: ["l1"], threads: ['t1'])
|
2016-06-02 05:36:57 +08:00
|
|
|
expect(task.description()).toEqual("Changed labels")
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [], labelsToRemove: [new Label(id: 'l1', displayName: 'LABEL')], threads: ['t1'])
|
2016-06-02 05:36:57 +08:00
|
|
|
expect(task.description()).toEqual("Removed LABEL")
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: ['l2'], labelsToRemove: [new Label(id: 'l1', displayName: 'LABEL')], threads: ['t1'])
|
2016-06-02 05:36:57 +08:00
|
|
|
expect(task.description()).toEqual("Changed labels")
|
2015-08-04 05:46:19 +08:00
|
|
|
|
|
|
|
it "should pluralize properly", ->
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: ["l2"], labelsToRemove: ["l1"], threads: ['t1', 't2', 't3'])
|
2015-08-04 05:46:19 +08:00
|
|
|
expect(task.description()).toEqual("Changed labels on 3 threads")
|
2016-06-02 05:36:57 +08:00
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(id: 'l1', displayName: 'LABEL')], labelsToRemove: [], threads: ['t1', 't2'])
|
|
|
|
expect(task.description()).toEqual("Added LABEL to 2 threads")
|
|
|
|
|
|
|
|
it "should include special cases for some common cases", ->
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "all")], labelsToRemove: [new Label(name: 'inbox')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Archived 3 threads")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "trash")], labelsToRemove: [new Label(name: 'inbox')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Trashed 3 threads")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "spam")], labelsToRemove: [new Label(name: 'inbox')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Marked 3 threads as Spam")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "inbox")], labelsToRemove: [new Label(name: 'spam')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Unmarked 3 threads as Spam")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "inbox")], labelsToRemove: [new Label(name: 'all')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Unarchived 3 threads")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "inbox")], labelsToRemove: [new Label(name: 'trash')], threads: ['t1', 't2', 't3'])
|
|
|
|
expect(task.description()).toEqual("Removed 3 threads from Trash")
|
|
|
|
task = new ChangeLabelsTask(labelsToAdd: [new Label(name: "inbox")], labelsToRemove: [new Label(name: 'trash')], threads: ['t1'])
|
|
|
|
expect(task.description()).toEqual("Removed from Trash")
|
2015-08-04 05:46:19 +08:00
|
|
|
|
fix(gmail-labels): Constraint so threads always belong to all,spam or trash
Summary:
- In Gmail all threads /must/ belong to either All Mail, Trash and Spam, and
they are mutually exclusive, so we need to make sure that any add/remove
label operation still guarantees that constraint
- Update ChangeLabelsTask to modify the set of labels to add and remove
based on this rule
- Update tasksFor archiving, moving to trash and moving to spam so they
don't affect any other labels in the thread, as gmail does.
- Removing from view /will/ remove any current labels, but will also
move between all mail and trash as needed
- Remove Inbox, Trash and Spam from the CategoryPicker, as Gmail does
Test Plan: - Unit tests
Reviewers: drew, evan, bengotow
Reviewed By: drew, evan, bengotow
Differential Revision: https://phab.nylas.com/D2715
2016-03-11 06:11:47 +08:00
|
|
|
describe "_ensureAndUpdateLabels", ->
|
|
|
|
beforeEach ->
|
|
|
|
@task = new ChangeLabelsTask()
|
|
|
|
@account = {}
|
|
|
|
|
|
|
|
it "does not remove `all` if attempting to remove `all` without adding `trash` or `spam`", ->
|
|
|
|
toAdd = []
|
|
|
|
toRemove = [{name: 'all'}]
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToRemove).toEqual([])
|
|
|
|
|
|
|
|
it "removes `trash` and `spam` if attempting to add `all` and not already removing them", ->
|
|
|
|
toRemove = []
|
|
|
|
toAdd = [{name: 'all'}]
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToRemove).toEqual([{name: 'trash'}, {name: 'spam'}])
|
|
|
|
|
|
|
|
it "adds `all` if removing `trash` and not adding to `all` or `spam`", ->
|
|
|
|
toRemove = [{name: 'trash'}]
|
|
|
|
toAdd = []
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToAdd).toEqual([{name: 'all'}])
|
|
|
|
|
|
|
|
it "removes `all` and `spam` if attempting to add `trash` and not already removing it", ->
|
|
|
|
toRemove = []
|
|
|
|
toAdd = [{name: 'trash'}]
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToRemove).toEqual([{name: 'all'}, {name: 'spam'}])
|
|
|
|
|
|
|
|
it "adds `all` if removing `spam` and not adding to `all` or `trash`", ->
|
|
|
|
toRemove = [{name: 'spam'}]
|
|
|
|
toAdd = []
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToAdd).toEqual([{name: 'all'}])
|
|
|
|
|
|
|
|
it "removes `all` and `trash` if attempting to add `spam` and not already removing it", ->
|
|
|
|
toRemove = []
|
|
|
|
toAdd = [{name: 'spam'}]
|
|
|
|
{labelsToAdd, labelsToRemove} = @task._ensureAndUpdateLabels(@account, toAdd, toRemove)
|
|
|
|
expect(labelsToRemove).toEqual([{name: 'all'}, {name: 'trash'}])
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
describe "performLocal", ->
|
2015-12-18 03:46:05 +08:00
|
|
|
it "should throw an exception if task has not been given a label, has been given messages, or no threads", ->
|
2015-07-16 23:54:20 +08:00
|
|
|
badTasks = [
|
|
|
|
new ChangeLabelsTask(),
|
2015-08-06 06:53:08 +08:00
|
|
|
new ChangeLabelsTask(threads: [123]),
|
|
|
|
new ChangeLabelsTask(threads: [123], messages: ["foo"]),
|
2015-12-18 03:46:05 +08:00
|
|
|
new ChangeLabelsTask(labelsToAdd: ['l2'], labelsToRemove: ['l1'], messages: [123]),
|
2015-08-06 06:53:08 +08:00
|
|
|
new ChangeLabelsTask(threads: "Thread"),
|
2015-07-16 23:54:20 +08:00
|
|
|
]
|
|
|
|
goodTasks = [
|
|
|
|
new ChangeLabelsTask(
|
|
|
|
labelsToAdd: ['l2']
|
|
|
|
labelsToRemove: ['l1']
|
2015-08-06 06:53:08 +08:00
|
|
|
threads: ['t1']
|
2015-07-16 23:54:20 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
caught = []
|
|
|
|
succeeded = []
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
[].concat(badTasks, goodTasks).forEach (task) ->
|
|
|
|
task.performLocal()
|
|
|
|
.then -> succeeded.push(task)
|
|
|
|
.catch (err) -> caught.push(task)
|
|
|
|
waitsFor ->
|
|
|
|
succeeded.length + caught.length == 6
|
|
|
|
runs ->
|
|
|
|
expect(caught.length).toEqual(badTasks.length)
|
|
|
|
expect(succeeded.length).toEqual(goodTasks.length)
|
|
|
|
|
2015-08-06 06:53:08 +08:00
|
|
|
it 'calls through to super performLocal', ->
|
2015-08-04 01:16:46 +08:00
|
|
|
task = new ChangeLabelsTask
|
2015-08-06 06:53:08 +08:00
|
|
|
labelsToAdd: ['l2']
|
|
|
|
labelsToRemove: ['l1']
|
|
|
|
threads: ['t1']
|
2015-08-04 01:16:46 +08:00
|
|
|
waitsForPromise =>
|
2015-08-06 06:53:08 +08:00
|
|
|
task.performLocal().then =>
|
2016-03-22 07:50:10 +08:00
|
|
|
expect(task.__proto__.__proto__.performLocal).toHaveBeenCalled()
|
2015-08-04 01:16:46 +08:00
|
|
|
|
2016-06-01 07:31:24 +08:00
|
|
|
describe "retrieveModels", ->
|
|
|
|
describe "when object IDs are provided", ->
|
|
|
|
beforeEach ->
|
|
|
|
@task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: ['l2']
|
|
|
|
labelsToRemove: ['l1']
|
|
|
|
threads: ['t1']
|
|
|
|
|
|
|
|
it 'resolves the objects before calling super', ->
|
|
|
|
waitsForPromise =>
|
|
|
|
@task.retrieveModels().then =>
|
|
|
|
expect(@task.labelsToAdd).toEqual([testLabels['l2']])
|
|
|
|
expect(@task.labelsToRemove).toEqual([testLabels['l1']])
|
|
|
|
expect(@task.threads).toEqual([testThreads['t1']])
|
|
|
|
|
|
|
|
describe "when objects are provided", ->
|
|
|
|
beforeEach ->
|
|
|
|
@task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: [testLabels['l2']]
|
|
|
|
labelsToRemove: [testLabels['l1']]
|
|
|
|
threads: [testThreads['t1']]
|
|
|
|
|
|
|
|
it 'still has the objects when calling super', ->
|
|
|
|
waitsForPromise =>
|
|
|
|
@task.retrieveModels().then =>
|
|
|
|
expect(@task.labelsToAdd).toEqual([testLabels['l2']])
|
|
|
|
expect(@task.labelsToRemove).toEqual([testLabels['l1']])
|
|
|
|
expect(@task.threads).toEqual([testThreads['t1']])
|
2015-08-06 06:53:08 +08:00
|
|
|
|
|
|
|
describe 'change methods', ->
|
2015-10-30 01:25:34 +08:00
|
|
|
describe "changesToModel", ->
|
2015-08-06 06:53:08 +08:00
|
|
|
it 'properly adds labels', ->
|
|
|
|
task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: [testLabels['l1'], testLabels['l2']]
|
|
|
|
labelsToRemove: []
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.changesToModel(testThreads['t1'])
|
2015-08-06 06:53:08 +08:00
|
|
|
expect(out).toEqual(labels: [testLabels['l1'], testLabels['l2']])
|
|
|
|
|
|
|
|
it 'properly removes labels', ->
|
|
|
|
task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: []
|
|
|
|
labelsToRemove: [testLabels['l1'], testLabels['l2']]
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.changesToModel(testThreads['t3'])
|
2015-08-06 06:53:08 +08:00
|
|
|
expect(out).toEqual(labels: [testLabels['l3']])
|
|
|
|
|
2016-02-06 03:56:43 +08:00
|
|
|
it 'properly adds and removes labels, ignoring labels that are both added and removed', ->
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: [testLabels['l1'], testLabels['l2']]
|
|
|
|
labelsToRemove: [testLabels['l2'], testLabels['l3']]
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.changesToModel(testThreads['t1'])
|
2016-02-06 03:56:43 +08:00
|
|
|
expect(out).toEqual(labels: [testLabels['l1'], testLabels['l2']])
|
2015-08-06 06:53:08 +08:00
|
|
|
|
|
|
|
it 'should return an == array of labels when no changes have occurred', ->
|
2016-01-23 08:55:29 +08:00
|
|
|
thread = new Thread(id: '1', categories: [testLabels['l2'], testLabels['l3'], testLabels['l1']])
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: [testLabels['l3'], testLabels['l1'], testLabels['l2']]
|
|
|
|
labelsToRemove: []
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.changesToModel(thread)
|
2015-08-06 06:53:08 +08:00
|
|
|
expect(_.isEqual(thread.labels, out.labels)).toBe(true)
|
|
|
|
|
|
|
|
it 'should not modify the input thread in any way', ->
|
2016-01-23 08:55:29 +08:00
|
|
|
thread = new Thread(id: '1', categories: [testLabels['l2'], testLabels['l1']])
|
2015-08-06 06:53:08 +08:00
|
|
|
task = new ChangeLabelsTask
|
|
|
|
labelsToAdd: []
|
|
|
|
labelsToRemove: [testLabels['l2']]
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.changesToModel(thread)
|
2015-08-06 06:53:08 +08:00
|
|
|
expect(thread.labels.length).toBe(2)
|
|
|
|
expect(out.labels.length).toBe(1)
|
|
|
|
|
2015-10-30 01:25:34 +08:00
|
|
|
describe "requestBodyForModel", ->
|
2015-08-06 06:53:08 +08:00
|
|
|
it 'returns labels:<ids> for both threads and messages', ->
|
|
|
|
task = new ChangeLabelsTask()
|
|
|
|
|
2015-10-30 01:25:34 +08:00
|
|
|
out = task.requestBodyForModel(testThreads['t3'])
|
2015-08-06 06:53:08 +08:00
|
|
|
expect(out).toEqual(labels: ['l2', 'l3'])
|