node-csfd-api-racintom 1.4.0 → 1.5.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 (111) hide show
  1. package/fetchers/fetch.polyfill.d.ts +1 -0
  2. package/fetchers/fetch.polyfill.js +9 -0
  3. package/fetchers/index.d.ts +1 -0
  4. package/fetchers/index.js +27 -0
  5. package/helpers/creator.helper.d.ts +17 -0
  6. package/helpers/creator.helper.js +87 -0
  7. package/helpers/global.helper.d.ts +17 -0
  8. package/helpers/global.helper.js +68 -0
  9. package/helpers/movie.helper.d.ts +26 -0
  10. package/helpers/movie.helper.js +270 -0
  11. package/helpers/search-user.helper.d.ts +5 -0
  12. package/helpers/search-user.helper.js +22 -0
  13. package/helpers/search.helper.d.ts +11 -0
  14. package/helpers/search.helper.js +62 -0
  15. package/helpers/user-ratings.helper.d.ts +13 -0
  16. package/helpers/user-ratings.helper.js +61 -0
  17. package/index.d.ts +24 -0
  18. package/index.js +39 -0
  19. package/interfaces/creator.interface.d.ts +12 -0
  20. package/interfaces/creator.interface.js +2 -0
  21. package/interfaces/global.d.ts +22 -0
  22. package/interfaces/global.js +2 -0
  23. package/interfaces/movie.interface.d.ts +73 -0
  24. package/interfaces/movie.interface.js +2 -0
  25. package/interfaces/search.interface.d.ts +27 -0
  26. package/interfaces/search.interface.js +2 -0
  27. package/interfaces/season.interface.d.ts +11 -0
  28. package/interfaces/season.interface.js +2 -0
  29. package/interfaces/user-ratings.interface.d.ts +18 -0
  30. package/interfaces/user-ratings.interface.js +2 -0
  31. package/package.json +62 -86
  32. package/services/creator.service.d.ts +6 -0
  33. package/services/creator.service.js +32 -0
  34. package/services/movie.service.d.ts +6 -0
  35. package/services/movie.service.js +59 -0
  36. package/services/search.service.d.ts +5 -0
  37. package/services/search.service.js +80 -0
  38. package/services/season.service.d.ts +9 -0
  39. package/services/season.service.js +42 -0
  40. package/services/user-ratings.service.d.ts +7 -0
  41. package/services/user-ratings.service.js +84 -0
  42. package/vars.d.ts +5 -0
  43. package/vars.js +13 -0
  44. package/.editorconfig +0 -13
  45. package/.eslintrc.json +0 -33
  46. package/.gitattributes +0 -2
  47. package/.github/FUNDING.yml +0 -8
  48. package/.github/pull_request_template.md +0 -19
  49. package/.github/workflows/main.yml +0 -40
  50. package/.github/workflows/publish.yml +0 -73
  51. package/.github/workflows/test.yml +0 -43
  52. package/.husky/pre-commit +0 -1
  53. package/.idea/codeStyles/Project.xml +0 -72
  54. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  55. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  56. package/.idea/misc.xml +0 -6
  57. package/.idea/modules.xml +0 -8
  58. package/.idea/node-csfd-api.iml +0 -9
  59. package/.idea/prettier.xml +0 -6
  60. package/.idea/vcs.xml +0 -7
  61. package/.nvmrc +0 -1
  62. package/.prettierignore +0 -8
  63. package/.prettierrc +0 -10
  64. package/.vscode/settings.json +0 -16
  65. package/Dockerfile +0 -19
  66. package/demo.ts +0 -35
  67. package/eslint.config.mjs +0 -55
  68. package/server.ts +0 -66
  69. package/src/fetchers/fetch.polyfill.ts +0 -7
  70. package/src/fetchers/index.ts +0 -25
  71. package/src/helpers/creator.helper.ts +0 -95
  72. package/src/helpers/global.helper.ts +0 -70
  73. package/src/helpers/movie.helper.ts +0 -276
  74. package/src/helpers/search-user.helper.ts +0 -19
  75. package/src/helpers/search.helper.ts +0 -66
  76. package/src/helpers/user-ratings.helper.ts +0 -62
  77. package/src/index.ts +0 -50
  78. package/src/interfaces/creator.interface.ts +0 -14
  79. package/src/interfaces/global.ts +0 -36
  80. package/src/interfaces/movie.interface.ts +0 -157
  81. package/src/interfaces/search.interface.ts +0 -32
  82. package/src/interfaces/season.interface.ts +0 -12
  83. package/src/interfaces/user-ratings.interface.ts +0 -21
  84. package/src/services/creator.service.ts +0 -34
  85. package/src/services/movie.service.ts +0 -89
  86. package/src/services/search.service.ts +0 -101
  87. package/src/services/season.service.ts +0 -55
  88. package/src/services/user-ratings.service.ts +0 -106
  89. package/src/vars.ts +0 -16
  90. package/tests/creator.test.ts +0 -182
  91. package/tests/fetchers.test.ts +0 -109
  92. package/tests/global.test.ts +0 -35
  93. package/tests/helpers.test.ts +0 -59
  94. package/tests/mocks/creator-actor.html.ts +0 -2244
  95. package/tests/mocks/creator-composer-empty.html.ts +0 -683
  96. package/tests/mocks/creator-director.html.ts +0 -3407
  97. package/tests/mocks/movie1.html.ts +0 -1430
  98. package/tests/mocks/movie2.html.ts +0 -740
  99. package/tests/mocks/movie3.html.ts +0 -1843
  100. package/tests/mocks/movie4.html.ts +0 -1568
  101. package/tests/mocks/search.html.ts +0 -838
  102. package/tests/mocks/series1.html.ts +0 -1540
  103. package/tests/mocks/userRatings.html.ts +0 -1354
  104. package/tests/movie.test.ts +0 -606
  105. package/tests/search.test.ts +0 -379
  106. package/tests/season.test.ts +0 -115
  107. package/tests/services.test.ts +0 -106
  108. package/tests/user-ratings.test.ts +0 -142
  109. package/tests/vars.test.ts +0 -34
  110. package/tsconfig.json +0 -23
  111. package/vitest.config.mts +0 -10
