Mailspring/spec-nylas/tasks/event-rsvp-spec.coffee
Ben Gotow 607ca3bf10 feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.

This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.

When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.

Search bar doesn't need to do full refresh on clear if it never committed

Allow drafts to be switched to a different account when not in reply to an existing thread

Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal

Show many dots for many accounts in long polling status bar

add/remove accounts from prefs

Spec fixes!

Test Plan: Run tests, none broken!

Reviewers: evan, dillon

Reviewed By: evan, dillon

Differential Revision: https://phab.nylas.com/D1928
2015-08-21 15:29:58 -07:00

92 lines
3.1 KiB
CoffeeScript

NylasAPI = require '../../src/flux/nylas-api'
Actions = require '../../src/flux/actions'
{APIError} = require '../../src/flux/errors'
EventRSVPTask = require '../../src/flux/tasks/event-rsvp'
DatabaseStore = require '../../src/flux/stores/database-store'
Event = require '../../src/flux/models/event'
AccountStore = require '../../src/flux/stores/account-store'
_ = require 'underscore'
describe "EventRSVPTask", ->
beforeEach ->
spyOn(DatabaseStore, 'find').andCallFake => Promise.resolve(@event)
spyOn(DatabaseStore, '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, "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(DatabaseStore.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, "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(DatabaseStore.persistModel).toHaveBeenCalled()