video-playlists.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. addVideoChannel,
  6. addVideoInPlaylist,
  7. checkPlaylistFilesWereRemoved,
  8. createUser,
  9. createVideoPlaylist,
  10. deleteVideoChannel,
  11. deleteVideoPlaylist,
  12. doubleFollow, doVideosExistInMyPlaylist,
  13. flushAndRunMultipleServers,
  14. flushTests,
  15. getAccountPlaylistsList,
  16. getAccountPlaylistsListWithToken, getMyUserInformation,
  17. getPlaylistVideos,
  18. getVideoChannelPlaylistsList,
  19. getVideoPlaylist,
  20. getVideoPlaylistPrivacies,
  21. getVideoPlaylistsList,
  22. getVideoPlaylistWithToken,
  23. killallServers,
  24. removeUser,
  25. removeVideoFromPlaylist,
  26. reorderVideosPlaylist,
  27. ServerInfo,
  28. setAccessTokensToServers,
  29. setDefaultVideoChannel,
  30. testImage,
  31. unfollow,
  32. updateVideoPlaylist,
  33. updateVideoPlaylistElement,
  34. uploadVideo,
  35. uploadVideoAndGetId,
  36. userLogin,
  37. waitJobs
  38. } from '../../../../shared/extra-utils'
  39. import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
  40. import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
  41. import { Video } from '../../../../shared/models/videos'
  42. import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
  43. import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
  44. import { User } from '../../../../shared/models/users'
  45. const expect = chai.expect
  46. describe('Test video playlists', function () {
  47. let servers: ServerInfo[] = []
  48. let playlistServer2Id1: number
  49. let playlistServer2Id2: number
  50. let playlistServer2UUID2: number
  51. let playlistServer1Id: number
  52. let playlistServer1UUID: string
  53. let nsfwVideoServer1: number
  54. before(async function () {
  55. this.timeout(120000)
  56. servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
  57. // Get the access tokens
  58. await setAccessTokensToServers(servers)
  59. await setDefaultVideoChannel(servers)
  60. // Server 1 and server 2 follow each other
  61. await doubleFollow(servers[0], servers[1])
  62. // Server 1 and server 3 follow each other
  63. await doubleFollow(servers[0], servers[2])
  64. {
  65. const serverPromises: Promise<any>[][] = []
  66. for (const server of servers) {
  67. const videoPromises: Promise<any>[] = []
  68. for (let i = 0; i < 7; i++) {
  69. videoPromises.push(
  70. uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
  71. .then(res => res.body.video)
  72. )
  73. }
  74. serverPromises.push(videoPromises)
  75. }
  76. servers[0].videos = await Promise.all(serverPromises[0])
  77. servers[1].videos = await Promise.all(serverPromises[1])
  78. servers[2].videos = await Promise.all(serverPromises[2])
  79. }
  80. nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
  81. await waitJobs(servers)
  82. })
  83. it('Should list video playlist privacies', async function () {
  84. const res = await getVideoPlaylistPrivacies(servers[0].url)
  85. const privacies = res.body
  86. expect(Object.keys(privacies)).to.have.length.at.least(3)
  87. expect(privacies[3]).to.equal('Private')
  88. })
  89. it('Should list watch later playlist', async function () {
  90. const url = servers[ 0 ].url
  91. const accessToken = servers[ 0 ].accessToken
  92. {
  93. const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
  94. expect(res.body.total).to.equal(1)
  95. expect(res.body.data).to.have.lengthOf(1)
  96. const playlist: VideoPlaylist = res.body.data[ 0 ]
  97. expect(playlist.displayName).to.equal('Watch later')
  98. expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
  99. expect(playlist.type.label).to.equal('Watch later')
  100. }
  101. {
  102. const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
  103. expect(res.body.total).to.equal(0)
  104. expect(res.body.data).to.have.lengthOf(0)
  105. }
  106. {
  107. const res = await getAccountPlaylistsList(url, 'root', 0, 5)
  108. expect(res.body.total).to.equal(0)
  109. expect(res.body.data).to.have.lengthOf(0)
  110. }
  111. })
  112. it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
  113. this.timeout(30000)
  114. await createVideoPlaylist({
  115. url: servers[0].url,
  116. token: servers[0].accessToken,
  117. playlistAttrs: {
  118. displayName: 'my super playlist',
  119. privacy: VideoPlaylistPrivacy.PUBLIC,
  120. description: 'my super description',
  121. thumbnailfile: 'thumbnail.jpg',
  122. videoChannelId: servers[0].videoChannel.id
  123. }
  124. })
  125. await waitJobs(servers)
  126. for (const server of servers) {
  127. const res = await getVideoPlaylistsList(server.url, 0, 5)
  128. expect(res.body.total).to.equal(1)
  129. expect(res.body.data).to.have.lengthOf(1)
  130. const playlistFromList = res.body.data[0] as VideoPlaylist
  131. const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
  132. const playlistFromGet = res2.body
  133. for (const playlist of [ playlistFromGet, playlistFromList ]) {
  134. expect(playlist.id).to.be.a('number')
  135. expect(playlist.uuid).to.be.a('string')
  136. expect(playlist.isLocal).to.equal(server.serverNumber === 1)
  137. expect(playlist.displayName).to.equal('my super playlist')
  138. expect(playlist.description).to.equal('my super description')
  139. expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
  140. expect(playlist.privacy.label).to.equal('Public')
  141. expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
  142. expect(playlist.type.label).to.equal('Regular')
  143. expect(playlist.videosLength).to.equal(0)
  144. expect(playlist.ownerAccount.name).to.equal('root')
  145. expect(playlist.ownerAccount.displayName).to.equal('root')
  146. expect(playlist.videoChannel.name).to.equal('root_channel')
  147. expect(playlist.videoChannel.displayName).to.equal('Main root channel')
  148. }
  149. }
  150. })
  151. it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
  152. this.timeout(30000)
  153. {
  154. const res = await createVideoPlaylist({
  155. url: servers[1].url,
  156. token: servers[1].accessToken,
  157. playlistAttrs: {
  158. displayName: 'playlist 2',
  159. privacy: VideoPlaylistPrivacy.PUBLIC,
  160. videoChannelId: servers[1].videoChannel.id
  161. }
  162. })
  163. playlistServer2Id1 = res.body.videoPlaylist.id
  164. }
  165. {
  166. const res = await createVideoPlaylist({
  167. url: servers[ 1 ].url,
  168. token: servers[ 1 ].accessToken,
  169. playlistAttrs: {
  170. displayName: 'playlist 3',
  171. privacy: VideoPlaylistPrivacy.PUBLIC,
  172. thumbnailfile: 'thumbnail.jpg',
  173. videoChannelId: servers[1].videoChannel.id
  174. }
  175. })
  176. playlistServer2Id2 = res.body.videoPlaylist.id
  177. playlistServer2UUID2 = res.body.videoPlaylist.uuid
  178. }
  179. for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
  180. await addVideoInPlaylist({
  181. url: servers[ 1 ].url,
  182. token: servers[ 1 ].accessToken,
  183. playlistId: id,
  184. elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
  185. })
  186. await addVideoInPlaylist({
  187. url: servers[ 1 ].url,
  188. token: servers[ 1 ].accessToken,
  189. playlistId: id,
  190. elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
  191. })
  192. }
  193. await waitJobs(servers)
  194. for (const server of [ servers[0], servers[1] ]) {
  195. const res = await getVideoPlaylistsList(server.url, 0, 5)
  196. const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
  197. expect(playlist2).to.not.be.undefined
  198. await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
  199. const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
  200. expect(playlist3).to.not.be.undefined
  201. await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
  202. }
  203. const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
  204. expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
  205. expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
  206. })
  207. it('Should have the playlist on server 3 after a new follow', async function () {
  208. this.timeout(30000)
  209. // Server 2 and server 3 follow each other
  210. await doubleFollow(servers[1], servers[2])
  211. const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
  212. const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
  213. expect(playlist2).to.not.be.undefined
  214. await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
  215. expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
  216. })
  217. it('Should correctly list the playlists', async function () {
  218. this.timeout(30000)
  219. {
  220. const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
  221. expect(res.body.total).to.equal(3)
  222. const data: VideoPlaylist[] = res.body.data
  223. expect(data).to.have.lengthOf(2)
  224. expect(data[ 0 ].displayName).to.equal('playlist 2')
  225. expect(data[ 1 ].displayName).to.equal('playlist 3')
  226. }
  227. {
  228. const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
  229. expect(res.body.total).to.equal(3)
  230. const data: VideoPlaylist[] = res.body.data
  231. expect(data).to.have.lengthOf(2)
  232. expect(data[ 0 ].displayName).to.equal('playlist 2')
  233. expect(data[ 1 ].displayName).to.equal('my super playlist')
  234. }
  235. })
  236. it('Should list video channel playlists', async function () {
  237. this.timeout(30000)
  238. {
  239. const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
  240. expect(res.body.total).to.equal(1)
  241. const data: VideoPlaylist[] = res.body.data
  242. expect(data).to.have.lengthOf(1)
  243. expect(data[ 0 ].displayName).to.equal('my super playlist')
  244. }
  245. })
  246. it('Should list account playlists', async function () {
  247. this.timeout(30000)
  248. {
  249. const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
  250. expect(res.body.total).to.equal(2)
  251. const data: VideoPlaylist[] = res.body.data
  252. expect(data).to.have.lengthOf(1)
  253. expect(data[ 0 ].displayName).to.equal('playlist 2')
  254. }
  255. {
  256. const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
  257. expect(res.body.total).to.equal(2)
  258. const data: VideoPlaylist[] = res.body.data
  259. expect(data).to.have.lengthOf(1)
  260. expect(data[ 0 ].displayName).to.equal('playlist 3')
  261. }
  262. })
  263. it('Should not list unlisted or private playlists', async function () {
  264. this.timeout(30000)
  265. await createVideoPlaylist({
  266. url: servers[ 1 ].url,
  267. token: servers[ 1 ].accessToken,
  268. playlistAttrs: {
  269. displayName: 'playlist unlisted',
  270. privacy: VideoPlaylistPrivacy.UNLISTED
  271. }
  272. })
  273. await createVideoPlaylist({
  274. url: servers[ 1 ].url,
  275. token: servers[ 1 ].accessToken,
  276. playlistAttrs: {
  277. displayName: 'playlist private',
  278. privacy: VideoPlaylistPrivacy.PRIVATE
  279. }
  280. })
  281. await waitJobs(servers)
  282. for (const server of servers) {
  283. const results = [
  284. await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
  285. await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
  286. ]
  287. expect(results[0].body.total).to.equal(2)
  288. expect(results[1].body.total).to.equal(3)
  289. for (const res of results) {
  290. const data: VideoPlaylist[] = res.body.data
  291. expect(data).to.have.lengthOf(2)
  292. expect(data[ 0 ].displayName).to.equal('playlist 3')
  293. expect(data[ 1 ].displayName).to.equal('playlist 2')
  294. }
  295. }
  296. })
  297. it('Should update a playlist', async function () {
  298. this.timeout(30000)
  299. await updateVideoPlaylist({
  300. url: servers[1].url,
  301. token: servers[1].accessToken,
  302. playlistAttrs: {
  303. displayName: 'playlist 3 updated',
  304. description: 'description updated',
  305. privacy: VideoPlaylistPrivacy.UNLISTED,
  306. thumbnailfile: 'thumbnail.jpg',
  307. videoChannelId: servers[1].videoChannel.id
  308. },
  309. playlistId: playlistServer2Id2
  310. })
  311. await waitJobs(servers)
  312. for (const server of servers) {
  313. const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
  314. const playlist: VideoPlaylist = res.body
  315. expect(playlist.displayName).to.equal('playlist 3 updated')
  316. expect(playlist.description).to.equal('description updated')
  317. expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
  318. expect(playlist.privacy.label).to.equal('Unlisted')
  319. expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
  320. expect(playlist.type.label).to.equal('Regular')
  321. expect(playlist.videosLength).to.equal(2)
  322. expect(playlist.ownerAccount.name).to.equal('root')
  323. expect(playlist.ownerAccount.displayName).to.equal('root')
  324. expect(playlist.videoChannel.name).to.equal('root_channel')
  325. expect(playlist.videoChannel.displayName).to.equal('Main root channel')
  326. }
  327. })
  328. it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
  329. this.timeout(30000)
  330. const addVideo = (elementAttrs: any) => {
  331. return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
  332. }
  333. const res = await createVideoPlaylist({
  334. url: servers[ 0 ].url,
  335. token: servers[ 0 ].accessToken,
  336. playlistAttrs: {
  337. displayName: 'playlist 4',
  338. privacy: VideoPlaylistPrivacy.PUBLIC,
  339. videoChannelId: servers[0].videoChannel.id
  340. }
  341. })
  342. playlistServer1Id = res.body.videoPlaylist.id
  343. playlistServer1UUID = res.body.videoPlaylist.uuid
  344. await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
  345. await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 })
  346. await addVideo({ videoId: servers[2].videos[2].uuid })
  347. await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 })
  348. await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
  349. await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
  350. await waitJobs(servers)
  351. })
  352. it('Should correctly list playlist videos', async function () {
  353. this.timeout(30000)
  354. for (const server of servers) {
  355. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  356. expect(res.body.total).to.equal(6)
  357. const videos: Video[] = res.body.data
  358. expect(videos).to.have.lengthOf(6)
  359. expect(videos[0].name).to.equal('video 0 server 1')
  360. expect(videos[0].playlistElement.position).to.equal(1)
  361. expect(videos[0].playlistElement.startTimestamp).to.equal(15)
  362. expect(videos[0].playlistElement.stopTimestamp).to.equal(28)
  363. expect(videos[1].name).to.equal('video 1 server 3')
  364. expect(videos[1].playlistElement.position).to.equal(2)
  365. expect(videos[1].playlistElement.startTimestamp).to.equal(35)
  366. expect(videos[1].playlistElement.stopTimestamp).to.be.null
  367. expect(videos[2].name).to.equal('video 2 server 3')
  368. expect(videos[2].playlistElement.position).to.equal(3)
  369. expect(videos[2].playlistElement.startTimestamp).to.be.null
  370. expect(videos[2].playlistElement.stopTimestamp).to.be.null
  371. expect(videos[3].name).to.equal('video 3 server 1')
  372. expect(videos[3].playlistElement.position).to.equal(4)
  373. expect(videos[3].playlistElement.startTimestamp).to.be.null
  374. expect(videos[3].playlistElement.stopTimestamp).to.equal(35)
  375. expect(videos[4].name).to.equal('video 4 server 1')
  376. expect(videos[4].playlistElement.position).to.equal(5)
  377. expect(videos[4].playlistElement.startTimestamp).to.equal(45)
  378. expect(videos[4].playlistElement.stopTimestamp).to.equal(60)
  379. expect(videos[5].name).to.equal('NSFW video')
  380. expect(videos[5].playlistElement.position).to.equal(6)
  381. expect(videos[5].playlistElement.startTimestamp).to.equal(5)
  382. expect(videos[5].playlistElement.stopTimestamp).to.be.null
  383. const res2 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10, { nsfw: false })
  384. expect(res2.body.total).to.equal(5)
  385. expect(res2.body.data.find(v => v.name === 'NSFW video')).to.be.undefined
  386. const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
  387. expect(res3.body.data).to.have.lengthOf(2)
  388. }
  389. })
  390. it('Should reorder the playlist', async function () {
  391. this.timeout(30000)
  392. {
  393. await reorderVideosPlaylist({
  394. url: servers[ 0 ].url,
  395. token: servers[ 0 ].accessToken,
  396. playlistId: playlistServer1Id,
  397. elementAttrs: {
  398. startPosition: 2,
  399. insertAfterPosition: 3
  400. }
  401. })
  402. await waitJobs(servers)
  403. for (const server of servers) {
  404. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  405. const names = res.body.data.map(v => v.name)
  406. expect(names).to.deep.equal([
  407. 'video 0 server 1',
  408. 'video 2 server 3',
  409. 'video 1 server 3',
  410. 'video 3 server 1',
  411. 'video 4 server 1',
  412. 'NSFW video'
  413. ])
  414. }
  415. }
  416. {
  417. await reorderVideosPlaylist({
  418. url: servers[0].url,
  419. token: servers[0].accessToken,
  420. playlistId: playlistServer1Id,
  421. elementAttrs: {
  422. startPosition: 1,
  423. reorderLength: 3,
  424. insertAfterPosition: 4
  425. }
  426. })
  427. await waitJobs(servers)
  428. for (const server of servers) {
  429. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  430. const names = res.body.data.map(v => v.name)
  431. expect(names).to.deep.equal([
  432. 'video 3 server 1',
  433. 'video 0 server 1',
  434. 'video 2 server 3',
  435. 'video 1 server 3',
  436. 'video 4 server 1',
  437. 'NSFW video'
  438. ])
  439. }
  440. }
  441. {
  442. await reorderVideosPlaylist({
  443. url: servers[0].url,
  444. token: servers[0].accessToken,
  445. playlistId: playlistServer1Id,
  446. elementAttrs: {
  447. startPosition: 6,
  448. insertAfterPosition: 3
  449. }
  450. })
  451. await waitJobs(servers)
  452. for (const server of servers) {
  453. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  454. const videos: Video[] = res.body.data
  455. const names = videos.map(v => v.name)
  456. expect(names).to.deep.equal([
  457. 'video 3 server 1',
  458. 'video 0 server 1',
  459. 'video 2 server 3',
  460. 'NSFW video',
  461. 'video 1 server 3',
  462. 'video 4 server 1'
  463. ])
  464. for (let i = 1; i <= videos.length; i++) {
  465. expect(videos[i - 1].playlistElement.position).to.equal(i)
  466. }
  467. }
  468. }
  469. })
  470. it('Should update startTimestamp/endTimestamp of some elements', async function () {
  471. this.timeout(30000)
  472. await updateVideoPlaylistElement({
  473. url: servers[0].url,
  474. token: servers[0].accessToken,
  475. playlistId: playlistServer1Id,
  476. videoId: servers[0].videos[3].uuid,
  477. elementAttrs: {
  478. startTimestamp: 1
  479. }
  480. })
  481. await updateVideoPlaylistElement({
  482. url: servers[0].url,
  483. token: servers[0].accessToken,
  484. playlistId: playlistServer1Id,
  485. videoId: servers[0].videos[4].uuid,
  486. elementAttrs: {
  487. stopTimestamp: null
  488. }
  489. })
  490. await waitJobs(servers)
  491. for (const server of servers) {
  492. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  493. const videos: Video[] = res.body.data
  494. expect(videos[0].name).to.equal('video 3 server 1')
  495. expect(videos[0].playlistElement.position).to.equal(1)
  496. expect(videos[0].playlistElement.startTimestamp).to.equal(1)
  497. expect(videos[0].playlistElement.stopTimestamp).to.equal(35)
  498. expect(videos[5].name).to.equal('video 4 server 1')
  499. expect(videos[5].playlistElement.position).to.equal(6)
  500. expect(videos[5].playlistElement.startTimestamp).to.equal(45)
  501. expect(videos[5].playlistElement.stopTimestamp).to.be.null
  502. }
  503. })
  504. it('Should check videos existence in my playlist', async function () {
  505. const videoIds = [
  506. servers[0].videos[0].id,
  507. 42000,
  508. servers[0].videos[3].id,
  509. 43000,
  510. servers[0].videos[4].id
  511. ]
  512. const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds)
  513. const obj = res.body as VideoExistInPlaylist
  514. {
  515. const elem = obj[servers[0].videos[0].id]
  516. expect(elem).to.have.lengthOf(1)
  517. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  518. expect(elem[ 0 ].startTimestamp).to.equal(15)
  519. expect(elem[ 0 ].stopTimestamp).to.equal(28)
  520. }
  521. {
  522. const elem = obj[servers[0].videos[3].id]
  523. expect(elem).to.have.lengthOf(1)
  524. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  525. expect(elem[ 0 ].startTimestamp).to.equal(1)
  526. expect(elem[ 0 ].stopTimestamp).to.equal(35)
  527. }
  528. {
  529. const elem = obj[servers[0].videos[4].id]
  530. expect(elem).to.have.lengthOf(1)
  531. expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
  532. expect(elem[ 0 ].startTimestamp).to.equal(45)
  533. expect(elem[ 0 ].stopTimestamp).to.equal(null)
  534. }
  535. expect(obj[42000]).to.have.lengthOf(0)
  536. expect(obj[43000]).to.have.lengthOf(0)
  537. })
  538. it('Should automatically update updatedAt field of playlists', async function () {
  539. const server = servers[1]
  540. const videoId = servers[1].videos[5].id
  541. async function getPlaylistNames () {
  542. const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
  543. return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
  544. }
  545. const elementAttrs = { videoId }
  546. await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
  547. await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
  548. const names1 = await getPlaylistNames()
  549. expect(names1[0]).to.equal('playlist 3 updated')
  550. expect(names1[1]).to.equal('playlist 2')
  551. await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, videoId })
  552. const names2 = await getPlaylistNames()
  553. expect(names2[0]).to.equal('playlist 2')
  554. expect(names2[1]).to.equal('playlist 3 updated')
  555. await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, videoId })
  556. const names3 = await getPlaylistNames()
  557. expect(names3[0]).to.equal('playlist 3 updated')
  558. expect(names3[1]).to.equal('playlist 2')
  559. })
  560. it('Should delete some elements', async function () {
  561. this.timeout(30000)
  562. await removeVideoFromPlaylist({
  563. url: servers[0].url,
  564. token: servers[0].accessToken,
  565. playlistId: playlistServer1Id,
  566. videoId: servers[0].videos[3].uuid
  567. })
  568. await removeVideoFromPlaylist({
  569. url: servers[0].url,
  570. token: servers[0].accessToken,
  571. playlistId: playlistServer1Id,
  572. videoId: nsfwVideoServer1
  573. })
  574. await waitJobs(servers)
  575. for (const server of servers) {
  576. const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
  577. expect(res.body.total).to.equal(4)
  578. const videos: Video[] = res.body.data
  579. expect(videos).to.have.lengthOf(4)
  580. expect(videos[ 0 ].name).to.equal('video 0 server 1')
  581. expect(videos[ 0 ].playlistElement.position).to.equal(1)
  582. expect(videos[ 1 ].name).to.equal('video 2 server 3')
  583. expect(videos[ 1 ].playlistElement.position).to.equal(2)
  584. expect(videos[ 2 ].name).to.equal('video 1 server 3')
  585. expect(videos[ 2 ].playlistElement.position).to.equal(3)
  586. expect(videos[ 3 ].name).to.equal('video 4 server 1')
  587. expect(videos[ 3 ].playlistElement.position).to.equal(4)
  588. }
  589. })
  590. it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
  591. this.timeout(30000)
  592. await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
  593. await waitJobs(servers)
  594. for (const server of servers) {
  595. await getVideoPlaylist(server.url, playlistServer1UUID, 404)
  596. }
  597. })
  598. it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
  599. this.timeout(30000)
  600. for (const server of servers) {
  601. await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
  602. }
  603. })
  604. it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
  605. this.timeout(30000)
  606. const finder = data => data.find(p => p.displayName === 'my super playlist')
  607. {
  608. const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
  609. expect(res.body.total).to.equal(2)
  610. expect(finder(res.body.data)).to.not.be.undefined
  611. }
  612. await unfollow(servers[2].url, servers[2].accessToken, servers[0])
  613. {
  614. const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
  615. expect(res.body.total).to.equal(1)
  616. expect(finder(res.body.data)).to.be.undefined
  617. }
  618. })
  619. it('Should delete a channel and put the associated playlist in private mode', async function () {
  620. this.timeout(30000)
  621. const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
  622. const videoChannelId = res.body.videoChannel.id
  623. const res2 = await createVideoPlaylist({
  624. url: servers[0].url,
  625. token: servers[0].accessToken,
  626. playlistAttrs: {
  627. displayName: 'channel playlist',
  628. privacy: VideoPlaylistPrivacy.PUBLIC,
  629. videoChannelId
  630. }
  631. })
  632. const videoPlaylistUUID = res2.body.videoPlaylist.uuid
  633. await waitJobs(servers)
  634. await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
  635. await waitJobs(servers)
  636. const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID)
  637. expect(res3.body.displayName).to.equal('channel playlist')
  638. expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
  639. await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
  640. })
  641. it('Should delete an account and delete its playlists', async function () {
  642. this.timeout(30000)
  643. const user = { username: 'user_1', password: 'password' }
  644. const res = await createUser({
  645. url: servers[ 0 ].url,
  646. accessToken: servers[ 0 ].accessToken,
  647. username: user.username,
  648. password: user.password
  649. })
  650. const userId = res.body.user.id
  651. const userAccessToken = await userLogin(servers[0], user)
  652. const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
  653. const userChannel = (resChannel.body as User).videoChannels[0]
  654. await createVideoPlaylist({
  655. url: servers[0].url,
  656. token: userAccessToken,
  657. playlistAttrs: {
  658. displayName: 'playlist to be deleted',
  659. privacy: VideoPlaylistPrivacy.PUBLIC,
  660. videoChannelId: userChannel.id
  661. }
  662. })
  663. await waitJobs(servers)
  664. const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
  665. {
  666. for (const server of [ servers[0], servers[1] ]) {
  667. const res = await getVideoPlaylistsList(server.url, 0, 15)
  668. expect(finder(res.body.data)).to.not.be.undefined
  669. }
  670. }
  671. await removeUser(servers[0].url, userId, servers[0].accessToken)
  672. await waitJobs(servers)
  673. {
  674. for (const server of [ servers[0], servers[1] ]) {
  675. const res = await getVideoPlaylistsList(server.url, 0, 15)
  676. expect(finder(res.body.data)).to.be.undefined
  677. }
  678. }
  679. })
  680. after(function () {
  681. killallServers(servers)
  682. })
  683. })