mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-17 21:50:56 +08:00
149b389508
* Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
108 lines
3.7 KiB
TypeScript
108 lines
3.7 KiB
TypeScript
import { Utils, KeyManager } from 'mailspring-exports';
|
|
import { IdentityStore } from '../../src/flux/stores/identity-store';
|
|
import * as MailspringAPIRequest from '../../src/flux/mailspring-api-request';
|
|
|
|
const TEST_NYLAS_ID = 'icihsnqh4pwujyqihlrj70vh';
|
|
|
|
describe('IdentityStore', function identityStoreSpec() {
|
|
beforeEach(() => {
|
|
this.identityJSON = {
|
|
firstName: 'Mailspring 050',
|
|
lastName: 'Test',
|
|
email: 'mailspring050test@evanmorikawa.com',
|
|
id: TEST_NYLAS_ID,
|
|
featureUsage: {
|
|
feat: {
|
|
quota: 10,
|
|
usedInPeriod: 1,
|
|
},
|
|
},
|
|
token: 'secret token',
|
|
};
|
|
});
|
|
|
|
describe('saveIdentity', () => {
|
|
beforeEach(() => {
|
|
IdentityStore._identity = this.identityJSON;
|
|
spyOn(KeyManager, 'deletePassword');
|
|
spyOn(KeyManager, 'replacePassword');
|
|
spyOn(IdentityStore, 'trigger');
|
|
spyOn(AppEnv.config, 'set');
|
|
spyOn(AppEnv.config, 'unset');
|
|
});
|
|
|
|
it('clears passwords if unsetting', async () => {
|
|
IdentityStore.saveIdentity(null);
|
|
expect(KeyManager.deletePassword).toHaveBeenCalled();
|
|
expect(KeyManager.replacePassword).not.toHaveBeenCalled();
|
|
expect(AppEnv.config.set).toHaveBeenCalled();
|
|
const ident = AppEnv.config.set.calls[0].args[1];
|
|
expect(ident).toBe(null);
|
|
});
|
|
|
|
it('applies changes synchronously', async () => {
|
|
const used = () => IdentityStore.identity().featureUsage.feat.usedInPeriod;
|
|
expect(used()).toBe(1);
|
|
|
|
const next = JSON.parse(JSON.stringify(this.identityJSON));
|
|
next.featureUsage.feat.usedInPeriod += 1;
|
|
IdentityStore.saveIdentity(next);
|
|
expect(used()).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('returning the identity object', () => {
|
|
beforeEach(() => {
|
|
spyOn(IdentityStore, 'saveIdentity').andReturn(Promise.resolve());
|
|
});
|
|
it('returns the identity as null if it looks blank', () => {
|
|
IdentityStore._identity = null;
|
|
expect(IdentityStore.identity()).toBe(null);
|
|
IdentityStore._identity = {};
|
|
expect(IdentityStore.identity()).toBe(null);
|
|
IdentityStore._identity = { token: 'bad' };
|
|
expect(IdentityStore.identity()).toBe(null);
|
|
});
|
|
|
|
it('returns a proper clone of the identity', () => {
|
|
IdentityStore._identity = { id: 'bar', deep: { obj: 'baz' } };
|
|
const ident = IdentityStore.identity();
|
|
IdentityStore._identity.deep.obj = 'changed';
|
|
expect(ident.deep.obj).toBe('baz');
|
|
});
|
|
});
|
|
|
|
describe('fetchIdentity', () => {
|
|
beforeEach(() => {
|
|
IdentityStore._identity = this.identityJSON;
|
|
spyOn(IdentityStore, 'saveIdentity');
|
|
spyOn(AppEnv, 'reportError');
|
|
spyOn(console, 'error');
|
|
});
|
|
|
|
it('saves the identity returned', async () => {
|
|
const resp = Utils.deepClone(this.identityJSON);
|
|
resp.featureUsage.feat.quota = 5;
|
|
spyOn(MailspringAPIRequest, 'makeRequest').andCallFake(() => {
|
|
return Promise.resolve(resp);
|
|
});
|
|
await IdentityStore.fetchIdentity();
|
|
expect(MailspringAPIRequest.makeRequest).toHaveBeenCalled();
|
|
const options = MailspringAPIRequest.makeRequest.calls[0].args[0];
|
|
expect(options.path).toEqual('/api/me');
|
|
expect(IdentityStore.saveIdentity).toHaveBeenCalled();
|
|
const newIdent = IdentityStore.saveIdentity.calls[0].args[0];
|
|
expect(newIdent.featureUsage.feat.quota).toBe(5);
|
|
expect(AppEnv.reportError).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('errors if the json is invalid', async () => {
|
|
spyOn(MailspringAPIRequest, 'makeRequest').andCallFake(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
await IdentityStore.fetchIdentity();
|
|
expect(AppEnv.reportError).toHaveBeenCalled();
|
|
expect(IdentityStore.saveIdentity).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|