Skip to content

Commit

Permalink
Merge pull request linagora#67 from fvn-linagora/REQUIRE_BLOBID
Browse files Browse the repository at this point in the history
add required property 'blobId' to Message. Fixes linagora#65
  • Loading branch information
ddolcimascolo authored Sep 26, 2017
2 parents 493b413 + 40222c0 commit 9dd48c6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
8 changes: 6 additions & 2 deletions lib/models/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Message extends Model {
*
* @param jmap {Client} The {@link Client} instance that created this _Message_.
* @param id {String} The unique identifier of this _Message_.
* @param blobId {String} The identifier representing the raw [@!RFC5322] message.
* @param threadId {String} The unique identifier of the _Thread_ this _Message_ is in.
* @param mailboxIds {String[]} The array of _Mailbox_ identifiers this _Message_ is present into.
* @param [opts] {Object} The optional properties of this _Message_.
Expand Down Expand Up @@ -44,16 +45,18 @@ export default class Message extends Model {
* @see Model
* @see EMailer
*/
constructor(jmap, id, threadId, mailboxIds, opts) {
constructor(jmap, id, blobId, threadId, mailboxIds, opts) {
super(jmap);

Utils.assertRequiredParameterIsPresent(id, 'id');
Utils.assertRequiredParameterIsPresent(blobId, 'blobId');
Utils.assertRequiredParameterIsPresent(threadId, 'threadId');
Utils.assertRequiredParameterIsArrayWithMinimumLength(mailboxIds, 'mailboxIds', 1);

opts = opts || {};

this.id = id;
this.blobId = blobId;
this.threadId = threadId;
this.mailboxIds = mailboxIds;
this.inReplyToMessageId = opts.inReplyToMessageId || null;
Expand Down Expand Up @@ -181,6 +184,7 @@ export default class Message extends Model {
* @param jmap {Client} The {@link Client} instance passed to the _Message_ constructor.
* @param object {Object} The JSON representation of the _Message_, as a Javascript object.
* @param object.id {Object} The identifier of the _Message_.
* @param object.blobId {String} The identifier representing the raw [@!RFC5322] message.
* @param object.threadId {String} The identifier of the thread the _Message_ is in.
* @param object.mailboxIds {String[]} The array of _Mailbox_ identifiers the _Message_ is present into.
*
Expand All @@ -189,6 +193,6 @@ export default class Message extends Model {
static fromJSONObject(jmap, object) {
Utils.assertRequiredParameterIsPresent(object, 'object');

return new Message(jmap, object.id, object.threadId, object.mailboxIds, object);
return new Message(jmap, object.id, object.blobId, object.threadId, object.mailboxIds, object);
}
}
26 changes: 18 additions & 8 deletions test/common/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,16 +953,19 @@ describe('The Client class', function() {
state: 'm815034',
list: [{
id: 'fm1u314',
blobId: '4f512aafed75e7fb',
threadId: '4f512aafed75e7fb',
mailboxIds: ['inbox']
},
{
id: 'fm1u312',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['inbox']
},
{
id: 'fm2u12',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['mailbox2']
}
Expand Down Expand Up @@ -1000,9 +1003,9 @@ describe('The Client class', function() {
new jmap.Thread(client, 'fed75e7fb4f512aa', { messageIds: ['fm1u312', 'fm2u12'] })
],
[
new jmap.Message(client, 'fm1u314', '4f512aafed75e7fb', ['inbox']),
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', ['inbox']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', ['mailbox2'])
new jmap.Message(client, 'fm1u314', '4f512aafed75e7fb', '4f512aafed75e7fb', ['inbox']),
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['inbox']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['mailbox2'])
]
]);

Expand Down Expand Up @@ -1133,6 +1136,7 @@ describe('The Client class', function() {
accountId: '[email protected]',
list: [{
id: 'fm1u314',
blobId: '4f512aafed75e7fb',
threadId: '4f512aafed75e7fb',
mailboxIds: ['inbox']
}],
Expand All @@ -1152,7 +1156,7 @@ describe('The Client class', function() {
.then(function(data) {
expect(data).to.deep.equal([
[new jmap.Thread(client, '4f512aafed75e7fb', { messageIds: ['fm1u314'] })],
[new jmap.Message(client, 'fm1u314', '4f512aafed75e7fb', ['inbox'])]
[new jmap.Message(client, 'fm1u314', '4f512aafed75e7fb', '4f512aafed75e7fb', ['inbox'])]
]);

done();
Expand Down Expand Up @@ -1242,11 +1246,13 @@ describe('The Client class', function() {
accountId: '[email protected]',
list: [{
id: 'fm1u312',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['mailbox1']
},
{
id: 'fm2u12',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['mailbox2']
}],
Expand All @@ -1261,8 +1267,8 @@ describe('The Client class', function() {
.getMessages({ ids: ['fm1u312', 'fm2u12'] })
.then(function(data) {
expect(data).to.deep.equal([
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', ['mailbox1']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', ['mailbox2'])
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['mailbox1']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['mailbox2'])
]);

done();
Expand All @@ -1276,18 +1282,22 @@ describe('The Client class', function() {
accountId: '[email protected]',
list: [{
id: 'fm1u312',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['mailbox1']
}, {
id: 'fm1azf52',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: null
}, {
id: 'fm2u12',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: ['mailbox2']
}, {
id: 'fm1ab32',
blobId: 'fed75e7fb4f512aa',
threadId: 'fed75e7fb4f512aa',
mailboxIds: []
}],
Expand All @@ -1302,8 +1312,8 @@ describe('The Client class', function() {
.getMessages({ ids: ['fm1u312', 'fm2u12'] })
.then(function(data) {
expect(data).to.deep.equal([
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', ['mailbox1']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', ['mailbox2'])
new jmap.Message(client, 'fm1u312', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['mailbox1']),
new jmap.Message(client, 'fm2u12', 'fed75e7fb4f512aa', 'fed75e7fb4f512aa', ['mailbox2'])
]);

done();
Expand Down
Loading

0 comments on commit 9dd48c6

Please sign in to comment.