diff options
Diffstat (limited to 'server/tests/api/search/search-playlists.ts')
-rw-r--r-- | server/tests/api/search/search-playlists.ts | 159 |
1 files changed, 104 insertions, 55 deletions
diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index ab17d55e9..15aac029a 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts | |||
@@ -2,82 +2,86 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { VideoPlaylist, VideoPlaylistPrivacy } from '@shared/models' | ||
6 | import { | 5 | import { |
7 | addVideoInPlaylist, | ||
8 | advancedVideoPlaylistSearch, | ||
9 | cleanupTests, | 6 | cleanupTests, |
10 | createVideoPlaylist, | 7 | createSingleServer, |
11 | flushAndRunServer, | 8 | doubleFollow, |
12 | searchVideoPlaylists, | 9 | PeerTubeServer, |
13 | ServerInfo, | 10 | SearchCommand, |
14 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
15 | setDefaultVideoChannel, | 12 | setDefaultVideoChannel |
16 | uploadVideoAndGetId | 13 | } from '@shared/extra-utils' |
17 | } from '../../../../shared/extra-utils' | 14 | import { VideoPlaylistPrivacy } from '@shared/models' |
18 | 15 | ||
19 | const expect = chai.expect | 16 | const expect = chai.expect |
20 | 17 | ||
21 | describe('Test playlists search', function () { | 18 | describe('Test playlists search', function () { |
22 | let server: ServerInfo = null | 19 | let server: PeerTubeServer |
20 | let remoteServer: PeerTubeServer | ||
21 | let command: SearchCommand | ||
22 | let playlistUUID: string | ||
23 | let playlistShortUUID: string | ||
23 | 24 | ||
24 | before(async function () { | 25 | before(async function () { |
25 | this.timeout(30000) | 26 | this.timeout(120000) |
26 | 27 | ||
27 | server = await flushAndRunServer(1) | 28 | const servers = await Promise.all([ |
29 | createSingleServer(1), | ||
30 | createSingleServer(2, { transcoding: { enabled: false } }) | ||
31 | ]) | ||
32 | server = servers[0] | ||
33 | remoteServer = servers[1] | ||
28 | 34 | ||
29 | await setAccessTokensToServers([ server ]) | 35 | await setAccessTokensToServers([ remoteServer, server ]) |
30 | await setDefaultVideoChannel([ server ]) | 36 | await setDefaultVideoChannel([ remoteServer, server ]) |
31 | |||
32 | const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid | ||
33 | 37 | ||
34 | { | 38 | { |
39 | const videoId = (await server.videos.upload()).uuid | ||
40 | |||
35 | const attributes = { | 41 | const attributes = { |
36 | displayName: 'Dr. Kenzo Tenma hospital videos', | 42 | displayName: 'Dr. Kenzo Tenma hospital videos', |
37 | privacy: VideoPlaylistPrivacy.PUBLIC, | 43 | privacy: VideoPlaylistPrivacy.PUBLIC, |
38 | videoChannelId: server.videoChannel.id | 44 | videoChannelId: server.store.channel.id |
39 | } | 45 | } |
40 | const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | 46 | const created = await server.playlists.create({ attributes }) |
41 | 47 | playlistUUID = created.uuid | |
42 | await addVideoInPlaylist({ | 48 | playlistShortUUID = created.shortUUID |
43 | url: server.url, | 49 | |
44 | token: server.accessToken, | 50 | await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) |
45 | playlistId: res.body.videoPlaylist.id, | ||
46 | elementAttrs: { videoId } | ||
47 | }) | ||
48 | } | 51 | } |
49 | 52 | ||
50 | { | 53 | { |
54 | const videoId = (await remoteServer.videos.upload()).uuid | ||
55 | |||
51 | const attributes = { | 56 | const attributes = { |
52 | displayName: 'Johan & Anna Libert musics', | 57 | displayName: 'Johan & Anna Libert music videos', |
53 | privacy: VideoPlaylistPrivacy.PUBLIC, | 58 | privacy: VideoPlaylistPrivacy.PUBLIC, |
54 | videoChannelId: server.videoChannel.id | 59 | videoChannelId: remoteServer.store.channel.id |
55 | } | 60 | } |
56 | const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | 61 | const created = await remoteServer.playlists.create({ attributes }) |
57 | 62 | ||
58 | await addVideoInPlaylist({ | 63 | await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) |
59 | url: server.url, | ||
60 | token: server.accessToken, | ||
61 | playlistId: res.body.videoPlaylist.id, | ||
62 | elementAttrs: { videoId } | ||
63 | }) | ||
64 | } | 64 | } |
65 | 65 | ||
66 | { | 66 | { |
67 | const attributes = { | 67 | const attributes = { |
68 | displayName: 'Inspector Lunge playlist', | 68 | displayName: 'Inspector Lunge playlist', |
69 | privacy: VideoPlaylistPrivacy.PUBLIC, | 69 | privacy: VideoPlaylistPrivacy.PUBLIC, |
70 | videoChannelId: server.videoChannel.id | 70 | videoChannelId: server.store.channel.id |
71 | } | 71 | } |
72 | await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) | 72 | await server.playlists.create({ attributes }) |
73 | } | 73 | } |
74 | |||
75 | await doubleFollow(server, remoteServer) | ||
76 | |||
77 | command = server.search | ||
74 | }) | 78 | }) |
75 | 79 | ||
76 | it('Should make a simple search and not have results', async function () { | 80 | it('Should make a simple search and not have results', async function () { |
77 | const res = await searchVideoPlaylists(server.url, 'abc') | 81 | const body = await command.searchPlaylists({ search: 'abc' }) |
78 | 82 | ||
79 | expect(res.body.total).to.equal(0) | 83 | expect(body.total).to.equal(0) |
80 | expect(res.body.data).to.have.lengthOf(0) | 84 | expect(body.data).to.have.lengthOf(0) |
81 | }) | 85 | }) |
82 | 86 | ||
83 | it('Should make a search and have results', async function () { | 87 | it('Should make a search and have results', async function () { |
@@ -87,27 +91,72 @@ describe('Test playlists search', function () { | |||
87 | start: 0, | 91 | start: 0, |
88 | count: 1 | 92 | count: 1 |
89 | } | 93 | } |
90 | const res = await advancedVideoPlaylistSearch(server.url, search) | 94 | const body = await command.advancedPlaylistSearch({ search }) |
91 | expect(res.body.total).to.equal(1) | 95 | expect(body.total).to.equal(1) |
92 | expect(res.body.data).to.have.lengthOf(1) | 96 | expect(body.data).to.have.lengthOf(1) |
93 | 97 | ||
94 | const playlist: VideoPlaylist = res.body.data[0] | 98 | const playlist = body.data[0] |
95 | expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') | 99 | expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') |
96 | expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) | 100 | expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) |
97 | } | 101 | } |
98 | 102 | ||
99 | { | 103 | { |
100 | const search = { | 104 | const search = { |
101 | search: 'Anna Livert', | 105 | search: 'Anna Livert music', |
102 | start: 0, | 106 | start: 0, |
103 | count: 1 | 107 | count: 1 |
104 | } | 108 | } |
105 | const res = await advancedVideoPlaylistSearch(server.url, search) | 109 | const body = await command.advancedPlaylistSearch({ search }) |
106 | expect(res.body.total).to.equal(1) | 110 | expect(body.total).to.equal(1) |
107 | expect(res.body.data).to.have.lengthOf(1) | 111 | expect(body.data).to.have.lengthOf(1) |
112 | |||
113 | const playlist = body.data[0] | ||
114 | expect(playlist.displayName).to.equal('Johan & Anna Libert music videos') | ||
115 | } | ||
116 | }) | ||
117 | |||
118 | it('Should filter by host', async function () { | ||
119 | { | ||
120 | const search = { search: 'tenma', host: server.host } | ||
121 | const body = await command.advancedPlaylistSearch({ search }) | ||
122 | expect(body.total).to.equal(1) | ||
123 | expect(body.data).to.have.lengthOf(1) | ||
124 | |||
125 | const playlist = body.data[0] | ||
126 | expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') | ||
127 | } | ||
128 | |||
129 | { | ||
130 | const search = { search: 'Anna', host: 'example.com' } | ||
131 | const body = await command.advancedPlaylistSearch({ search }) | ||
132 | expect(body.total).to.equal(0) | ||
133 | expect(body.data).to.have.lengthOf(0) | ||
134 | } | ||
135 | |||
136 | { | ||
137 | const search = { search: 'video', host: remoteServer.host } | ||
138 | const body = await command.advancedPlaylistSearch({ search }) | ||
139 | expect(body.total).to.equal(1) | ||
140 | expect(body.data).to.have.lengthOf(1) | ||
141 | |||
142 | const playlist = body.data[0] | ||
143 | expect(playlist.displayName).to.equal('Johan & Anna Libert music videos') | ||
144 | } | ||
145 | }) | ||
146 | |||
147 | it('Should filter by UUIDs', async function () { | ||
148 | for (const uuid of [ playlistUUID, playlistShortUUID ]) { | ||
149 | const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } }) | ||
150 | |||
151 | expect(body.total).to.equal(1) | ||
152 | expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos') | ||
153 | } | ||
154 | |||
155 | { | ||
156 | const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } }) | ||
108 | 157 | ||
109 | const playlist: VideoPlaylist = res.body.data[0] | 158 | expect(body.total).to.equal(0) |
110 | expect(playlist.displayName).to.equal('Johan & Anna Libert musics') | 159 | expect(body.data).to.have.lengthOf(0) |
111 | } | 160 | } |
112 | }) | 161 | }) |
113 | 162 | ||
@@ -117,12 +166,12 @@ describe('Test playlists search', function () { | |||
117 | start: 0, | 166 | start: 0, |
118 | count: 1 | 167 | count: 1 |
119 | } | 168 | } |
120 | const res = await advancedVideoPlaylistSearch(server.url, search) | 169 | const body = await command.advancedPlaylistSearch({ search }) |
121 | expect(res.body.total).to.equal(0) | 170 | expect(body.total).to.equal(0) |
122 | expect(res.body.data).to.have.lengthOf(0) | 171 | expect(body.data).to.have.lengthOf(0) |
123 | }) | 172 | }) |
124 | 173 | ||
125 | after(async function () { | 174 | after(async function () { |
126 | await cleanupTests([ server ]) | 175 | await cleanupTests([ server, remoteServer ]) |
127 | }) | 176 | }) |
128 | }) | 177 | }) |