]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-playlists.ts
Add gitlab ci support
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
index 931491406e84dede6605ada43734169ef1453663..f82c8cbce0937f4b19390c9292f702acd4251c6d 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,
@@ -35,13 +36,15 @@ import {
   uploadVideo,
   uploadVideoAndGetId,
   userLogin,
-  waitJobs
-} from '../../../../shared/utils'
+  waitJobs,
+  generateUserAccessToken
+} 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
 
@@ -136,6 +139,18 @@ describe('Test video playlists', function () {
     }
   })
 
+  it('Should get private playlist for a classic user', async function () {
+    const token = await generateUserAccessToken(servers[0], 'toto')
+
+    const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5)
+
+    expect(res.body.total).to.equal(1)
+    expect(res.body.data).to.have.lengthOf(1)
+
+    const playlistId = res.body.data[0].id
+    await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5)
+  })
+
   it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
     this.timeout(30000)
 
@@ -195,7 +210,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 +224,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 +371,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 +439,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 +682,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)
 
@@ -705,6 +754,39 @@ describe('Test video playlists', function () {
     }
   })
 
+  it('Should be able to create a public playlist, and set it to private', async function () {
+    this.timeout(30000)
+
+    const res = await createVideoPlaylist({
+      url: servers[0].url,
+      token: servers[0].accessToken,
+      playlistAttrs: {
+        displayName: 'my super public playlist',
+        privacy: VideoPlaylistPrivacy.PUBLIC,
+        videoChannelId: servers[0].videoChannel.id
+      }
+    })
+    const videoPlaylistIds = res.body.videoPlaylist
+
+    await waitJobs(servers)
+
+    for (const server of servers) {
+      await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 200)
+    }
+
+    const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE }
+    await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs })
+
+    await waitJobs(servers)
+
+    for (const server of [ servers[1], servers[2] ]) {
+      await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 404)
+    }
+    await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, 401)
+
+    await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, 200)
+  })
+
   it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
     this.timeout(30000)
 
@@ -721,7 +803,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 +862,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 +908,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)
   })
 })