-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.js
83 lines (70 loc) · 2.96 KB
/
tests.js
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
'use strict';
const assert = require('assert');
const whatsappParser = require('./index');
describe('the Whatsapp parser', () => {
describe('when the file does not exist', () => {
it('should return an empty list', () => {
whatsappParser
.parseFile('')
.then((messages) => {
assert.deepEqual(messages, []);
})
});
});
describe('parsing a single message', () => {
describe('the date', () => {
it('should return a Date object', () => {
let output = whatsappParser._parseLine('01-01-16 00:00:01: Niels Dequeker: Happy New Year!');
assert.deepEqual(output.date, new Date(2016, 0, 1, 0, 0, 1));
});
it('should allow the dd-mm-yy hh:mm:ss format', () => {
let output = whatsappParser._parseLine('30-01-16 12:51:20: Niels Dequeker: Test message content');
assert.deepEqual(output.date, new Date(2016, 0, 30, 12, 51, 20));
});
it('should allow the dd/mm/yy hh:mm:ss format', () => {
let output = whatsappParser._parseLine('30/01/16 12:51:20: Niels Dequeker: Test message content');
assert.deepEqual(output.date, new Date(2016, 0, 30, 12, 51, 20));
});
it('should allow the [dd/mm/yyyy, hh:mm:ss] format', () => {
let output = whatsappParser._parseLine('[30/01/2016, 12:51:20] Niels Dequeker: Test message content');
assert.deepEqual(output.date, new Date(2016, 0, 30, 12, 51, 20));
});
});
describe('the author', () => {
it('should return the author', () => {
let output = whatsappParser._parseLine('30/01/16 12:51:20: Niels Dequeker: Test message content');
assert.equal(output.author, 'Niels Dequeker');
});
});
describe('the content', () => {
it('should return the content', () => {
let output = whatsappParser._parseLine('30/01/16 12:51:20: Niels Dequeker: Test message content');
assert.equal(output.content, 'Test message content');
});
});
});
describe('parsing an announcement', () => {
it('should be ignored when adding a person', () => {
let output = whatsappParser._parseLine('06-01-16 12:29:41: Niels Dequeker heeft u toegevoegd');
assert.deepEqual(output, null);
});
it('should work when the owner changes the image of the group', () => {
let output = whatsappParser._parseLine('06-01-16 14:15:59: U hebt de groepsafbeelding gewijzigd');
assert.deepEqual(output, null);
});
it('should work when a member changes the image of the group', () => {
let output = whatsappParser._parseLine('09-01-16 09:13:34: Niels Dequeker heeft de groepsafbeelding gewijzigd');
assert.deepEqual(output, null);
});
});
describe('parsing multiple messages', () => {
it('should return the user messages', (done) => {
whatsappParser
.parseFile('./example-input.txt')
.then((messages) => {
assert.deepEqual(messages.length, 2);
done();
});
});
})
});