-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcompute-group-data.js
216 lines (197 loc) · 5.2 KB
/
compute-group-data.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* Tests the Group data wrangler
*/
/* global describe, it */
const {computeGroupData} = require("../lib/compute-group-data");
const assert = require("assert");
const baseCgData = [
{
id: 42,
name: "test group",
type: "community group",
shortname: "test",
_links : { homepage: { href: "https://example.com" } }
},
[], // WG repository data
[{title: "Standing Couch"}], // chairs
[], // activity data
[{
// this will be used as the default creation date in many tests,
// so mock activity needs to be later
created: "2023-08-14T15:44:00",
_links: { user: { href: 'https://example.test/user-id' } }
}] // participants
];
describe('The Group data wrangler', function () {
it('observes start date of the group', () => {
const testData = structuredClone(baseCgData);
testData[0]["start-date"] = "2011-05-05";
const cgData = computeGroupData(testData, []);
assert.equal(cgData.created, new Date("2011-05-05").toString());
});
it('assumes start date from first participant join date when start-date not set', () => {
const testData = structuredClone(baseCgData);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.created, new Date("2023-08-14T15:44:00Z").toString());
});
it('calculates number of participants', () => {
const testData = structuredClone(baseCgData);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.participants, 1);
});
it('lists staff in the group with their picture', () => {
const testData = structuredClone(baseCgData);
const cgData = computeGroupData(testData, [{
name: "Stick Cane",
_links: {
self: {
href: 'https://example.test/user-id'
},
photos: [
{
name: "tiny",
href: "https://example.test/user.jpg"
}
]
}
}]);
assert.equal(cgData.staff.length, 1);
assert.equal(cgData.staff[0].name, "Stick Cane");
assert.equal(cgData.staff[0].photo, "https://example.test/user.jpg");
});
it('compiles mailing list activity data', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "lists",
},
"data": {
"2023-10": 3,
"2023-11": 1
}
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.lists["2023-10"], 3);
});
it('reports errors gotten from fetching mailing list activity data', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "lists",
},
"data": [],
"error": "Failed to fetch mailing list data"
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.lists.errors[0], "Failed to fetch mailing list data");
});
it('compiles forum activity data', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "forum"
},
"data": {
"items": [
{
"created_at": "2023-10-19T19:05:56.303Z",
"topic_title": "Test Oct 1"
},
{
"created_at": "2023-10-20T19:05:56.303Z",
"topic_title": "Test Oct 2"
},
{
"created_at": "2023-11-19T19:05:56.303Z",
"topic_title": "Test Nov"
}
]
}
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.lists["2023-10"], 2);
assert.equal(cgData.activity.lists["2023-11"], 1);
});
it('compiles repo activity data (CG mode)', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "repository"
},
"data": {
"items": [
{
"created_at": "2023-10-19T19:05:56.303Z",
}
]
}
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.repository["2023-10"], 1);
});
it('compiles repo activity data (WG mode)', () => {
const testData = structuredClone(baseCgData);
testData[1].push(
{
items: [
{
"created_at": "2023-10-19T19:05:56.303Z",
}
]
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.repository["2023-10"], 1);
});
it('compiles wiki activity data', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "wiki"
},
"data": {
"items": [
{
"isoDate": "2023-10-18T10:02:10.000Z"
}
]
}
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.wiki["2023-10"], 1);
});
it('compiles blog activity data', () => {
const testData = structuredClone(baseCgData);
testData[3].push(
{
"service": {
"type": "rss"
},
"data": {
"items": [
{
"isoDate": "2023-10-18T10:02:10.000Z"
}
]
}
}
);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.rss["2023-10"], 1);
});
it('compiles join activity data', () => {
const testData = structuredClone(baseCgData);
const cgData = computeGroupData(testData, []);
assert.equal(cgData.activity.join["2023-08"], 1);
});
});