]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-playlists.ts
Add migrations
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
index baa2b3b8cefd9b92000a057910e569ec8bf19a90..8c3542906da2a1e7585db483ecebfaa1938fa0ac 100644 (file)
@@ -10,11 +10,11 @@ import {
   createVideoPlaylist,
   deleteVideoChannel,
   deleteVideoPlaylist,
-  doubleFollow,
+  doubleFollow, doVideosExistInMyPlaylist,
   flushAndRunMultipleServers,
   flushTests,
   getAccountPlaylistsList,
-  getAccountPlaylistsListWithToken,
+  getAccountPlaylistsListWithToken, getMyUserInformation,
   getPlaylistVideos,
   getVideoChannelPlaylistsList,
   getVideoPlaylist,
@@ -36,11 +36,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 +196,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 +210,8 @@ describe('Test video playlists', function () {
         playlistAttrs: {
           displayName: 'playlist 3',
           privacy: VideoPlaylistPrivacy.PUBLIC,
-          thumbnailfile: 'thumbnail.jpg'
+          thumbnailfile: 'thumbnail.jpg',
+          videoChannelId: servers[1].videoChannel.id
         }
       })
 
@@ -421,7 +425,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 +629,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)
 
@@ -740,17 +815,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
       }
     })