2016-12-06 04:16:53 +08:00
|
|
|
const LocalDatabaseConnector = require('../src/shared/local-database-connector');
|
|
|
|
const {parseFromImap} = require('../src/shared/message-factory');
|
2016-12-06 08:07:46 +08:00
|
|
|
const {forEachJSONFixture, ACCOUNT_ID} = require('./helpers');
|
2016-12-06 04:16:53 +08:00
|
|
|
|
|
|
|
describe('MessageFactory', function MessageFactorySpecs() {
|
|
|
|
beforeEach(() => {
|
|
|
|
waitsForPromise(async () => {
|
2016-12-06 08:07:46 +08:00
|
|
|
await LocalDatabaseConnector.ensureAccountDatabase(ACCOUNT_ID);
|
|
|
|
const db = await LocalDatabaseConnector.forAccount(ACCOUNT_ID);
|
2016-12-06 04:16:53 +08:00
|
|
|
const folder = await db.Folder.create({
|
|
|
|
id: 'test-folder-id',
|
2016-12-06 08:07:46 +08:00
|
|
|
accountId: ACCOUNT_ID,
|
2016-12-06 04:16:53 +08:00
|
|
|
version: 1,
|
|
|
|
name: 'Test Folder',
|
|
|
|
role: null,
|
|
|
|
});
|
2016-12-06 08:07:46 +08:00
|
|
|
this.options = { accountId: ACCOUNT_ID, db, folder };
|
2016-12-06 04:16:53 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-12-06 08:07:46 +08:00
|
|
|
afterEach(() => {
|
|
|
|
LocalDatabaseConnector.destroyAccountDatabase(ACCOUNT_ID)
|
|
|
|
})
|
2016-12-06 04:16:53 +08:00
|
|
|
|
2016-12-06 08:07:46 +08:00
|
|
|
describe("parseFromImap", () => {
|
|
|
|
forEachJSONFixture('MessageFactory/parseFromImap', (filename, json) => {
|
2016-12-06 04:16:53 +08:00
|
|
|
it(`should correctly build message properties for ${filename}`, () => {
|
2016-12-06 08:07:46 +08:00
|
|
|
const {imapMessage, desiredParts, result} = json;
|
2016-12-06 04:16:53 +08:00
|
|
|
|
|
|
|
waitsForPromise(async () => {
|
|
|
|
const actual = await parseFromImap(imapMessage, desiredParts, this.options);
|
|
|
|
expect(actual).toEqual(result)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|