@@ -1,55 +0,0 @@
1
- import { fetchPage } from '../fetchers';
2
- import { HTMLElement, parse } from 'node-html-parser';
3
- import { seasonUrl } from '../vars';
4
- import { EpisodeInfo, Season } from '../interfaces/season.interface';
5
-
6
- export class SeasonScraper {
7
- public async season(url: string): Promise<Season> {
8
- const response = await fetchPage(seasonUrl(url));
9
-
10
- const seasonHtml = parse(response);
11
-
12
- const movieNode = seasonHtml.querySelector('.main-movie-profile');
13
-
14
- return this.buildSeason(movieNode);
15
- }
16
-
17
- private buildSeason(
18
- movieNode: HTMLElement
19
- ): Season {
20
- return {
21
- origin: this.getOriginFromHtml(movieNode),
22
- description: this.getDescriptionFromHtml(movieNode),
23
- thumbnail: this.getThumbnailFromHtml(movieNode),
24
- episodeList: this.getEpisodeListFromHtml(movieNode),
25
- }
26
- }
27
-
28
- private getOriginFromHtml(movieNode: HTMLElement): string {
29
- return movieNode.querySelector('.film-info-content .origin').textContent;
30
- }
31
-
32
- private getDescriptionFromHtml(movieNode: HTMLElement): string {
33
- return movieNode.querySelector('.plot-full').textContent;
34
- }
35
-
36
- private getThumbnailFromHtml(movieNode: HTMLElement): string {
37
- return movieNode.querySelector('.film-posters img').getAttribute('src');
38
- }
39
-
40
- private getEpisodeListFromHtml(movieNode: HTMLElement): EpisodeInfo[] {
41
- return movieNode.querySelectorAll('.film-episodes-list li').map(container => {
42
- const nameContainer = container.querySelector('.film-title-name')
43
-
44
- return {
45
- name: nameContainer.textContent,
46
- seasonEpisodeIdentifier: container.querySelector('.film-title-info').textContent,
47
- linkToDetail: nameContainer.getAttribute('href'),
48
- }
49
- })
50
- }
51
-
52
-
53
-
54
- }
55
-
@@ -1,106 +0,0 @@
1
- import { HTMLElement, parse } from 'node-html-parser';
2
- import { fetchPage } from '../fetchers';
3
- import {
4
- getColorRating,
5
- getDate,
6
- getId,
7
- getTitle,
8
- getType,
9
- getUrl,
10
- getUserRating,
11
- getYear,
12
- sleep
13
- } from '../helpers/user-ratings.helper';
14
- import { CSFDColorRating, CSFDStars } from '../interfaces/global';
15
- import { CSFDUserRatingConfig, CSFDUserRatings } from '../interfaces/user-ratings.interface';
16
- import { userRatingsUrl } from '../vars';
17
-
18
- export class UserRatingsScraper {
19
- private films: CSFDUserRatings[] = [];
20
-
21
- public async userRatings(
22
- user: string | number,
23
- config?: CSFDUserRatingConfig
24
- ): Promise<CSFDUserRatings[]> {
25
- let allMovies: CSFDUserRatings[] = [];
26
- const url = userRatingsUrl(user);
27
- const response = await fetchPage(url);
28
-
29
- const items = parse(response);
30
- const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
31
-
32
- // Get number of pages
33
- const pagesNode = items.querySelector('.pagination');
34
- const pages = +pagesNode?.childNodes[pagesNode.childNodes.length - 4].rawText || 1;
35
-
36
- allMovies = this.getPage(config, movies);
37
-
38
- if (config?.allPages) {
39
- console.log('User', user, url);
40
- console.log('Fetching all pages', pages);
41
- for (let i = 2; i <= pages; i++) {
42
- console.log('Fetching page', i, 'out of', pages, '...');
43
- const url = userRatingsUrl(user, i);
44
- const response = await fetchPage(url);
45
-
46
- const items = parse(response);
47
- const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
48
- allMovies = [...this.getPage(config, movies)];
49
-
50
- // Sleep
51
- if (config.allPagesDelay) {
52
- await sleep(config.allPagesDelay);
53
- }
54
- }
55
- return allMovies;
56
- }
57
-
58
- return allMovies;
59
- }
60
-
61
- private getPage(config: CSFDUserRatingConfig, movies: HTMLElement[]) {
62
- if (config) {
63
- if (config.includesOnly?.length && config.excludes?.length) {
64
- console.warn(
65
- `node-csfd-api:
66
- You can not use both parameters 'includesOnly' and 'excludes'.
67
- Parameter 'includesOnly' will be used now:`,
68
- config.includesOnly
69
- );
70
- }
71
- }
72
-
73
- for (const el of movies) {
74
- const type = getType(el);
75
-
76
- // Filtering includesOnly
77
- if (config?.includesOnly?.length) {
78
- if (config.includesOnly.some((include) => type === include)) {
79
- this.buildUserRatings(el);
80
- }
81
- // Filter exludes
82
- } else if (config?.excludes?.length) {
83
- if (!config.excludes.some((exclude) => type === exclude)) {
84
- this.buildUserRatings(el);
85
- }
86
- } else {
87
- // Without filtering
88
- this.buildUserRatings(el);
89
- }
90
- }
91
- return this.films;
92
- }
93
-
94
- private buildUserRatings(el: HTMLElement) {
95
- this.films.push({
96
- id: getId(el),
97
- title: getTitle(el),
98
- year: getYear(el),
99
- type: getType(el),
100
- url: getUrl(el),
101
- colorRating: getColorRating(el) as CSFDColorRating,
102
- userDate: getDate(el),
103
- userRating: getUserRating(el) as CSFDStars
104
- });
105
- }
106
- }
package/src/vars.ts DELETED
@@ -1,16 +0,0 @@
1
- export const userRatingsUrl = (user: string | number, page?: number): string =>
2
- `https://www.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/${
3
- page ? '?page=' + page : ''
4
- }`;
5
-
6
- export const movieUrl = (movie: number): string =>
7
- `https://www.csfd.cz/film/${encodeURIComponent(movie)}/prehled/`;
8
-
9
- export const creatorUrl = (creator: number | string): string =>
10
- `https://www.csfd.cz/tvurce/${encodeURIComponent(creator)}`;
11
-
12
- export const searchUrl = (text: string): string =>
13
- `https://www.csfd.cz/hledat/?q=${encodeURIComponent(text)}`;
14
-
15
- export const seasonUrl = (url: string): string =>
16
- `https://www.csfd.cz/${url}`;
@@ -1,182 +0,0 @@
1
- import { parse } from 'node-html-parser';
2
- import { describe, expect, test } from 'vitest';
3
- import {
4
- getBio,
5
- getBirthdayInfo,
6
- getFilms,
7
- getName,
8
- getPhoto
9
- } from '../src/helpers/creator.helper';
10
- import { CSFDCreatorScreening } from '../src/interfaces/creator.interface';
11
- import { actorMock } from './mocks/creator-actor.html';
12
- import { composerMock } from './mocks/creator-composer-empty.html';
13
- import { directorMock } from './mocks/creator-director.html';
14
-
15
- const html = parse(directorMock);
16
- const asideNode = html.querySelector('.creator-about');
17
- const filmsNode = html.querySelector('.creator-filmography');
18
-
19
- const htmlActor = parse(actorMock);
20
- const asideNodeActor = htmlActor.querySelector('.creator-about');
21
- const filmsNodeActor = htmlActor.querySelector('.creator-filmography');
22
-
23
- const htmlComposer = parse(composerMock);
24
- const asideNodeComposer = htmlComposer.querySelector('.creator-about');
25
- const filmsNodeComposer = htmlComposer.querySelector('.creator-filmography');
26
-
27
- describe('Creator info', () => {
28
- test('Name', () => {
29
- const creator = getName(asideNode);
30
- expect(creator).toEqual<string>('Quentin Tarantino');
31
- });
32
-
33
- test('Bio', () => {
34
- const creator = getBio(asideNode);
35
- expect(creator).toEqual<string>(
36
- 'Narodil se teprve šestnáctileté Connii McHugh, která mu dala křestní jméno podle své oblíbené postavy Quinta ze seriálu Gunsmoke. Jeho biologickým otcem byl jistý Tony Tarantino, který rodinu opustil když byl Quentin ještě malinký a nikdy o syna nejevil zájem (přesněji řečeno jen do doby, než se potomek stal slavným – pak se na jeho úspěchu pokoušel parazitovat). Jeho náhradním tatínkem se stal hudebník s československými kořeny, který si Connii vzal a Quentina…'
37
- );
38
- });
39
-
40
- test('Photo', () => {
41
- const creator = getPhoto(asideNode);
42
- expect(creator).toEqual<string>(
43
- 'https://image.pmgstatic.com/cache/resized/w100h132crop/files/images/creator/photos/164/515/164515525_b98f8a.jpg'
44
- );
45
- });
46
- });
47
-
48
- describe('Creator birthday info', () => {
49
- test('Birthday', () => {
50
- const creator = getBirthdayInfo(asideNode)?.birthday;
51
- expect(creator).toEqual<string>('27.03.1963');
52
- });
53
-
54
- test('Birthplace', () => {
55
- const creator = getBirthdayInfo(asideNode)?.birthPlace;
56
- expect(creator).toEqual<string>('Knoxville, Tennessee, USA');
57
- });
58
-
59
- test('Age', () => {
60
- const creator = getBirthdayInfo(asideNode)?.age;
61
- expect(creator).toEqual<number>(61);
62
- });
63
- });
64
-
65
- describe("Creator's films", () => {
66
- test('First film from first section', () => {
67
- const films = getFilms(filmsNode) as CSFDCreatorScreening[];
68
- expect(films[0].title).toEqual<string>('The Movie Critic');
69
- });
70
-
71
- test('Last film from first section', () => {
72
- const films = getFilms(filmsNode) as CSFDCreatorScreening[];
73
- expect(films[films.length - 1].id).toEqual<number>(1051715);
74
- });
75
-
76
- test('Year second movie', () => {
77
- const films = getFilms(filmsNode) as CSFDCreatorScreening[];
78
- expect(films[1].year).toEqual<number>(2019);
79
- });
80
- });
81
-
82
- // actor
83
-
84
- describe('Actor info', () => {
85
- test('Name', () => {
86
- const creator = getName(asideNodeActor);
87
- expect(creator).toEqual<string>('Mads Mikkelsen');
88
- });
89
-
90
- test('Bio', () => {
91
- const creator = getBio(asideNodeActor);
92
- expect(creator).toEqual<string>(
93
- 'Dánský herec, celým jménem Mads Dittmann Mikkelsen, se narodil v roce 1965 v kodaňské čtvrti Østerbro. Dříve než se vrhl na hereckou dráhu, pracoval 8 let jako profesionální tanečník. Herecké vzdělání získal Mikkelsen na herecké škole při divadle v Århusu. Školu zakončil v roce 1996. Co se týká soukromého života je Mads Mikkelsen, který za svůj nejoblíbenější film považuje Taxikáře od Martina Scorseseho, od roku 1987 ženatý s dánskou choreografkou Hanne Jacobsen.…'
94
- );
95
- });
96
-
97
- test('Photo', () => {
98
- const creator = getPhoto(asideNodeActor);
99
- expect(creator).toEqual<string>(
100
- 'https://image.pmgstatic.com/cache/resized/w100h132crop/files/images/creator/photos/166/233/166233274_298dbd.jpg'
101
- );
102
- });
103
- });
104
-
105
- describe('Actor birthday info', () => {
106
- test('Birthday', () => {
107
- const creator = getBirthdayInfo(asideNodeActor)?.birthday;
108
- expect(creator).toEqual<string>('22.11.1965');
109
- });
110
-
111
- test('Birthplace', () => {
112
- const creator = getBirthdayInfo(asideNodeActor)?.birthPlace;
113
- expect(creator).toEqual<string>('Østerbro, København, Dánsko');
114
- });
115
-
116
- test('Age', () => {
117
- const creator = getBirthdayInfo(asideNodeActor)?.age;
118
- expect(creator).toEqual<number>(58);
119
- });
120
- });
121
-
122
- describe("Creator's films", () => {
123
- test('First film from first section', () => {
124
- const films = getFilms(filmsNodeActor) as CSFDCreatorScreening[];
125
- expect(films[0].title).toEqual<string>('The Billion Dollar Spy');
126
- });
127
-
128
- test('Last film from first section', () => {
129
- const films = getFilms(filmsNodeActor) as CSFDCreatorScreening[];
130
- expect(films[films.length - 1].id).toEqual<number>(88874);
131
- });
132
-
133
- test('Year second movie', () => {
134
- const films = getFilms(filmsNodeActor) as CSFDCreatorScreening[];
135
- expect(films[1].year).toEqual<number>(2025);
136
- });
137
- });
138
-
139
- // composer
140
-
141
- describe('Composer info', () => {
142
- test('Name', () => {
143
- const creator = getName(asideNodeComposer);
144
- expect(creator).toEqual<string>('Sven Mikkelsen');
145
- });
146
-
147
- test('Bio', () => {
148
- const creator = getBio(asideNodeComposer);
149
- expect(creator).toEqual<string>(null);
150
- });
151
-
152
- test('Photo', () => {
153
- const creator = getPhoto(asideNodeComposer);
154
- expect(creator).toEqual<string>(
155
- 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
156
- );
157
- });
158
- });
159
-
160
- describe('Composer birthday info', () => {
161
- test('Birthday', () => {
162
- const creator = getBirthdayInfo(asideNodeComposer)?.birthday;
163
- expect(creator).toEqual<string>('');
164
- });
165
-
166
- test('Birthplace', () => {
167
- const creator = getBirthdayInfo(asideNodeComposer)?.birthPlace;
168
- expect(creator).toEqual<string>('');
169
- });
170
-
171
- test('Birthplace', () => {
172
- const creator = getBirthdayInfo(asideNodeComposer)?.age;
173
- expect(creator).toEqual(null);
174
- });
175
- });
176
-
177
- describe("Creator's films", () => {
178
- test('First film from first section', () => {
179
- const films = getFilms(filmsNodeComposer) as CSFDCreatorScreening[];
180
- expect(films[0].title).toEqual<string>('Spolu');
181
- });
182
- });
@@ -1,109 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { csfd } from '../src';
3
- import { fetchPage } from '../src/fetchers';
4
- import { CSFDCreatorScreening } from '../src/interfaces/creator.interface';
5
- import { CSFDColorRating, CSFDFilmTypes } from '../src/interfaces/global';
6
- import { movieUrl, userRatingsUrl } from '../src/vars';
7
- const badId = 999999999999999;
8
-
9
- // User Ratings
10
- describe('Live: Fetch rating page', () => {
11
- test('Fetch `912-bart` user and check some movie', async () => {
12
- const MOVIE_NAME = 'Návštěvník';
13
-
14
- const movies = await csfd.userRatings('912-bart');
15
- const movieSelected = movies.filter((x) => x.title === MOVIE_NAME)[0];
16
- expect(movies.map((x) => x.title)).toEqual(expect.arrayContaining([MOVIE_NAME]));
17
- expect(movieSelected?.year).toEqual<number>(2025);
18
- expect(movieSelected?.type).toEqual<CSFDFilmTypes>('film');
19
- expect(movieSelected?.userDate).toContain<string>('2025');
20
- expect(movies.length).toEqual(50);
21
- });
22
- });
23
-
24
- describe('Fetch rating page 2', () => {
25
- test('Fetch `912-bart` user – page 2 and check html', async () => {
26
- const url = userRatingsUrl(912, 2);
27
- const html = await fetchPage(url);
28
- expect(html).toContain('Můj soused Totoro');
29
- });
30
- });
31
-
32
- // Movie
33
- describe('Live: Movie page', () => {
34
- test('Fetch `10135-forrest-gump` movie', async () => {
35
- const movie = await csfd.movie(10135);
36
- expect(movie.title).toEqual<string>('Forrest Gump');
37
- expect(movie.rating).toBeGreaterThan(90);
38
- expect(movie.ratingCount).toBeGreaterThan(100000);
39
- // More than 10 words in description
40
- expect(movie.descriptions[0].split(' ').length).toBeGreaterThan(10);
41
- expect(movie.tags.length).toBeGreaterThan(3);
42
- expect(movie.year).toEqual(1994);
43
- expect(movie.type).toEqual<CSFDFilmTypes>('film');
44
- expect(movie.duration).toBeGreaterThan(140);
45
- expect(movie.premieres.length).toBeGreaterThan(1);
46
- expect(movie.colorRating).toEqual<CSFDColorRating>('good');
47
- expect(movie.creators.directors[0]?.name).toEqual('Robert Zemeckis');
48
- expect(movie.origins[0]).toEqual<string>('USA');
49
- });
50
- test('Fetch `71924-kralovstvi` serial years', async () => {
51
- const movie = await csfd.movie(71924);
52
- expect(movie.year).toEqual<number>(1994);
53
- expect(movie.title).toEqual<string>('Království');
54
- });
55
- });
56
-
57
- // Search
58
- describe('Live: Search', () => {
59
- test('Search matrix', async () => {
60
- const search = await csfd.search('matrix');
61
- const matrix = search.movies.find((x) => x.title === 'Matrix');
62
- expect(matrix?.year).toEqual<number>(1999);
63
- expect(matrix?.creators?.directors.map((x) => x.name)).toEqual<string[]>(
64
- expect.arrayContaining(['Lilly Wachowski'])
65
- );
66
- });
67
- });
68
-
69
- // Creator
70
- describe('Live: Creator page', () => {
71
- test('Fetch `2018-jan-werich` creator', async () => {
72
- const creator = await csfd.creator(2018);
73
- expect(creator.name).toEqual<string>('Jan Werich');
74
- expect(creator.birthday).toEqual('06.02.1905');
75
- expect(creator.birthplace).toContain('Rakousko-Uhersko');
76
- expect(creator.birthplace).toContain('Praha');
77
- expect(creator.films.find((film) => film.title === 'Hej-rup!')).toEqual<CSFDCreatorScreening>({
78
- id: 3106,
79
- title: 'Hej-rup!',
80
- year: 1934,
81
- colorRating: 'good'
82
- });
83
- });
84
- });
85
-
86
- // Edge cases
87
- describe('User page 404', () => {
88
- test('Fetch error URL', async () => {
89
- try {
90
- const url = userRatingsUrl(badId);
91
- const html = await fetchPage(url);
92
- expect(html).toBe('Error');
93
- } catch (e) {
94
- expect(e).toContain(Error);
95
- }
96
- });
97
- });
98
-
99
- describe('Movie page 404', () => {
100
- test('Fetch error URL', async () => {
101
- try {
102
- const url = movieUrl(badId);
103
- const html = await fetchPage(url);
104
- expect(html).toBe('Error');
105
- } catch (e) {
106
- expect(e).toThrow(Error);
107
- }
108
- });
109
- });
@@ -1,35 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { getDuration } from '../src/helpers/global.helper';
3
-
4
- export const durationInput = [
5
- 'PT142M',
6
- undefined,
7
- undefined,
8
- undefined,
9
- undefined,
10
- undefined,
11
- undefined,
12
- '142',
13
- undefined,
14
- { index: 0 },
15
- { input: 'PT142M' },
16
- { groups: undefined }
17
- ];
18
-
19
- const result = {
20
- sign: '+',
21
- years: 0,
22
- months: 0,
23
- weeks: 0,
24
- days: 0,
25
- hours: 0,
26
- minutes: '142',
27
- seconds: 0
28
- };
29
-
30
- describe('Live: Fetch rating page', () => {
31
- test('Resolve duration', async () => {
32
- const resolver = getDuration(durationInput);
33
- expect(resolver).toEqual(result);
34
- });
35
- });
@@ -1,59 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { addProtocol, parseColor, parseIdFromUrl } from '../src/helpers/global.helper';
3
-
4
- describe('Add protocol', () => {
5
- test('Handle without protocol', () => {
6
- const url = addProtocol('//www.csfd.cz/uzivatel/912-bart/hodnoceni/');
7
- expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');
8
- });
9
- test('Handle with protocol', () => {
10
- const url = addProtocol('https://www.csfd.cz/uzivatel/912-bart');
11
- expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart');
12
- });
13
- test('Handle http protocol', () => {
14
- const url = addProtocol('http://www.csfd.cz/uzivatel/912-bart');
15
- expect(url).toBe('http://www.csfd.cz/uzivatel/912-bart');
16
- });
17
- });
18
-
19
- describe('Parse Id', () => {
20
- test('Handle whole movie url', () => {
21
- const url = parseIdFromUrl('https://www.csfd.cz/film/906693-projekt-adam/recenze/');
22
- expect(url).toBe(null);
23
- });
24
- test('Handle movie url', () => {
25
- const url = parseIdFromUrl('/film/906693-projekt-adam/recenze/');
26
- expect(url).toBe(906693);
27
- });
28
- test('Handle bad url', () => {
29
- const url = parseIdFromUrl(null as any);
30
- expect(url).toBe(null);
31
- });
32
- test('bad string', () => {
33
- const url = parseIdFromUrl('bad string');
34
- expect(url).toBe(null);
35
- });
36
- });
37
-
38
- describe('Parse color', () => {
39
- test('Red', () => {
40
- const url = parseColor('red');
41
- expect(url).toBe('good');
42
- });
43
- test('Blue', () => {
44
- const url = parseColor('blue');
45
- expect(url).toBe('average');
46
- });
47
- test('Light grey', () => {
48
- const url = parseColor('lightgrey');
49
- expect(url).toBe('unknown');
50
- });
51
- test('Grey', () => {
52
- const url = parseColor('grey');
53
- expect(url).toBe('bad');
54
- });
55
- test('Wrong color', () => {
56
- const url = parseColor('adas' as any);
57
- expect(url).toBe('unknown');
58
- });
59
- });