2016-12-06 04:16:53 +08:00
|
|
|
/* eslint global-require: 0 */
|
|
|
|
/* eslint import/no-dynamic-require: 0 */
|
2017-01-07 06:28:28 +08:00
|
|
|
const detectThread = require('../src/message-processor/detect-thread');
|
2016-12-06 07:00:21 +08:00
|
|
|
const LocalDatabaseConnector = require('../src/shared/local-database-connector');
|
|
|
|
|
2016-12-06 08:07:46 +08:00
|
|
|
const {FIXTURES_PATH, ACCOUNT_ID} = require('./helpers')
|
2016-12-06 07:00:21 +08:00
|
|
|
|
|
|
|
function messagesFromFixture({Message}, folder, name) {
|
|
|
|
const {A, B} = require(`${FIXTURES_PATH}/Threading/${name}`)
|
|
|
|
|
|
|
|
const msgA = Message.build(A);
|
|
|
|
msgA.folder = folder;
|
|
|
|
msgA.labels = [];
|
|
|
|
|
|
|
|
const msgB = Message.build(B);
|
|
|
|
msgB.folder = folder;
|
|
|
|
msgB.labels = [];
|
|
|
|
|
|
|
|
return {msgA, msgB};
|
|
|
|
}
|
|
|
|
|
2016-12-14 04:27:42 +08:00
|
|
|
xdescribe('threading', function threadingSpecs() {
|
2016-12-06 07:00:21 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
waitsForPromise({timeout: 1000}, async () => {
|
|
|
|
await LocalDatabaseConnector.ensureAccountDatabase(ACCOUNT_ID);
|
|
|
|
this.db = await LocalDatabaseConnector.forAccount(ACCOUNT_ID);
|
|
|
|
this.folder = await this.db.Folder.create({
|
|
|
|
id: 'test-folder-id',
|
|
|
|
accountId: ACCOUNT_ID,
|
|
|
|
version: 1,
|
|
|
|
name: 'Test Folder',
|
|
|
|
role: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
LocalDatabaseConnector.destroyAccountDatabase(ACCOUNT_ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("when remote thread ids are present", () => {
|
|
|
|
it('threads emails with the same gthreadid', () => {
|
|
|
|
waitsForPromise(async () => {
|
|
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'remote-thread-id-yes');
|
|
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
|
|
expect(threadB.id).toEqual(threadA.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not thread other emails', () => {
|
|
|
|
waitsForPromise(async () => {
|
|
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'remote-thread-id-no');
|
|
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
|
|
expect(threadB.id).not.toEqual(threadA.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("when subject matching", () => {
|
|
|
|
it('threads emails with the same subject', () => {
|
|
|
|
waitsForPromise(async () => {
|
|
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'subject-matching-yes');
|
|
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
|
|
expect(threadB.id).toEqual(threadA.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not thread other emails', () => {
|
|
|
|
waitsForPromise(async () => {
|
|
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'subject-matching-no');
|
|
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
|
|
expect(threadB.id).not.toEqual(threadA.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-12-06 04:16:53 +08:00
|
|
|
});
|