-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconferences.test.js
242 lines (201 loc) · 7.35 KB
/
conferences.test.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
const path = require('path');
const glob = require('glob');
const LANGS = require('./iso-639-1');
const COUNTRIES = require('./countries');
const {
getJSON,
INFO_STATUS_COMPLETE,
INFO_STATUS_INCOMPLETE,
REGEX_ID_YOUTUBE_CHANNEL,
REGEX_URL_YOUTUBE_PLAYLIST,
REGEX_URL_YOUTUBE,
REGEX_URL_VIMEO,
} = require('../js/utils/utils-node');
// Common
const REGEX_FILENAME = /^[0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z0-9-]+\.yaml$/;
const REGEX_URL = /^http[s]?:\/\/[a-z0-9-\.]+\.[a-z]{2,}/;
// Conference info
const INFO_ROOT_KEYS = ['name', 'status', 'series', 'tags', 'links', 'date', 'location', 'description'];
const INFO_STATUS_VALUES = [INFO_STATUS_COMPLETE, INFO_STATUS_INCOMPLETE];
const INFO_TAGS_VALUES = [
'android',
'angular',
'css',
'design',
'devops',
'ember',
'flutter',
'general',
'graphql',
'ios',
'java',
'javascript',
'laravel',
'machinelearning',
'management',
'mobile',
'node',
'react',
'reactnative',
'performance',
'php',
'python',
'reason',
'ruby',
'rust',
'security',
'swift',
'testing',
'typescript',
'vue',
'web',
];
const INFO_LINKS_KEYS = ['playlist', 'twitter', 'youtube', 'website'];
const INFO_DATE_KEYS = ['from', 'to'];
const INFO_LOCATION_KEYS = ['country', 'city'];
// Conference talk
const TALK_ROOT_KEYS = ['title', 'lang', 'type', 'time', 'authors', 'slides', 'videos', 'description'];
const TALK_AUTHOR_KEYS = ['name', 'twitter', 'github', 'website'];
const TALK_TYPES = ['regular', 'lightning', 'workshop'];
let year;
let testGlob = './data/conferences/*/*.yaml';
// Single file test?
let testFile = process.argv.pop();
if (testFile.match(REGEX_FILENAME) !== null) {
year = testFile.substr(0, 4);
testGlob = `./data/conferences/${year}/${testFile}`;
}
glob.sync(testGlob).forEach(file => {
let data = getJSON(file);
let conference = data.conference;
let talks = data.talks;
// Conference file tests
describe(`Conference file: ${file}`, () => {
it('has filename in correct format and lowercase', () => {
let filename = path.basename(file);
expect(filename.match(REGEX_FILENAME)).not.toBeNull();
});
});
// Conference info
describe(`Conference info: ${file}`, () => {
it('contains all fields in correct order', () => {
expect(Object.keys(conference)).toEqual(INFO_ROOT_KEYS);
});
// Status
it('contains valid status', () => {
expect(INFO_STATUS_VALUES).toContain(conference.status);
});
// Series
it('contains valid series', () => {
expect(conference.series).not.toBeNull();
});
// Tags
it('contains valid tags', () => {
expect(conference.tags.length).toBe(3);
conference.tags.forEach(tag => {
tag && expect(INFO_TAGS_VALUES).toContain(tag);
});
});
// Link
it('contains link entry with all fields in correct order', () => {
expect(Object.keys(conference.links)).toEqual(INFO_LINKS_KEYS);
});
it('contains valid playlist URL', () => {
conference.links.playlist && expect(conference.links.playlist.match(REGEX_URL)).not.toBeNull();
conference.links.playlist && conference.links.playlist.includes('www.youtube.com') && expect(conference.links.playlist.match(REGEX_URL_YOUTUBE_PLAYLIST)).not.toBeNull();
});
it('contains valid Twitter account ID', () => {
conference.links.twitter && expect(conference.links.twitter.includes('@')).toEqual(false);
conference.links.twitter && expect(conference.links.twitter.includes('http')).toEqual(false);
});
it('contains valid YouTube channel ID', () => {
conference.links.youtube && expect(conference.links.youtube.match(REGEX_ID_YOUTUBE_CHANNEL)).not.toBeNull();
});
it('contains valid website URL', () => {
conference.links.website && expect(conference.links.website.match(REGEX_URL)).not.toBeNull();
});
// Date
it('contains date entry with all fields in correct order', () => {
expect(Object.keys(conference.date)).toEqual(INFO_DATE_KEYS);
conference.location && expect(Object.keys(conference.location)).toEqual(INFO_LOCATION_KEYS);
});
it('contains valid date from/to', () => {
[conference.date.from, conference.date.to].forEach(date => {
expect(date).toBeInstanceOf(Date);
expect(typeof date.getFullYear()).toBe('number');
});
});
// Location
it('contains valid country and city', () => {
conference.location && expect(COUNTRIES).toContain(conference.location.country);
conference.location && expect(typeof conference.location.country).toBe('string');
conference.location && expect(typeof conference.location.city).toBe('string');
});
// Description
it('contains description on one line only if any', () => {
expect(conference.description.includes('\n')).toEqual(false);
});
});
// Conference talks tests
conference.status === INFO_STATUS_COMPLETE && talks.forEach(talk => {
describe(`Conference talk: ${file} - "${talk.title}"`, () => {
it('contains all fields in correct order', () => {
expect(Object.keys(talk)).toEqual(TALK_ROOT_KEYS);
});
it('contains valid lang', () => {
expect(typeof talk.lang).toBe('string');
expect(talk.lang).toHaveLength(2);
expect(LANGS).toContain(talk.lang);
});
it('contains valid type', () => {
expect(TALK_TYPES).toContain(talk.type);
});
it('contains valid time', () => {
expect(talk.time).toBeInstanceOf(Date);
expect(typeof talk.time.getFullYear()).toBe('number');
});
it('contains all authors fields in correct order if any', () => {
talk.authors && talk.authors.forEach(author => {
expect(Object.keys(author)).toEqual(TALK_AUTHOR_KEYS);
});
});
it('has valid authors entries if any', () => {
talk.authors && talk.authors.forEach(author => {
expect(typeof author.name).toBe('string');
author.twitter && expect(author.twitter.includes('@')).toEqual(false);
author.twitter && expect(author.twitter.includes('http')).toEqual(false);
author.github && expect(author.github.includes('@')).toEqual(false);
author.github && expect(author.github.includes('http')).toEqual(false);
author.website && expect(author.website.match(REGEX_URL)).not.toBeNull();
});
});
it('contains slides URLs starting with http(s) if any', () => {
talk.slides && talk.slides.map(url => {
expect(url.match(REGEX_URL)).not.toBeNull();
});
});
it('contains video URLs starting with http(s) if any', () => {
talk.videos && talk.videos.map(url => {
expect(url.match(REGEX_URL)).not.toBeNull();
});
});
it(`contains YouTube video URLs in format: ${REGEX_URL_YOUTUBE}`, () => {
talk.videos && talk.videos.map(url => {
if (url.includes('youtu')) {
expect(url.match(REGEX_URL_YOUTUBE)).not.toBeNull();
}
});
});
it(`contains Vimeo video URLs in format: ${REGEX_URL_VIMEO}`, () => {
talk.videos && talk.videos.map(url => {
if (url.includes('vimeo')) {
expect(url.match(REGEX_URL_VIMEO)).not.toBeNull();
}
});
});
it('contains description on one line only if any', () => {
talk.description && expect(talk.description.includes('\n')).toEqual(false);
});
});
});
});