3 var assert = require('assert');
4 var underTest = require('../lib/notification-message-generator');
6 describe('notification-message-generator', function() {
7 it('should generate message for the simple case', function() {
8 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
9 { id: '00001', text: 'Yo', fromUser: { displayName: 'Mike Bartlett ' } }
12 assert.equal(message, 'gitterHQ/gitter-webapp \nMike Bartlett: Yo');
15 it('should should not repeat usernames', function() {
16 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
17 { id: '00001', text: 'Yo', fromUser: { displayName: 'Mike Bartlett ' } },
18 { id: '00001', text: 'Moo', fromUser: { displayName: 'Mike Bartlett ' } }
21 assert.equal(message, 'gitterHQ/gitter-webapp \nMike Bartlett: Yo \nMoo');
24 it('should generate a message for a one to one', function() {
26 id: '5395a3c7ade1b7aa68a08e6d',
27 name: 'Andy Trevorah',
29 userIds: ['535f8372096160afe0362eba', '538f52b7ade1b7aa68a08e68'],
34 id: '53b68c9b11e679b683873e12',
36 sent: '2014-07-04T11:14:35.188Z',
39 id: '535f8372096160afe0362eba',
41 displayName: 'Andy Trevorah'
46 // var smsLink = "http://localhost:5000/trevorah";
48 var message = underTest(troupe, items);
50 assert.equal(message, 'Andy Trevorah \ntest message');
53 it('should generate message for the double chat case', function() {
54 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
55 { id: '00001', text: 'Yo', fromUser: { displayName: 'Mike Bartlett ' } },
56 { id: '00002', text: 'Hey how are you?', fromUser: { displayName: 'Andrew Newdigate' } }
60 'gitterHQ/gitter-webapp \nMike Bartlett: Yo \nAndrew Newdigate: Hey how are you?'
64 it('should truncate really long lines', function() {
65 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
68 text: 'Hey I just wanted to run by those accounts figures with you',
69 fromUser: { displayName: 'Mahershalalhashbaz Smith' }
73 text: 'Why is your name so long?',
74 fromUser: { displayName: 'Andrew Newdigate' }
80 'gitterHQ/gitter-webapp \nMahershalalhashbaz Smith: Hey I just wanted to run by those accounts figures with you \nAndrew Newdigate: Why is your name so long?'
84 it('should handle really long content', function() {
85 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
86 { id: '00001', text: 'Freaky', fromUser: { displayName: 'Andrew Newdigate' } },
90 "This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something."
92 fromUser: { displayName: 'Mike Bartlett ' }
94 { id: '00005', text: 'Hey how are you?', fromUser: { displayName: 'Andrew Newdigate' } }
96 assert.strictEqual(message.length, 1024);
99 "gitterHQ/gitter-webapp \nAndrew Newdigate: Freaky \nMike Bartlett: This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say something.This is a fairly long message do you not thing. I think it is. I'm quite verbose sometimes when I want to say someth…"
103 it('should truncate a second line if it is huge', function() {
104 var text1 = Array(200).join('0123456789');
106 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
107 { id: '00003', text: Array(10).join('ABCDEFGHIJ') },
108 { id: '00001', text: text1 }
110 assert.equal(message.length, 1024);
112 it('should truncate a single line if it is huge', function() {
113 var text1 = Array(200).join('0123456789');
115 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
116 { id: '00001', text: text1 },
117 { id: '00003', text: Array(10).join('ABCDEFGHIJ') },
118 { id: '00005', text: 'Hey how are you?', fromUser: { displayName: 'Andrew Newdigate' } }
120 assert.equal(message.length, 1024);
123 it('should not make the second line too short', function() {
124 var text1 = Array(100).join('0123456789');
125 assert.strictEqual(text1.length, 990);
127 var message = underTest({ uri: 'gitterHQ/gitter-webapp' }, [
128 { id: '00001', text: text1 },
129 { id: '00003', text: Array(10).join('ABCDEFGHIJ') },
130 { id: '00005', text: 'Hey how are you?', fromUser: { displayName: 'Andrew Newdigate' } }
132 assert(message.length < 1024);
133 assert.equal(message, 'gitterHQ/gitter-webapp \n' + text1);