mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
6695de4187
Summary: 1. **Generic CUD Tasks**: There is now a generic `CreateModelTask`, `UpdateModelTask`, and `DestroyModelTask`. These can either be used as-is or trivially overridden to easily update simple objects. Hopefully all of the boilerplate rollback, error handling, and undo logic won't have to be re-duplicated on every task. There are also tests for these tasks. We use them to perform mutating actions on `Metadata` objects. 1. **Failing on Promise Rejects**: Turns out that if a Promise rejected due to an error or `Promise.reject` we were ignoring it and letting tests pass. Now, tests will Fail if any unhandled promise rejects. This uncovered a variety of errors throughout the test suite that had to be fixed. The most significant one was during the `theme-manager` tests when all packages (and their stores with async DB requests) was loaded. Long after the `theme-manager` specs finished, those DB requests were (somtimes) silently failing. 1. **Globally stub `DatabaseStore._query`**: All tests shouldn't actually make queries on the database. Furthremore, the `inTransaction` block doesn't resolve at all unless `_query` is stubbed. Instead of manually remembering to do this in every test that touches the DB, it's now mocked in `spec_helper`. This broke a handful of tests that needed to be manually fixed. 1. **ESLint Fixes**: Some minor fixes to the linter config to prevent yelling about minor ES6 things and ensuring we have the correct parser. Test Plan: new tests Reviewers: bengotow, juan, drew Differential Revision: https://phab.nylas.com/D2419 Remove cloudState and N1-Send-Later
94 lines
2.9 KiB
CoffeeScript
94 lines
2.9 KiB
CoffeeScript
_ = require 'underscore'
|
|
|
|
{NylasAPI,
|
|
Event,
|
|
Actions,
|
|
APIError,
|
|
EventRSVPTask,
|
|
DatabaseStore,
|
|
DatabaseTransaction,
|
|
AccountStore} = require 'nylas-exports'
|
|
|
|
describe "EventRSVPTask", ->
|
|
beforeEach ->
|
|
spyOn(DatabaseStore, 'find').andCallFake => Promise.resolve(@event)
|
|
spyOn(DatabaseTransaction.prototype, 'persistModel').andCallFake -> Promise.resolve()
|
|
@myName = "Ben Tester"
|
|
@myEmail = "tester@nylas.com"
|
|
@event = new Event
|
|
id: '12233AEDF5'
|
|
accountId: TEST_ACCOUNT_ID
|
|
title: 'Meeting with Ben Bitdiddle'
|
|
description: ''
|
|
location: ''
|
|
when:
|
|
end_time: 1408123800
|
|
start_time: 1408120200
|
|
start: 1408120200
|
|
end: 1408123800
|
|
participants: [
|
|
{"name": "Ben Bitdiddle",
|
|
"email": "ben@bitdiddle.com",
|
|
"status": "yes"},
|
|
{"name": @myName,
|
|
"email": @myEmail,
|
|
"status": 'noreply'}
|
|
]
|
|
@task = new EventRSVPTask(@event, @myEmail, "no")
|
|
|
|
describe "performLocal", ->
|
|
it "should mark our status as no", ->
|
|
@task.performLocal()
|
|
advanceClock()
|
|
expect(@event.participants[1].status).toBe "no"
|
|
|
|
it "should trigger an action to persist the change", ->
|
|
@task.performLocal()
|
|
advanceClock()
|
|
expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled()
|
|
|
|
describe "performRemote", ->
|
|
it "should make the POST request to the message endpoint", ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake => new Promise (resolve,reject) ->
|
|
@task.performRemote()
|
|
options = NylasAPI.makeRequest.mostRecentCall.args[0]
|
|
expect(options.path).toBe("/send-rsvp")
|
|
expect(options.method).toBe('POST')
|
|
expect(options.accountId).toBe(@event.accountId)
|
|
expect(options.body.event_id).toBe(@event.id)
|
|
expect(options.body.status).toBe("no")
|
|
|
|
describe "when the remote API request fails", ->
|
|
beforeEach ->
|
|
spyOn(NylasAPI, 'makeRequest').andCallFake -> Promise.reject(new APIError(body: '', statusCode: 400))
|
|
|
|
it "should not be marked with the status", ->
|
|
@event = new Event
|
|
id: '12233AEDF5'
|
|
title: 'Meeting with Ben Bitdiddle'
|
|
description: ''
|
|
location: ''
|
|
when:
|
|
end_time: 1408123800
|
|
start_time: 1408120200
|
|
start: 1408120200
|
|
end: 1408123800
|
|
participants: [
|
|
{"name": "Ben Bitdiddle",
|
|
"email": "ben@bitdiddle.com",
|
|
"status": "yes"},
|
|
{"name": @myName,
|
|
"email": @myEmail,
|
|
"status": 'noreply'}
|
|
]
|
|
@task = new EventRSVPTask(@event, @myEmail, "no")
|
|
@task.performLocal()
|
|
@task.performRemote()
|
|
advanceClock()
|
|
expect(@event.participants[1].status).toBe "noreply"
|
|
|
|
it "should trigger an action to persist the change", ->
|
|
@task.performLocal()
|
|
@task.performRemote()
|
|
advanceClock()
|
|
expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled()
|