]>
Commit | Line | Data |
---|---|---|
37a44fc9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
af971e06 | 5 | import { VideoPlaylistPrivacy } from '@shared/models' |
37a44fc9 C |
6 | import { |
7 | addVideoInPlaylist, | |
37a44fc9 C |
8 | cleanupTests, |
9 | createVideoPlaylist, | |
10 | flushAndRunServer, | |
af971e06 | 11 | SearchCommand, |
37a44fc9 C |
12 | ServerInfo, |
13 | setAccessTokensToServers, | |
14 | setDefaultVideoChannel, | |
15 | uploadVideoAndGetId | |
16 | } from '../../../../shared/extra-utils' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test playlists search', function () { | |
21 | let server: ServerInfo = null | |
af971e06 | 22 | let command: SearchCommand |
37a44fc9 C |
23 | |
24 | before(async function () { | |
25 | this.timeout(30000) | |
26 | ||
27 | server = await flushAndRunServer(1) | |
28 | ||
29 | await setAccessTokensToServers([ server ]) | |
30 | await setDefaultVideoChannel([ server ]) | |
31 | ||
32 | const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid | |
33 | ||
34 | { | |
35 | const attributes = { | |
36 | displayName: 'Dr. Kenzo Tenma hospital videos', | |
37 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
38 | videoChannelId: server.videoChannel.id | |
39 | } | |
40 | const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | |
41 | ||
42 | await addVideoInPlaylist({ | |
43 | url: server.url, | |
44 | token: server.accessToken, | |
45 | playlistId: res.body.videoPlaylist.id, | |
46 | elementAttrs: { videoId } | |
47 | }) | |
48 | } | |
49 | ||
50 | { | |
51 | const attributes = { | |
52 | displayName: 'Johan & Anna Libert musics', | |
53 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
54 | videoChannelId: server.videoChannel.id | |
55 | } | |
56 | const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | |
57 | ||
58 | await addVideoInPlaylist({ | |
59 | url: server.url, | |
60 | token: server.accessToken, | |
61 | playlistId: res.body.videoPlaylist.id, | |
62 | elementAttrs: { videoId } | |
63 | }) | |
64 | } | |
65 | ||
66 | { | |
67 | const attributes = { | |
68 | displayName: 'Inspector Lunge playlist', | |
69 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
70 | videoChannelId: server.videoChannel.id | |
71 | } | |
72 | await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | |
73 | } | |
af971e06 C |
74 | |
75 | command = server.searchCommand | |
37a44fc9 C |
76 | }) |
77 | ||
78 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 79 | const body = await command.searchPlaylists({ search: 'abc' }) |
37a44fc9 | 80 | |
af971e06 C |
81 | expect(body.total).to.equal(0) |
82 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
83 | }) |
84 | ||
85 | it('Should make a search and have results', async function () { | |
86 | { | |
87 | const search = { | |
88 | search: 'tenma', | |
89 | start: 0, | |
90 | count: 1 | |
91 | } | |
af971e06 C |
92 | const body = await command.advancedPlaylistSearch({ search }) |
93 | expect(body.total).to.equal(1) | |
94 | expect(body.data).to.have.lengthOf(1) | |
37a44fc9 | 95 | |
af971e06 | 96 | const playlist = body.data[0] |
37a44fc9 C |
97 | expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') |
98 | expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) | |
99 | } | |
100 | ||
101 | { | |
102 | const search = { | |
103 | search: 'Anna Livert', | |
104 | start: 0, | |
105 | count: 1 | |
106 | } | |
af971e06 C |
107 | const body = await command.advancedPlaylistSearch({ search }) |
108 | expect(body.total).to.equal(1) | |
109 | expect(body.data).to.have.lengthOf(1) | |
37a44fc9 | 110 | |
af971e06 | 111 | const playlist = body.data[0] |
37a44fc9 C |
112 | expect(playlist.displayName).to.equal('Johan & Anna Libert musics') |
113 | } | |
114 | }) | |
115 | ||
116 | it('Should not display playlists without videos', async function () { | |
117 | const search = { | |
118 | search: 'Lunge', | |
119 | start: 0, | |
120 | count: 1 | |
121 | } | |
af971e06 C |
122 | const body = await command.advancedPlaylistSearch({ search }) |
123 | expect(body.total).to.equal(0) | |
124 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
125 | }) |
126 | ||
127 | after(async function () { | |
128 | await cleanupTests([ server ]) | |
129 | }) | |
130 | }) |