-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsm-github.spec.js
146 lines (117 loc) · 5.88 KB
/
dsm-github.spec.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
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
{
const should = require('should');
const sinon = require('sinon');
const assert = require('assert');
const fs = require('fs');
const dsmGithub = require('./dsm-github');
const util = require('./util');
_stubEventGetRequest = () => {
const request = require('es6-request');
const getStub = sinon.stub();
getStub.withArgs(`https://raw.githubusercontent.com/${process.env.GITHUB_USERNAME}/dsmwebcollective.github.io/1/_data/events.yml`)
.returns(new Promise((fulfill, reject) => {
fulfill([fs.readFileSync('./test_data/events1.yml')]);
}));
getStub.withArgs(`https://raw.githubusercontent.com/${process.env.GITHUB_USERNAME}/dsmwebcollective.github.io/2/_data/events.yml`)
.returns(new Promise((fulfill, reject) => {
fulfill([fs.readFileSync('./test_data/events2.yml')]);
}));
getStub.withArgs(`https://raw.githubusercontent.com/${process.env.GITHUB_USERNAME}/dsmwebcollective.github.io/3/_data/events.yml`)
.returns(new Promise((fulfill, reject) => {
fulfill([fs.readFileSync('./test_data/events3.yml')]);
}));
getStub.withArgs(`https://raw.githubusercontent.com/${process.env.GITHUB_USERNAME}/dsmwebcollective.github.io/4/_data/events.yml`)
.returns(new Promise((fulfill, reject) => {
fulfill([fs.readFileSync('./test_data/events4.yml')]);
}));
getStub.withArgs(`https://raw.githubusercontent.com/${process.env.GITHUB_USERNAME}/dsmwebcollective.github.io/5/_data/events.yml`)
.returns(new Promise((fulfill, reject) => {
fulfill([fs.readFileSync('./test_data/events5.yml')]);
}));
sinon.stub(request, "get", getStub);
};
describe('DSM Github helper', () => {
before(() => {
_stubEventGetRequest();
});
it('should correctly determine if two objects are equal', (done) => {
let obj1, obj2;
obj1 = { a: 1, b: 2, c: 3 };
obj2 = { a: 1, b: 2, c: 3 };
should(util.objectsAreEqual(obj1, obj2)).equal(true);
should(util.objectsAreEqual(obj2, obj1)).equal(true);
obj1 = { a: 1, b: 2 };
obj2 = { a: 1, b: 1 };
should(util.objectsAreEqual(obj1, obj2)).equal(false);
should(util.objectsAreEqual(obj2, obj1)).equal(false);
done();
});
it('should parse event yaml as expected', (done) => {
dsmGithub.event.getEntries('4')
.then((entries) => {
should(entries.length).equal(4);
for(let i = 0; i < entries.length; i++) {
const entry = entries[i];
entry.should.have.property('title', ['A', 'B', 'C', 'D'][i]);
entry.should.have.property('group', 'Group who is hosting');
entry.should.have.property('location', 'Name of the location');
entry.should.have.property('details_url', 'URL to additional details');
entry.should.have.property('date', 'June 23');
entry.should.have.property('time', '5:00pm - 6:00pm');
}
done();
});
});
it('should return an array with one entry if one entry is added', (done) => {
dsmGithub.event.getNewEntries(1, 2)
.then((newEntries) => {
should(newEntries.length).equal(1);
const entry = newEntries[0];
entry.should.have.property('title', 'B');
entry.should.have.property('group', 'Group who is hosting');
entry.should.have.property('location', 'Name of the location');
entry.should.have.property('details_url', 'URL to additional details');
entry.should.have.property('date', 'June 23');
entry.should.have.property('time', '5:00pm - 6:00pm');
done();
});
});
it('should return an array with four entries if four entires are added', (done) => {
dsmGithub.event.getNewEntries(3, 4)
.then((newEntries) => {
should(newEntries.length).equal(4);
for(let i = 0; i < 4; i++) {
const entry = newEntries[i];
entry.should.have.property('title', ['A', 'B', 'C', 'D'][i]);
entry.should.have.property('group', 'Group who is hosting');
entry.should.have.property('location', 'Name of the location');
entry.should.have.property('details_url', 'URL to additional details');
entry.should.have.property('date', 'June 23');
entry.should.have.property('time', '5:00pm - 6:00pm');
}
done();
});
});
it('should return an array with zero entries if no entries were added', (done) => {
dsmGithub.event.getNewEntries(2, 1)
.then((newEntries) => {
should(newEntries.length).equal(0);
done();
});
});
it('should return an array with one entry if one entry is added and one is removed', (done) => {
dsmGithub.event.getNewEntries(1, 5)
.then((newEntries) => {
should(newEntries.length).equal(1);
const entry = newEntries[0];
entry.should.have.property('title', 'E');
entry.should.have.property('group', 'Group who is hosting');
entry.should.have.property('location', 'Name of the location');
entry.should.have.property('details_url', 'URL to additional details');
entry.should.have.property('date', 'June 23');
entry.should.have.property('time', '5:00pm - 6:00pm');
done();
});
});
});
}