node-csfd-api-racintom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintrc.json +33 -0
  3. package/.gitattributes +2 -0
  4. package/.github/FUNDING.yml +8 -0
  5. package/.github/pull_request_template.md +19 -0
  6. package/.github/workflows/main.yml +40 -0
  7. package/.github/workflows/publish.yml +73 -0
  8. package/.github/workflows/test.yml +43 -0
  9. package/.husky/pre-commit +1 -0
  10. package/.idea/codeStyles/Project.xml +72 -0
  11. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  12. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  13. package/.idea/misc.xml +6 -0
  14. package/.idea/modules.xml +8 -0
  15. package/.idea/node-csfd-api.iml +9 -0
  16. package/.idea/prettier.xml +6 -0
  17. package/.idea/vcs.xml +7 -0
  18. package/.nvmrc +1 -0
  19. package/.prettierignore +8 -0
  20. package/.prettierrc +10 -0
  21. package/.vscode/settings.json +16 -0
  22. package/Dockerfile +19 -0
  23. package/README.md +510 -0
  24. package/demo.ts +35 -0
  25. package/eslint.config.mjs +55 -0
  26. package/package.json +86 -0
  27. package/server.ts +66 -0
  28. package/src/fetchers/fetch.polyfill.ts +7 -0
  29. package/src/fetchers/index.ts +25 -0
  30. package/src/helpers/creator.helper.ts +95 -0
  31. package/src/helpers/global.helper.ts +70 -0
  32. package/src/helpers/movie.helper.ts +276 -0
  33. package/src/helpers/search-user.helper.ts +19 -0
  34. package/src/helpers/search.helper.ts +66 -0
  35. package/src/helpers/user-ratings.helper.ts +62 -0
  36. package/src/index.ts +42 -0
  37. package/src/interfaces/creator.interface.ts +14 -0
  38. package/src/interfaces/global.ts +36 -0
  39. package/src/interfaces/movie.interface.ts +157 -0
  40. package/src/interfaces/search.interface.ts +32 -0
  41. package/src/interfaces/user-ratings.interface.ts +21 -0
  42. package/src/services/creator.service.ts +34 -0
  43. package/src/services/movie.service.ts +89 -0
  44. package/src/services/search.service.ts +101 -0
  45. package/src/services/user-ratings.service.ts +106 -0
  46. package/src/vars.ts +13 -0
  47. package/tests/creator.test.ts +182 -0
  48. package/tests/fetchers.test.ts +109 -0
  49. package/tests/global.test.ts +35 -0
  50. package/tests/helpers.test.ts +59 -0
  51. package/tests/mocks/creator-actor.html.ts +2244 -0
  52. package/tests/mocks/creator-composer-empty.html.ts +683 -0
  53. package/tests/mocks/creator-director.html.ts +3407 -0
  54. package/tests/mocks/movie1.html.ts +1430 -0
  55. package/tests/mocks/movie2.html.ts +740 -0
  56. package/tests/mocks/movie3.html.ts +1843 -0
  57. package/tests/mocks/movie4.html.ts +1568 -0
  58. package/tests/mocks/search.html.ts +838 -0
  59. package/tests/mocks/series1.html.ts +1540 -0
  60. package/tests/mocks/userRatings.html.ts +1354 -0
  61. package/tests/movie.test.ts +606 -0
  62. package/tests/search.test.ts +379 -0
  63. package/tests/services.test.ts +106 -0
  64. package/tests/user-ratings.test.ts +142 -0
  65. package/tests/vars.test.ts +34 -0
  66. package/tsconfig.json +23 -0
  67. package/vitest.config.mts +10 -0
