]> 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 baa2b3b8cefd9b92000a057910e569ec8bf19a90..83a2f3d4d81550a3e926e6af7896477abe41a62b 100644 (file)
@@ -6,22 +6,23 @@ import {
   addVideoChannel,
   addVideoInPlaylist,
   checkPlaylistFilesWereRemoved,
+  cleanupTests,
   createUser,
   createVideoPlaylist,
   deleteVideoChannel,
   deleteVideoPlaylist,
   doubleFollow,
+  doVideosExistInMyPlaylist,
   flushAndRunMultipleServers,
-  flushTests,
   getAccountPlaylistsList,
   getAccountPlaylistsListWithToken,
+  getMyUserInformation,
   getPlaylistVideos,
   getVideoChannelPlaylistsList,
   getVideoPlaylist,
   getVideoPlaylistPrivacies,
   getVideoPlaylistsList,
   getVideoPlaylistWithToken,
-  killallServers,
   removeUser,
   removeVideoFromPlaylist,
   reorderVideosPlaylist,
@@ -36,11 +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
 
@@ -194,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
@@ -207,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
         }
       })
 
@@ -353,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')
       ]
 
@@ -421,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
       }
     })
 
@@ -624,6 +630,76 @@ describe('Test video playlists', function () {
     }
   })
 
+  it('Should check videos existence in my playlist', async function () {
+    const videoIds = [
+      servers[0].videos[0].id,
+      42000,
+      servers[0].videos[3].id,
+      43000,
+      servers[0].videos[4].id
+    ]
+    const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds)
+    const obj = res.body as VideoExistInPlaylist
+
+    {
+      const elem = obj[servers[0].videos[0].id]
+      expect(elem).to.have.lengthOf(1)
+      expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
+      expect(elem[ 0 ].startTimestamp).to.equal(15)
+      expect(elem[ 0 ].stopTimestamp).to.equal(28)
+    }
+
+    {
+      const elem = obj[servers[0].videos[3].id]
+      expect(elem).to.have.lengthOf(1)
+      expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
+      expect(elem[ 0 ].startTimestamp).to.equal(1)
+      expect(elem[ 0 ].stopTimestamp).to.equal(35)
+    }
+
+    {
+      const elem = obj[servers[0].videos[4].id]
+      expect(elem).to.have.lengthOf(1)
+      expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
+      expect(elem[ 0 ].startTimestamp).to.equal(45)
+      expect(elem[ 0 ].stopTimestamp).to.equal(null)
+    }
+
+    expect(obj[42000]).to.have.lengthOf(0)
+    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)
 
@@ -681,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)
     }
   })
 
@@ -740,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
       }
     })
 
@@ -777,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)
   })
 })