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