2017-02-10 08:15:19 +08:00
|
|
|
import {NylasAPIRequest, Message, SyncbackMetadataTask, Thread} from 'nylas-exports'
|
|
|
|
|
|
|
|
describe("SyncbackMetadataTask", () => {
|
|
|
|
it("sends messageIds if the object is a Thread", () => {
|
|
|
|
spyOn(NylasAPIRequest.prototype, 'run').andCallFake(function fakeRun() {
|
|
|
|
return Promise.resolve(this)
|
|
|
|
})
|
2017-06-22 04:12:49 +08:00
|
|
|
const thread = new Thread({id: 't:5'})
|
2017-02-10 08:15:19 +08:00
|
|
|
thread.applyPluginMetadata('test-plugin', {key: 'value'})
|
|
|
|
const messages = [
|
|
|
|
new Message({threadId: thread.id}),
|
|
|
|
new Message({threadId: thread.id}),
|
|
|
|
]
|
|
|
|
thread.messages = () => messages
|
2017-06-22 04:12:49 +08:00
|
|
|
const task = new SyncbackMetadataTask(thread.id, 'Thread', 'test-plugin')
|
2017-02-10 08:15:19 +08:00
|
|
|
waitsForPromise(() => task.makeRequest(thread).then(nylasAPIRequest => {
|
|
|
|
expect(nylasAPIRequest.options.body.messageIds).toEqual(messages.map(m => m.id))
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("does not send messageIds if the object is not a Thread", () => {
|
|
|
|
spyOn(NylasAPIRequest.prototype, 'run').andCallFake(function fakeRun() {
|
|
|
|
return Promise.resolve(this)
|
|
|
|
})
|
2017-06-22 04:12:49 +08:00
|
|
|
const message = new Message({id: '5'})
|
2017-02-10 08:15:19 +08:00
|
|
|
message.applyPluginMetadata('test-plugin', {key: 'value'})
|
2017-06-22 04:12:49 +08:00
|
|
|
const task = new SyncbackMetadataTask(message.id, 'Message', 'test-plugin')
|
2017-02-10 08:15:19 +08:00
|
|
|
waitsForPromise(() => task.makeRequest(message).then(nylasAPIRequest => {
|
|
|
|
expect(nylasAPIRequest.options.body.messageIds).toBeUndefined()
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|