]>
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' | |
37a44fc9 | 5 | import { |
37a44fc9 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
254d3579 | 8 | PeerTubeServer, |
4c7e60bc | 9 | SearchCommand, |
37a44fc9 | 10 | setAccessTokensToServers, |
d23dd9fb C |
11 | setDefaultVideoChannel |
12 | } from '@shared/extra-utils' | |
13 | import { VideoPlaylistPrivacy } from '@shared/models' | |
37a44fc9 C |
14 | |
15 | const expect = chai.expect | |
16 | ||
17 | describe('Test playlists search', function () { | |
254d3579 | 18 | let server: PeerTubeServer = null |
af971e06 | 19 | let command: SearchCommand |
37a44fc9 C |
20 | |
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
254d3579 | 24 | server = await createSingleServer(1) |
37a44fc9 C |
25 | |
26 | await setAccessTokensToServers([ server ]) | |
27 | await setDefaultVideoChannel([ server ]) | |
28 | ||
89d241a7 | 29 | const videoId = (await server.videos.quickUpload({ name: 'video' })).uuid |
37a44fc9 C |
30 | |
31 | { | |
32 | const attributes = { | |
33 | displayName: 'Dr. Kenzo Tenma hospital videos', | |
34 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 35 | videoChannelId: server.store.channel.id |
37a44fc9 | 36 | } |
89d241a7 | 37 | const created = await server.playlists.create({ attributes }) |
e6346d59 | 38 | |
89d241a7 | 39 | await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) |
37a44fc9 C |
40 | } |
41 | ||
42 | { | |
43 | const attributes = { | |
44 | displayName: 'Johan & Anna Libert musics', | |
45 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 46 | videoChannelId: server.store.channel.id |
37a44fc9 | 47 | } |
89d241a7 | 48 | const created = await server.playlists.create({ attributes }) |
e6346d59 | 49 | |
89d241a7 | 50 | await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) |
37a44fc9 C |
51 | } |
52 | ||
53 | { | |
54 | const attributes = { | |
55 | displayName: 'Inspector Lunge playlist', | |
56 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 57 | videoChannelId: server.store.channel.id |
37a44fc9 | 58 | } |
89d241a7 | 59 | await server.playlists.create({ attributes }) |
37a44fc9 | 60 | } |
af971e06 | 61 | |
89d241a7 | 62 | command = server.search |
37a44fc9 C |
63 | }) |
64 | ||
65 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 66 | const body = await command.searchPlaylists({ search: 'abc' }) |
37a44fc9 | 67 | |
af971e06 C |
68 | expect(body.total).to.equal(0) |
69 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
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 | } | |
af971e06 C |
79 | const body = await command.advancedPlaylistSearch({ search }) |
80 | expect(body.total).to.equal(1) | |
81 | expect(body.data).to.have.lengthOf(1) | |
37a44fc9 | 82 | |
af971e06 | 83 | const playlist = body.data[0] |
37a44fc9 C |
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 | } | |
af971e06 C |
94 | const body = await command.advancedPlaylistSearch({ search }) |
95 | expect(body.total).to.equal(1) | |
96 | expect(body.data).to.have.lengthOf(1) | |
37a44fc9 | 97 | |
af971e06 | 98 | const playlist = body.data[0] |
37a44fc9 C |
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 | } | |
af971e06 C |
109 | const body = await command.advancedPlaylistSearch({ search }) |
110 | expect(body.total).to.equal(0) | |
111 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
112 | }) |
113 | ||
114 | after(async function () { | |
115 | await cleanupTests([ server ]) | |
116 | }) | |
117 | }) |