]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-playlists.ts
Merge branch 'feature/parallel-tests' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
index 931491406e84dede6605ada43734169ef1453663..83a2f3d4d81550a3e926e6af7896477abe41a62b 100644 (file)
@@ -6,22 +6,23 @@ import {
   addVideoChannel,
   addVideoInPlaylist,
   checkPlaylistFilesWereRemoved,
+  cleanupTests,
   createUser,
   createVideoPlaylist,
   deleteVideoChannel,
   deleteVideoPlaylist,
-  doubleFollow, doVideosExistInMyPlaylist,
+  doubleFollow,
+  doVideosExistInMyPlaylist,
   flushAndRunMultipleServers,
-  flushTests,
   getAccountPlaylistsList,
   getAccountPlaylistsListWithToken,
+  getMyUserInformation,
   getPlaylistVideos,
   getVideoChannelPlaylistsList,
   getVideoPlaylist,
   getVideoPlaylistPrivacies,
   getVideoPlaylistsList,
   getVideoPlaylistWithToken,
-  killallServers,
   removeUser,
   removeVideoFromPlaylist,
   reorderVideosPlaylist,
@@ -36,12 +37,13 @@ import {
   uploadVideoAndGetId,
   userLogin,
   waitJobs
-} from '../../../../shared/utils'
+} from '../../../../shared/extra-utils'
 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
 import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
 import { Video } from '../../../../shared/models/videos'
 import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
 import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
+import { User } from '../../../../shared/models/users'
 
 const expect = chai.expect
 
@@ -195,7 +197,8 @@ describe('Test video playlists', function () {
         token: servers[1].accessToken,
         playlistAttrs: {
           displayName: 'playlist 2',
-          privacy: VideoPlaylistPrivacy.PUBLIC
+          privacy: VideoPlaylistPrivacy.PUBLIC,
+          videoChannelId: servers[1].videoChannel.id
         }
       })
       playlistServer2Id1 = res.body.videoPlaylist.id
@@ -208,7 +211,8 @@ describe('Test video playlists', function () {
         playlistAttrs: {
           displayName: 'playlist 3',
           privacy: VideoPlaylistPrivacy.PUBLIC,
-          thumbnailfile: 'thumbnail.jpg'
+          thumbnailfile: 'thumbnail.jpg',
+          videoChannelId: servers[1].videoChannel.id
         }
       })
 
@@ -354,7 +358,7 @@ describe('Test video playlists', function () {
 
     for (const server of servers) {
       const results = [
-        await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
+        await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'),
         await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
       ]
 
@@ -422,7 +426,8 @@ describe('Test video playlists', function () {
       token: servers[ 0 ].accessToken,
       playlistAttrs: {
         displayName: 'playlist 4',
-        privacy: VideoPlaylistPrivacy.PUBLIC
+        privacy: VideoPlaylistPrivacy.PUBLIC,
+        videoChannelId: servers[0].videoChannel.id
       }
     })
 
@@ -664,6 +669,37 @@ describe('Test video playlists', function () {
     expect(obj[43000]).to.have.lengthOf(0)
   })
 
+  it('Should automatically update updatedAt field of playlists', async function () {
+    const server = servers[1]
+    const videoId = servers[1].videos[5].id
+
+    async function getPlaylistNames () {
+      const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
+
+      return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
+    }
+
+    const elementAttrs = { videoId }
+    await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
+    await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
+
+    const names1 = await getPlaylistNames()
+    expect(names1[0]).to.equal('playlist 3 updated')
+    expect(names1[1]).to.equal('playlist 2')
+
+    await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, videoId })
+
+    const names2 = await getPlaylistNames()
+    expect(names2[0]).to.equal('playlist 2')
+    expect(names2[1]).to.equal('playlist 3 updated')
+
+    await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, videoId })
+
+    const names3 = await getPlaylistNames()
+    expect(names3[0]).to.equal('playlist 3 updated')
+    expect(names3[1]).to.equal('playlist 2')
+  })
+
   it('Should delete some elements', async function () {
     this.timeout(30000)
 
@@ -721,7 +757,7 @@ describe('Test video playlists', function () {
     this.timeout(30000)
 
     for (const server of servers) {
-      await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
+      await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber)
     }
   })
 
@@ -780,17 +816,26 @@ describe('Test video playlists', function () {
     this.timeout(30000)
 
     const user = { username: 'user_1', password: 'password' }
-    const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
+    const res = await createUser({
+      url: servers[ 0 ].url,
+      accessToken: servers[ 0 ].accessToken,
+      username: user.username,
+      password: user.password
+    })
 
     const userId = res.body.user.id
     const userAccessToken = await userLogin(servers[0], user)
 
+    const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
+    const userChannel = (resChannel.body as User).videoChannels[0]
+
     await createVideoPlaylist({
       url: servers[0].url,
       token: userAccessToken,
       playlistAttrs: {
         displayName: 'playlist to be deleted',
-        privacy: VideoPlaylistPrivacy.PUBLIC
+        privacy: VideoPlaylistPrivacy.PUBLIC,
+        videoChannelId: userChannel.id
       }
     })
 
@@ -817,11 +862,6 @@ describe('Test video playlists', function () {
   })
 
   after(async function () {
-    killallServers(servers)
-
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests(servers)
   })
 })