2016-12-06 08:07:46 +08:00
|
|
|
|
2017-01-16 06:09:05 +08:00
|
|
|
const FetchFolderList = require('../../src/local-sync-worker/sync-tasks/fetch-folder-list.imap.es6');
|
2016-12-06 08:07:46 +08:00
|
|
|
const LocalDatabaseConnector = require('../../src/shared/local-database-connector');
|
|
|
|
const {forEachJSONFixture, ACCOUNT_ID, silentLogger} = require('../helpers');
|
|
|
|
|
2016-12-14 04:27:42 +08:00
|
|
|
xdescribe("FetchFolderList", function FetchFolderListSpecs() {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await LocalDatabaseConnector.ensureAccountDatabase(ACCOUNT_ID);
|
|
|
|
this.db = await LocalDatabaseConnector.forAccount(ACCOUNT_ID);
|
|
|
|
|
|
|
|
this.stubImapBoxes = null;
|
|
|
|
this.imap = {
|
|
|
|
getBoxes: () => {
|
|
|
|
return Promise.resolve(this.stubImapBoxes);
|
|
|
|
},
|
|
|
|
};
|
2016-12-06 08:07:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
LocalDatabaseConnector.destroyAccountDatabase(ACCOUNT_ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("initial syncing", () => {
|
|
|
|
forEachJSONFixture('FetchFolderList', (filename, json) => {
|
2016-12-14 04:27:42 +08:00
|
|
|
it(`should create folders and labels correctly for boxes (${filename})`, async () => {
|
|
|
|
const {boxes, expectedFolders, expectedLabels} = json;
|
|
|
|
const provider = filename.split('-')[0];
|
|
|
|
this.stubImapBoxes = boxes;
|
2016-12-06 08:07:46 +08:00
|
|
|
|
2016-12-14 04:27:42 +08:00
|
|
|
const task = new FetchFolderList(provider, silentLogger);
|
|
|
|
await task.run(this.db, this.imap);
|
2016-12-06 08:07:46 +08:00
|
|
|
|
2016-12-14 04:27:42 +08:00
|
|
|
const folders = await this.db.Folder.findAll();
|
|
|
|
expect(folders.map((f) => { return {name: f.name, role: f.role} })).toEqual(expectedFolders);
|
2016-12-06 08:07:46 +08:00
|
|
|
|
2016-12-14 04:27:42 +08:00
|
|
|
const labels = await this.db.Label.findAll();
|
|
|
|
expect(labels.map(f => { return {name: f.name, role: f.role} })).toEqual(expectedLabels);
|
2016-12-06 08:07:46 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|