1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/* global expect */
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define([
'replybuilder',
'models/message',
'models/folder',
'models/account',
'backbone'
], function(ReplyBuilder, Message, Folder, Account, Backbone) {
describe('ReplyBuilder', function() {
var message, messageBody, folder, account;
beforeEach(function() {
message = new Message();
messageBody = new Backbone.Model();
folder = new Folder();
account = new Account();
account.addFolder(folder);
folder.addMessage(message);
});
var createAddress = function(addr) {
return {
label: addr,
email: addr
};
};
var setEmail = function(message, address) {
message.folder.account.set('emailAddress', address.email);
};
var assertSameAddressList = function(l1, l2) {
var rawL1 = l1.map(function(a) {
return a.email;
});
var rawL2 = l2.map(function(a) {
return a.email;
});
rawL1.sort();
rawL2.sort();
expect(rawL1).toEqual(rawL2);
};
// b -> a to a -as b
it('handles a one-on-one reply', function() {
var a = createAddress('a@domain.tld');
var b = createAddress('b@domain.tld');
messageBody.set('from', [b]);
messageBody.set('to', [a]);
messageBody.set('cc', []);
setEmail(message, a);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [a]);
assertSameAddressList(reply.to, [b]);
assertSameAddressList(reply.cc, []);
});
it('handles simple group reply', function() {
var a = createAddress('a@domain.tld');
var b = createAddress('b@domain.tld');
var c = createAddress('c@domain.tld');
messageBody.set('from', [a]);
messageBody.set('to', [b, c]);
messageBody.set('cc', []);
setEmail(message, b);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [b]);
assertSameAddressList(reply.to, [a, c]);
assertSameAddressList(reply.cc, []);
});
it('handles group reply with CC', function() {
var a = createAddress('a@domain.tld');
var b = createAddress('b@domain.tld');
var c = createAddress('c@domain.tld');
var d = createAddress('d@domain.tld');
messageBody.set('from', [a]);
messageBody.set('to', [b, c]);
messageBody.set('cc', [d]);
setEmail(message, b);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [b]);
assertSameAddressList(reply.to, [a, c]);
assertSameAddressList(reply.cc, [d]);
});
it('handles group reply of CC address', function() {
var a = createAddress('a@domain.tld');
var b = createAddress('b@domain.tld');
var c = createAddress('c@domain.tld');
var d = createAddress('d@domain.tld');
messageBody.set('from', [a]);
messageBody.set('to', [b, c]);
messageBody.set('cc', [d]);
setEmail(message, d);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [d]);
assertSameAddressList(reply.to, [a, b, c]);
assertSameAddressList(reply.cc, []);
});
it('handles group reply of CC address with many CCs', function() {
var a = createAddress('a@domain.tld');
var b = createAddress('b@domain.tld');
var c = createAddress('c@domain.tld');
var d = createAddress('d@domain.tld');
var e = createAddress('e@domain.tld');
messageBody.set('from', [a]);
messageBody.set('to', [b, c]);
messageBody.set('cc', [d, e]);
setEmail(message, e);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [e]);
assertSameAddressList(reply.to, [a, b, c]);
assertSameAddressList(reply.cc, [d]);
});
it('handles reply of message where the recipient is in the CC', function() {
var ali = createAddress('ali@domain.tld');
var bob = createAddress('bob@domain.tld');
var me = createAddress('c@domain.tld');
var dani = createAddress('d@domain.tld');
messageBody.set('from', [ali]);
messageBody.set('to', [bob]);
messageBody.set('cc', [me, dani]);
setEmail(message, me);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [me]);
assertSameAddressList(reply.to, [ali, bob]);
assertSameAddressList(reply.cc, [dani]);
});
it('handles jan\'s reply to nina\'s mesage to a mailing list', function() {
var nina = createAddress('nina@nc.com');
var list = createAddress('list@nc.com');
var jan = createAddress('jan@nc.com');
messageBody.set('from', [nina]);
messageBody.set('to', [list]);
messageBody.set('cc', []);
setEmail(message, jan);
var reply = ReplyBuilder.buildReply(message, messageBody);
assertSameAddressList(reply.from, [jan]);
assertSameAddressList(reply.to, [nina, list]);
assertSameAddressList(reply.cc, []);
});
});
});
|