1
0
mirror of https://github.com/moparisthebest/mail synced 2025-02-16 15:10:10 -05:00

fixed tests to work with new imap-client get message api

This commit is contained in:
Tankred Hase 2013-08-28 19:20:59 +02:00
parent 73d46bc72b
commit eec91acd7a
2 changed files with 28 additions and 26 deletions

View File

@ -257,7 +257,7 @@ define(function(require) {
var self = this,
expectedItems,
itemCounter = 0,
message, attachments = [];
message /*, attachments = []*/ ;
// validate options
if (!options.folder || !options.uid) {
@ -341,25 +341,25 @@ define(function(require) {
});
}
function attachmentReady(err, gottenAttachment) {
attachments.push(gottenAttachment);
itemCounter++;
check();
}
// function attachmentReady(err, gottenAttachment) {
// attachments.push(gottenAttachment);
// itemCounter++;
// check();
// }
function check() {
// go for another round you don't yet know how mich to fetch or you haven't fetch enough
if (!expectedItems || itemCounter < expectedItems) {
return;
}
// function check() {
// // go for another round you don't yet know how mich to fetch or you haven't fetch enough
// if (!expectedItems || itemCounter < expectedItems) {
// return;
// }
// overwrite attachments array with the uint8array variant
message.attachments = (attachments.length > 0) ? attachments : undefined;
// cache message object in memory
self.cacheItem(options.folder, message);
// // overwrite attachments array with the uint8array variant
// message.attachments = (attachments.length > 0) ? attachments : undefined;
// // cache message object in memory
// self.cacheItem(options.folder, message);
callback(null, message);
}
// callback(null, message);
// }
self._imapClient.getMessage({
path: options.folder,

View File

@ -257,7 +257,7 @@ define(function(require) {
});
});
describe('IMAP: get message content from', function() {
describe('IMAP: get message content', function() {
it('should fail due to bad options', function(done) {
emailDao.imapGetMessage({
folder: 'INBOX'
@ -271,8 +271,9 @@ define(function(require) {
it('should parse message body without attachement', function(done) {
var uid = 415;
imapClientStub.getMessage.yields(null, {
uid: uid
imapClientStub.getMessage.yieldsTo('onMessageBody', null, {
uid: uid,
body: ''
});
emailDao.imapGetMessage({
folder: 'INBOX',
@ -291,14 +292,15 @@ define(function(require) {
newImapClientStub = {
getMessage: function() {}
};
sinon.stub(newImapClientStub, 'getMessage', function(options, messageReady, attachmentReady) {
messageReady(null, {
sinon.stub(newImapClientStub, 'getMessage', function(options) {
options.onMessageBody(null, {
uid: uid,
body: '',
attachments: ['file.txt']
});
attachmentReady(null, {
uint8Array: new Uint8Array(42)
});
// options.onAttachment(null, {
// uint8Array: new Uint8Array(42)
// });
});
emailDao._imapClient = newImapClientStub;
@ -309,7 +311,7 @@ define(function(require) {
expect(newImapClientStub.getMessage.calledOnce).to.be.true;
expect(err).to.not.exist;
expect(message.uid).to.equal(uid);
expect(message.attachments[0].uint8Array).to.exist;
//expect(message.attachments[0].uint8Array).to.exist;
emailDao._imapClient = imapClientStub;
done();
});