@@ -0,0 +1,379 @@
1
+ import { parse } from 'node-html-parser';
2
+ import { describe, expect, test } from 'vitest';
3
+ import { getAvatar, getUser, getUserRealName, getUserUrl } from '../src/helpers/search-user.helper';
4
+ import {
5
+ getColorRating,
6
+ getOrigins,
7
+ getPoster,
8
+ getTitle,
9
+ getType,
10
+ getUrl,
11
+ getYear,
12
+ parsePeople
13
+ } from '../src/helpers/search.helper';
14
+ import { CSFDColorRating, CSFDFilmTypes } from '../src/interfaces/global';
15
+ import { CSFDCreator } from '../src/interfaces/movie.interface';
16
+ import { searchMock } from './mocks/search.html';
17
+
18
+ const html = parse(searchMock);
19
+ const moviesNode = html.querySelectorAll('.main-movies article');
20
+ const usersNode = html.querySelectorAll('.main-users article');
21
+ const tvSeriesNode = html.querySelectorAll('.main-series article');
22
+
23
+ describe('Get Movie titles', () => {
24
+ test('First movie', () => {
25
+ const movie = getTitle(moviesNode[0]);
26
+ expect(movie).toEqual<string>('Matrix');
27
+ });
28
+ test('Last movie', () => {
29
+ const movie = getTitle(moviesNode[moviesNode.length - 1]);
30
+ expect(movie).toEqual<string>('Matrix hunter');
31
+ });
32
+ test('Some movie', () => {
33
+ const movie = getTitle(moviesNode[5]);
34
+ expect(movie).toEqual<string>('Matrix - Reloaded');
35
+ });
36
+ });
37
+
38
+ describe('Get Movie years', () => {
39
+ test('First movie', () => {
40
+ const movie = getYear(moviesNode[0]);
41
+ expect(movie).toEqual<number>(1999);
42
+ });
43
+ test('Last movie', () => {
44
+ const movie = getYear(moviesNode[moviesNode.length - 1]);
45
+ expect(movie).toEqual<number>(2004);
46
+ });
47
+ test('Some movie', () => {
48
+ const movie = getYear(moviesNode[3]);
49
+ expect(movie).toEqual<number>(2003);
50
+ });
51
+ });
52
+
53
+ describe('Get Movie url', () => {
54
+ test('First movie', () => {
55
+ const movie = getUrl(moviesNode[0]);
56
+ expect(movie).toEqual<string>('/film/9499-matrix/');
57
+ });
58
+ test('Last movie', () => {
59
+ const movie = getUrl(moviesNode[moviesNode.length - 1]);
60
+ expect(movie).toEqual<string>('/film/40940-matrix-hunter/');
61
+ });
62
+ test('Some movie', () => {
63
+ const movie = getUrl(moviesNode[4]);
64
+ expect(movie).toEqual<string>('/film/799868-matrix/');
65
+ });
66
+ });
67
+
68
+ describe('Get Movie types', () => {
69
+ test('First movie', () => {
70
+ const movie = getType(moviesNode[0]);
71
+ expect(movie).toEqual<CSFDFilmTypes>('film');
72
+ });
73
+ test('Last movie', () => {
74
+ const movie = getType(moviesNode[moviesNode.length - 1]);
75
+ expect(movie).toEqual<CSFDFilmTypes>('film');
76
+ });
77
+ test('Some movie', () => {
78
+ const movie = getType(moviesNode[1]);
79
+ expect(movie).toEqual<CSFDFilmTypes>('film');
80
+ });
81
+ });
82
+
83
+ describe('Get Movie colors', () => {
84
+ test('First movie', () => {
85
+ const movie = getColorRating(moviesNode[0]);
86
+ expect(movie).toEqual<CSFDColorRating>('good');
87
+ });
88
+ test('Last movie', () => {
89
+ const movie = getColorRating(moviesNode[moviesNode.length - 1]);
90
+ expect(movie).toEqual<CSFDColorRating>('average');
91
+ });
92
+ test('Some movie', () => {
93
+ const movie = getColorRating(moviesNode[4]);
94
+ expect(movie).toEqual<CSFDColorRating>('unknown');
95
+ });
96
+ });
97
+
98
+ describe('Get Movie posters', () => {
99
+ test('First movie', () => {
100
+ const movie = getPoster(moviesNode[0]);
101
+ expect(movie).toEqual<string>(
102
+ 'https://image.pmgstatic.com/cache/resized/w60h85/files/images/film/posters/000/008/8959_164d69.jpg'
103
+ );
104
+ });
105
+ test('Empty poster', () => {
106
+ const movie = getPoster(moviesNode[4]);
107
+ expect(movie).toEqual<string>(
108
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
109
+ );
110
+ });
111
+ test('Some movie', () => {
112
+ const movie = getPoster(moviesNode[1]);
113
+ expect(movie).toEqual<string>(
114
+ 'https://image.pmgstatic.com/cache/resized/w60h85/files/images/film/posters/165/852/165852808_71b2e1.jpg'
115
+ );
116
+ });
117
+ });
118
+
119
+ describe('Get Movie origins', () => {
120
+ test('First movie', () => {
121
+ const movie = getOrigins(moviesNode[0]);
122
+ expect(movie).toEqual<string[]>(['USA']);
123
+ });
124
+ test('Second movie', () => {
125
+ const movie = getOrigins(moviesNode[1]);
126
+ expect(movie).toEqual<string[]>(['USA']);
127
+ });
128
+ test('Third movie', () => {
129
+ const movie = getOrigins(moviesNode[2]);
130
+ expect(movie).toEqual<string[]>(['USA', 'Austrálie']);
131
+ });
132
+ test('Some movie', () => {
133
+ const movie = getOrigins(moviesNode[4]);
134
+ expect(movie).toEqual<string[]>(['Slovensko']);
135
+ });
136
+ });
137
+
138
+ describe('Get Movie creators', () => {
139
+ test('First movie directors', () => {
140
+ const movie = parsePeople(moviesNode[0], 'directors');
141
+ expect(movie).toEqual<CSFDCreator[]>([
142
+ {
143
+ id: 3112,
144
+ name: 'Lilly Wachowski',
145
+ url: 'https://www.csfd.cz/tvurce/3112-lilly-wachowski/'
146
+ },
147
+ {
148
+ id: 3113,
149
+ name: 'Lana Wachowski',
150
+ url: 'https://www.csfd.cz/tvurce/3113-lana-wachowski/'
151
+ }
152
+ ]);
153
+ });
154
+ test('Last movie actors', () => {
155
+ const movie = parsePeople(moviesNode[moviesNode.length - 1], 'actors');
156
+ expect(movie).toEqual<CSFDCreator[]>([
157
+ {
158
+ id: 67747,
159
+ name: "Genevieve O'Reilly",
160
+ url: 'https://www.csfd.cz/tvurce/67747-genevieve-o-reilly/'
161
+ },
162
+ {
163
+ id: 294809,
164
+ name: 'Luoyong Wang',
165
+ url: 'https://www.csfd.cz/tvurce/294809-luoyong-wang/'
166
+ }
167
+ ]);
168
+ });
169
+ test('Empty actors', () => {
170
+ const movie = parsePeople(moviesNode[5], 'actors');
171
+ expect(movie).toEqual<CSFDCreator[]>([]);
172
+ });
173
+ });
174
+
175
+ // TV SERIES
176
+
177
+ describe('Get TV series titles', () => {
178
+ test('First TV series', () => {
179
+ const movie = getTitle(tvSeriesNode[0]);
180
+ expect(movie).toEqual<string>('Matrix');
181
+ });
182
+ test('Last TV series', () => {
183
+ const movie = getTitle(tvSeriesNode[tvSeriesNode.length - 1]);
184
+ expect(movie).toEqual<string>('Futurama - Skoro poslední přání');
185
+ });
186
+ test('Some TV series', () => {
187
+ const movie = getTitle(tvSeriesNode[5]);
188
+ expect(movie).toEqual<string>('MP4orce - Dungeon Matrix');
189
+ });
190
+ });
191
+
192
+ describe('Get TV series years', () => {
193
+ test('First TV series', () => {
194
+ const movie = getYear(tvSeriesNode[0]);
195
+ expect(movie).toEqual<number>(1993);
196
+ });
197
+ test('Last TV series', () => {
198
+ const movie = getYear(tvSeriesNode[tvSeriesNode.length - 1]);
199
+ expect(movie).toEqual<number>(2012);
200
+ });
201
+ test('Some TV series', () => {
202
+ const movie = getYear(tvSeriesNode[4]);
203
+ expect(movie).toEqual<number>(2020);
204
+ });
205
+ });
206
+
207
+ describe('Get TV series url', () => {
208
+ test('First TV series', () => {
209
+ const movie = getUrl(tvSeriesNode[0]);
210
+ expect(movie).toEqual<string>('/film/72014-matrix/');
211
+ });
212
+ test('Last TV series', () => {
213
+ const movie = getUrl(tvSeriesNode[tvSeriesNode.length - 1]);
214
+ expect(movie).toEqual<string>('/film/77748-futurama/483972-skoro-posledni-prani/');
215
+ });
216
+ test('Some TV series', () => {
217
+ const movie = getUrl(tvSeriesNode[4]);
218
+ expect(movie).toEqual<string>('/film/999565-escape-the-matrix/');
219
+ });
220
+ });
221
+
222
+ describe('Get TV series types', () => {
223
+ test('First TV series', () => {
224
+ const movie = getType(tvSeriesNode[0]);
225
+ expect(movie).toEqual<CSFDFilmTypes>('seriál');
226
+ });
227
+ test('Last TV series', () => {
228
+ const movie = getType(tvSeriesNode[tvSeriesNode.length - 1]);
229
+ expect(movie).toEqual<CSFDFilmTypes>('epizoda');
230
+ });
231
+ test('Some TV series', () => {
232
+ const movie = getType(tvSeriesNode[1]);
233
+ expect(movie).toEqual<CSFDFilmTypes>('epizoda');
234
+ });
235
+ });
236
+
237
+ describe('Get TV series colors', () => {
238
+ test('First TV series', () => {
239
+ const movie = getColorRating(tvSeriesNode[0]);
240
+ expect(movie).toEqual<CSFDColorRating>('good');
241
+ });
242
+ test('Last TV series', () => {
243
+ const movie = getColorRating(tvSeriesNode[3]);
244
+ expect(movie).toEqual<CSFDColorRating>('average');
245
+ });
246
+ test('Some TV series', () => {
247
+ const movie = getColorRating(tvSeriesNode[5]);
248
+ expect(movie).toEqual<CSFDColorRating>('unknown');
249
+ });
250
+ });
251
+
252
+ describe('Get TV series posters', () => {
253
+ test('Some TV series', () => {
254
+ const movie = getPoster(tvSeriesNode[2]);
255
+ expect(movie).toEqual<string>(
256
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
257
+ );
258
+ });
259
+ test('Empty poster', () => {
260
+ const movie = getPoster(tvSeriesNode[4]);
261
+ expect(movie).toEqual<string>(
262
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
263
+ );
264
+ });
265
+ });
266
+
267
+ describe('Get TV series origins', () => {
268
+ test('First TV series', () => {
269
+ const movie = getOrigins(tvSeriesNode[0]);
270
+ expect(movie).toEqual<string[]>(['Kanada']);
271
+ });
272
+ test('Second TV series', () => {
273
+ const movie = getOrigins(tvSeriesNode[1]);
274
+ expect(movie).toEqual<string[]>(['Česko']);
275
+ });
276
+ test('Third TV series', () => {
277
+ const movie = getOrigins(tvSeriesNode[2]);
278
+ expect(movie).toEqual<string[]>(['USA', 'Kanada']);
279
+ });
280
+ test('Some TV series', () => {
281
+ const movie = getOrigins(tvSeriesNode[4]);
282
+ expect(movie).toEqual<string[]>(['Velká Británie']);
283
+ });
284
+ });
285
+
286
+ describe('Get TV series creators', () => {
287
+ test('First TV series directors', () => {
288
+ const movie = parsePeople(tvSeriesNode[0], 'directors');
289
+ expect(movie).toEqual<CSFDCreator[]>([
290
+ {
291
+ id: 8877,
292
+ name: 'Allan Eastman',
293
+ url: 'https://www.csfd.cz/tvurce/8877-allan-eastman/'
294
+ },
295
+ {
296
+ id: 8686,
297
+ name: 'Mario Azzopardi',
298
+ url: 'https://www.csfd.cz/tvurce/8686-mario-azzopardi/'
299
+ }
300
+ ]);
301
+ });
302
+ test('Last TV series actors', () => {
303
+ const movie = parsePeople(tvSeriesNode[tvSeriesNode.length - 1], 'actors');
304
+ expect(movie).toEqual<CSFDCreator[]>([
305
+ {
306
+ id: 20335,
307
+ name: 'Billy West',
308
+ url: 'https://www.csfd.cz/tvurce/20335-billy-west/'
309
+ },
310
+ {
311
+ id: 1931,
312
+ name: 'Katey Sagal',
313
+ url: 'https://www.csfd.cz/tvurce/1931-katey-sagal/'
314
+ }
315
+ ]);
316
+ });
317
+ test('Empty actors', () => {
318
+ const movie = parsePeople(tvSeriesNode[5], 'actors');
319
+ expect(movie).toEqual<CSFDCreator[]>([]);
320
+ });
321
+ test('Empty directors + some actors', () => {
322
+ const movie = parsePeople(tvSeriesNode[4], 'actors');
323
+ const movieDirectors = parsePeople(tvSeriesNode[4], 'directors');
324
+ expect(movie).toEqual<CSFDCreator[]>([
325
+ {
326
+ id: 61834,
327
+ name: 'David Icke',
328
+ url: 'https://www.csfd.cz/tvurce/61834-david-icke/'
329
+ }
330
+ ]);
331
+ expect(movieDirectors).toEqual<CSFDCreator[]>([]);
332
+ });
333
+ });
334
+
335
+ // USERS
336
+
337
+ describe('Get Users name', () => {
338
+ test('First user', () => {
339
+ const movie = getUser(usersNode[0]);
340
+ expect(movie).toEqual<string>('Matrix44');
341
+ });
342
+ test('Last user', () => {
343
+ const movie = getUser(usersNode[usersNode.length - 1]);
344
+ expect(movie).toEqual<string>('Atrix');
345
+ });
346
+ });
347
+
348
+ describe('Get Users real name', () => {
349
+ test('First user', () => {
350
+ const movie = getUserRealName(usersNode[0]);
351
+ expect(movie).toEqual<string>('Matrix 44');
352
+ });
353
+ test('Some name (nothing)', () => {
354
+ const movie = getUserRealName(usersNode[3]);
355
+ expect(movie).toEqual(null);
356
+ });
357
+ });
358
+
359
+ describe('Get Users avatar', () => {
360
+ test('First user', () => {
361
+ const movie = getAvatar(usersNode[0]);
362
+ expect(movie).toEqual<string>(
363
+ 'https://image.pmgstatic.com/cache/resized/w45h60crop/files/images/user/avatars/000/327/327230_b48a6e.jpg'
364
+ );
365
+ });
366
+ test('Some name (nothing)', () => {
367
+ const movie = getAvatar(usersNode[3]);
368
+ expect(movie).toEqual<string>(
369
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
370
+ );
371
+ });
372
+ });
373
+
374
+ describe('Get Users url', () => {
375
+ test('First user', () => {
376
+ const movie = getUserUrl(usersNode[0]);
377
+ expect(movie).toEqual<string>('/uzivatel/100416-matrix44/');
378
+ });
379
+ });
@@ -0,0 +1,106 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { CSFDUserRatings } from '../src/interfaces/user-ratings.interface';
3
+ import { UserRatingsScraper } from '../src/services/user-ratings.service';
4
+
5
+ // Live API tests
6
+ const USER = 912;
7
+ const USER2 = 228645;
8
+
9
+ describe('Simple call', () => {
10
+ // Fetch data with excludes
11
+ const userRatingsScraper = new UserRatingsScraper();
12
+ const res: Promise<CSFDUserRatings[]> = userRatingsScraper.userRatings(USER);
13
+
14
+ test('Should have some movies', async () => {
15
+ const results = await res;
16
+
17
+ const films = results.filter((item) => item.type === 'film');
18
+ expect(films.length).toBeGreaterThan(10);
19
+ });
20
+ });
21
+
22
+ describe('AllPages', async () => {
23
+ const userRatingsScraper = new UserRatingsScraper();
24
+ const res: Promise<CSFDUserRatings[]> = userRatingsScraper.userRatings(USER2, {
25
+ allPages: true,
26
+ allPagesDelay: 100
27
+ });
28
+
29
+ test('Should have exact number of movies', async () => {
30
+ const results = await res;
31
+ expect(results.length).toBeCloseTo(181);
32
+ });
33
+ });
34
+
35
+ describe('Filter out episodes, TV Series and Seasons', () => {
36
+ // Fetch data with excludes
37
+ const userRatingsScraper = new UserRatingsScraper();
38
+ const resExcluded: Promise<CSFDUserRatings[]> = userRatingsScraper.userRatings(USER, {
39
+ excludes: ['epizoda', 'seriál', 'série']
40
+ });
41
+
42
+ test('Should not have any episode', async () => {
43
+ const results = await resExcluded;
44
+
45
+ const episodes = results.filter((item) => item.type === 'epizoda');
46
+ expect(episodes.length).toBe<number>(0);
47
+ });
48
+ test('Should not have any TV series', async () => {
49
+ const results = await resExcluded;
50
+ const tvSeries = results.filter((item) => item.type === 'seriál');
51
+ expect(tvSeries.length).toBe<number>(0);
52
+ });
53
+ test('Should not have any Season', async () => {
54
+ const results = await resExcluded;
55
+ const season = results.filter((item) => item.type === 'série');
56
+ expect(season.length).toBe<number>(0);
57
+ });
58
+ });
59
+
60
+ describe('Includes only TV series or Episodes or something...', () => {
61
+ // Fetch data with excludes
62
+ const userRatingsScraper = new UserRatingsScraper();
63
+ const resIncluded: Promise<CSFDUserRatings[]> = userRatingsScraper.userRatings(USER, {
64
+ includesOnly: ['série']
65
+ });
66
+
67
+ test('Should not have any film', async () => {
68
+ const results = await resIncluded;
69
+
70
+ const films = results.filter((item) => item.type === 'film');
71
+ expect(films.length).toBe<number>(0);
72
+ });
73
+ test('Should have some season', async () => {
74
+ const results = await resIncluded;
75
+ console.log(results);
76
+
77
+ const tvSeries = results.filter((item) => item.type === 'série');
78
+ expect(tvSeries.length).toBeGreaterThan(0);
79
+ });
80
+ test('Should have only TV series', async () => {
81
+ const results = await resIncluded;
82
+
83
+ const tvSeries = results.filter((item) => item.type === 'série');
84
+ expect(tvSeries.length).toBe(results.length);
85
+ });
86
+ });
87
+
88
+ describe('Exclude + includes together', () => {
89
+ // Fetch data with excludes + includes
90
+ const userRatingsScraper = new UserRatingsScraper();
91
+ const resBoth: Promise<CSFDUserRatings[]> = userRatingsScraper.userRatings(USER, {
92
+ includesOnly: ['seriál'],
93
+ excludes: ['film']
94
+ });
95
+
96
+ test('Should have warning', () => {
97
+ expect(console.warn).toHaveBeenCalled;
98
+ });
99
+
100
+ test('Should use includesOnly', async () => {
101
+ const results = await resBoth;
102
+
103
+ const tvSeries = results.filter((item) => item.type === 'seriál');
104
+ expect(tvSeries.length).toBe<number>(results.length);
105
+ });
106
+ });
@@ -0,0 +1,142 @@
1
+ import { HTMLElement, parse } from 'node-html-parser';
2
+ import { describe, expect, test } from 'vitest';
3
+ import {
4
+ getColorRating,
5
+ getDate,
6
+ getId,
7
+ getTitle,
8
+ getType,
9
+ getUrl,
10
+ getUserRating,
11
+ getYear
12
+ } from '../src/helpers/user-ratings.helper';
13
+ import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../src/interfaces/global';
14
+ import { userRatingsMock } from './mocks/userRatings.html';
15
+
16
+ const items = parse(userRatingsMock);
17
+ const movies: HTMLElement[] = items.querySelectorAll('.box-user-rating .table-container tbody tr');
18
+
19
+ describe('Get Ratings', () => {
20
+ test('First rating', () => {
21
+ const movie = getUserRating(movies[0]);
22
+ expect(movie).toEqual<CSFDStars>(4);
23
+ });
24
+ test('Last rating', () => {
25
+ const movie = getUserRating(movies[movies.length - 1]);
26
+ expect(movie).toEqual<CSFDStars>(3);
27
+ });
28
+ // TODO
29
+ // test('Zero Rating', () => {
30
+ // const movie = getUserRating(movies[5]);
31
+ // expect(movie).toEqual<CSFDStars>(0);
32
+ // });
33
+ });
34
+
35
+ describe('Get ID', () => {
36
+ test('First ID', () => {
37
+ const movie = getId(movies[0]);
38
+ expect(movie).toEqual<number>(1254361);
39
+ });
40
+ test('Last ID', () => {
41
+ const movie = getId(movies[movies.length - 1]);
42
+ expect(movie).toEqual<number>(1169425);
43
+ });
44
+ });
45
+
46
+ describe('Get type', () => {
47
+ test('Film', () => {
48
+ const movie = getType(movies[0]);
49
+ expect(movie).toEqual<CSFDFilmTypes>('film');
50
+ });
51
+ test('TV series', () => {
52
+ const movie = getType(movies[23]);
53
+ expect(movie).toEqual<CSFDFilmTypes>('seriál');
54
+ });
55
+ test('Episode', () => {
56
+ const movie = getType(movies[4]);
57
+ expect(movie).toEqual<CSFDFilmTypes>('epizoda');
58
+ });
59
+ // test('TV film', () => {
60
+ // const movie = getType(movies[18]);
61
+ // expect(movie).toEqual<CSFDFilmTypes>('TV film');
62
+ // });
63
+ // test('Pořad', () => {
64
+ // const movie = getType(movies[6]);
65
+ // expect(movie).toEqual<CSFDFilmTypes>('pořad');
66
+ // });
67
+ test('Amateur film', () => {
68
+ const movie = getType(movies[31]);
69
+ expect(movie).toEqual<CSFDFilmTypes>('amatérský film');
70
+ });
71
+ test('Season', () => {
72
+ const movie = getType(movies[11]);
73
+ expect(movie).toEqual<CSFDFilmTypes>('série');
74
+ });
75
+ });
76
+
77
+ describe('Get title', () => {
78
+ test('First title', () => {
79
+ const movie = getTitle(movies[0]);
80
+ expect(movie).toEqual<string>('Stutz');
81
+ });
82
+ test('Last title', () => {
83
+ const movie = getTitle(movies[movies.length - 1]);
84
+ expect(movie).toEqual<string>('Kouření způsobuje kašel');
85
+ });
86
+ });
87
+
88
+ describe('Get year', () => {
89
+ test('First year', () => {
90
+ const movie = getYear(movies[0]);
91
+ expect(movie).toEqual<number>(2022);
92
+ });
93
+ test('Some year', () => {
94
+ const movie = getYear(movies[7]);
95
+ expect(movie).toEqual<number>(2016);
96
+ });
97
+ test('Almost last year', () => {
98
+ const movie = getYear(movies[movies.length - 7]);
99
+ expect(movie).toEqual<number>(2000);
100
+ });
101
+ });
102
+
103
+ describe('Get color rating', () => {
104
+ // test('Black', () => {
105
+ // const movie = getColorRating(movies[7]);
106
+ // expect(movie).toEqual<CSFDColorRating>('bad');
107
+ // });
108
+ // test('Gray', () => {
109
+ // const movie = getColorRating(movies[29]);
110
+ // expect(movie).toEqual<CSFDColorRating>('unknown');
111
+ // });
112
+ test('Blue', () => {
113
+ const movie = getColorRating(movies[3]);
114
+ expect(movie).toEqual<CSFDColorRating>('average');
115
+ });
116
+ test('Red', () => {
117
+ const movie = getColorRating(movies[1]);
118
+ expect(movie).toEqual<CSFDColorRating>('good');
119
+ });
120
+ });
121
+
122
+ describe('Get date', () => {
123
+ test('First date', () => {
124
+ const movie = getDate(movies[0]);
125
+ expect(movie).toEqual<string>('16.12.2022');
126
+ });
127
+ test('Last date', () => {
128
+ const movie = getDate(movies[movies.length - 1]);
129
+ expect(movie).toEqual<string>('05.07.2022');
130
+ });
131
+ });
132
+
133
+ describe('Get Url', () => {
134
+ test('First url', () => {
135
+ const movie = getUrl(movies[0]);
136
+ expect(movie).toEqual<string>('https://www.csfd.cz/film/1254361-stutz/');
137
+ });
138
+ test('Last url', () => {
139
+ const movie = getUrl(movies[movies.length - 1]);
140
+ expect(movie).toEqual<string>('https://www.csfd.cz/film/1169425-koureni-zpusobuje-kasel/');
141
+ });
142
+ });
@@ -0,0 +1,34 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { creatorUrl, movieUrl, searchUrl, userRatingsUrl } from '../src/vars';
3
+
4
+ describe('Vars User Ratings', () => {
5
+ test('Assemble User rating url', () => {
6
+ const url = userRatingsUrl('912-bart');
7
+ expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');
8
+ });
9
+ test('Assemble User rating. Page 2', () => {
10
+ const url = userRatingsUrl('912-bart', 2);
11
+ expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/?page=2');
12
+ });
13
+ });
14
+
15
+ describe('Vars Movies', () => {
16
+ test('Assemble movieUrl', () => {
17
+ const url = movieUrl(535121);
18
+ expect(url).toBe('https://www.csfd.cz/film/535121/prehled/');
19
+ });
20
+ });
21
+
22
+ describe('Vars Search', () => {
23
+ test('Assemble searchUrl', () => {
24
+ const url = searchUrl('matrix');
25
+ expect(url).toBe('https://www.csfd.cz/hledat/?q=matrix');
26
+ });
27
+ });
28
+
29
+ describe('Vars Creator', () => {
30
+ test('Assemble creatorUrl', () => {
31
+ const url = creatorUrl('1');
32
+ expect(url).toBe('https://www.csfd.cz/tvurce/1');
33
+ });
34
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2017",
4
+ "lib": ["dom"],
5
+ "types": ["node"],
6
+ "baseUrl": "./src",
7
+ "esModuleInterop": true,
8
+ "module": "commonjs",
9
+ "strictNullChecks": false,
10
+ "sourceMap": false,
11
+ "outDir": "./dist",
12
+ "strict": true,
13
+ "declaration": true,
14
+ "pretty": true,
15
+ "skipLibCheck": true,
16
+ "resolveJsonModule": true,
17
+ "alwaysStrict": true,
18
+ "noImplicitAny": true,
19
+ "noImplicitReturns": true
20
+ },
21
+ "include": ["src"],
22
+ "exclude": ["dist/**/*", "*/tests/**/*"]
23
+ }
@@ -0,0 +1,10 @@
1
+ import { configDefaults, defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ coverage: {
6
+ provider: 'istanbul',
7
+ exclude: [...configDefaults.exclude, 'demo.ts', '**/*.polyfill.ts', 'vars.ts']
8
+ }
9
+ }
10
+ });