2016-03-04 04:37:20 +08:00
|
|
|
import {
|
|
|
|
Message,
|
|
|
|
NylasAPI,
|
|
|
|
Actions,
|
|
|
|
DatabaseStore,
|
|
|
|
} from 'nylas-exports'
|
|
|
|
import SendLaterStore from '../lib/send-later-store'
|
|
|
|
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
describe('SendLaterStore', () => {
|
|
|
|
beforeEach(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.store = new SendLaterStore('plug-id', 'plug-name')
|
|
|
|
});
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
describe('onSendLater', () => {
|
|
|
|
it("should call setMetadata and then close the popover (if in a composer)", () => {
|
|
|
|
spyOn(Actions, 'closePopover');
|
|
|
|
spyOn(NylasEnv, 'isComposerWindow').andReturn(true);
|
|
|
|
spyOn(this.store, 'setMetadata').andReturn(Promise.resolve());
|
|
|
|
this.store.onSendLater('client-id', new Date(), 'asd');
|
|
|
|
advanceClock();
|
|
|
|
expect(Actions.closePopover).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setMetadata', () => {
|
|
|
|
beforeEach(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.message = new Message({accountId: 123, clientId: 'c-1'})
|
|
|
|
this.metadata = {sendLaterDate: 'the future'}
|
|
|
|
spyOn(this.store, 'recordAction')
|
|
|
|
spyOn(DatabaseStore, 'modelify').andReturn(Promise.resolve([this.message]))
|
|
|
|
spyOn(NylasAPI, 'authPlugin').andReturn(Promise.resolve())
|
|
|
|
spyOn(Actions, 'setMetadata')
|
|
|
|
spyOn(NylasEnv, 'reportError')
|
|
|
|
spyOn(NylasEnv, 'showErrorDialog')
|
|
|
|
});
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
it('auths the plugin correctly', () => {
|
|
|
|
waitsForPromise(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
return this.store.setMetadata('c-1', this.metadata)
|
2016-03-17 10:27:12 +08:00
|
|
|
.then(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(NylasAPI.authPlugin).toHaveBeenCalled()
|
|
|
|
expect(NylasAPI.authPlugin).toHaveBeenCalledWith(
|
|
|
|
'plug-id',
|
|
|
|
'plug-name',
|
|
|
|
123
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
it('sets the correct metadata', () => {
|
|
|
|
waitsForPromise(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
return this.store.setMetadata('c-1', this.metadata)
|
2016-03-17 10:27:12 +08:00
|
|
|
.then(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(Actions.setMetadata).toHaveBeenCalledWith(
|
2016-03-17 10:27:12 +08:00
|
|
|
this.message,
|
2016-03-04 04:37:20 +08:00
|
|
|
'plug-id',
|
|
|
|
this.metadata
|
|
|
|
)
|
|
|
|
expect(NylasEnv.reportError).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
it('displays dialog if an error occurs', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
jasmine.unspy(NylasAPI, 'authPlugin')
|
|
|
|
spyOn(NylasAPI, 'authPlugin').andReturn(Promise.reject(new Error('Oh no!')))
|
2016-03-17 10:27:12 +08:00
|
|
|
waitsForPromise(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
return this.store.setMetadata('c-1', this.metadata)
|
2016-03-17 10:27:12 +08:00
|
|
|
.finally(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(Actions.setMetadata).not.toHaveBeenCalled()
|
|
|
|
expect(NylasEnv.reportError).toHaveBeenCalled()
|
|
|
|
expect(NylasEnv.showErrorDialog).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|