aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-14 09:19:03 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commit2a10aab3d7634a252a2acc946974df903e6025be (patch)
tree79d58e426ebf331f1331adab9e4da159ab8f634f
parent76564702b7be1b7bd0481624235960e6ff642078 (diff)
downloadPeerTube-2a10aab3d7634a252a2acc946974df903e6025be.tar.gz
PeerTube-2a10aab3d7634a252a2acc946974df903e6025be.tar.zst
PeerTube-2a10aab3d7634a252a2acc946974df903e6025be.zip
Add playlist updatedAt tests
-rw-r--r--server/controllers/api/video-playlist.ts8
-rw-r--r--server/tests/api/videos/video-playlists.ts31
-rw-r--r--shared/utils/videos/video-playlists.ts6
3 files changed, 39 insertions, 6 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 0a7ff92df..c7dfc583b 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -292,7 +292,7 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
292 videoId: video.id 292 videoId: video.id
293 }, { transaction: t }) 293 }, { transaction: t })
294 294
295 videoPlaylist.updatedAt = new Date() 295 videoPlaylist.changed('updatedAt', true)
296 await videoPlaylist.save({ transaction: t }) 296 await videoPlaylist.save({ transaction: t })
297 297
298 await sendUpdateVideoPlaylist(videoPlaylist, t) 298 await sendUpdateVideoPlaylist(videoPlaylist, t)
@@ -332,7 +332,7 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
332 332
333 const element = await videoPlaylistElement.save({ transaction: t }) 333 const element = await videoPlaylistElement.save({ transaction: t })
334 334
335 videoPlaylist.updatedAt = new Date() 335 videoPlaylist.changed('updatedAt', true)
336 await videoPlaylist.save({ transaction: t }) 336 await videoPlaylist.save({ transaction: t })
337 337
338 await sendUpdateVideoPlaylist(videoPlaylist, t) 338 await sendUpdateVideoPlaylist(videoPlaylist, t)
@@ -356,7 +356,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
356 // Decrease position of the next elements 356 // Decrease position of the next elements
357 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t) 357 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t)
358 358
359 videoPlaylist.updatedAt = new Date() 359 videoPlaylist.changed('updatedAt', true)
360 await videoPlaylist.save({ transaction: t }) 360 await videoPlaylist.save({ transaction: t })
361 361
362 await sendUpdateVideoPlaylist(videoPlaylist, t) 362 await sendUpdateVideoPlaylist(videoPlaylist, t)
@@ -401,7 +401,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
401 // Decrease positions of elements after the old position of our ordered elements (decrease) 401 // Decrease positions of elements after the old position of our ordered elements (decrease)
402 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t) 402 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t)
403 403
404 videoPlaylist.updatedAt = new Date() 404 videoPlaylist.changed('updatedAt', true)
405 await videoPlaylist.save({ transaction: t }) 405 await videoPlaylist.save({ transaction: t })
406 406
407 await sendUpdateVideoPlaylist(videoPlaylist, t) 407 await sendUpdateVideoPlaylist(videoPlaylist, t)
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 931491406..358a064ff 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -664,6 +664,37 @@ describe('Test video playlists', function () {
664 expect(obj[43000]).to.have.lengthOf(0) 664 expect(obj[43000]).to.have.lengthOf(0)
665 }) 665 })
666 666
667 it('Should automatically update updatedAt field of playlists', async function () {
668 const server = servers[1]
669 const videoId = servers[1].videos[5].id
670
671 async function getPlaylistNames () {
672 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
673
674 return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
675 }
676
677 const elementAttrs = { videoId }
678 await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
679 await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
680
681 const names1 = await getPlaylistNames()
682 expect(names1[0]).to.equal('playlist 3 updated')
683 expect(names1[1]).to.equal('playlist 2')
684
685 await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, videoId })
686
687 const names2 = await getPlaylistNames()
688 expect(names2[0]).to.equal('playlist 2')
689 expect(names2[1]).to.equal('playlist 3 updated')
690
691 await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, videoId })
692
693 const names3 = await getPlaylistNames()
694 expect(names3[0]).to.equal('playlist 3 updated')
695 expect(names3[1]).to.equal('playlist 2')
696 })
697
667 it('Should delete some elements', async function () { 698 it('Should delete some elements', async function () {
668 this.timeout(30000) 699 this.timeout(30000)
669 700
diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts
index ad65bec56..7568852dc 100644
--- a/shared/utils/videos/video-playlists.ts
+++ b/shared/utils/videos/video-playlists.ts
@@ -68,14 +68,16 @@ function getAccountPlaylistsListWithToken (
68 accountName: string, 68 accountName: string,
69 start: number, 69 start: number,
70 count: number, 70 count: number,
71 playlistType?: VideoPlaylistType 71 playlistType?: VideoPlaylistType,
72 sort?: string
72) { 73) {
73 const path = '/api/v1/accounts/' + accountName + '/video-playlists' 74 const path = '/api/v1/accounts/' + accountName + '/video-playlists'
74 75
75 const query = { 76 const query = {
76 start, 77 start,
77 count, 78 count,
78 playlistType 79 playlistType,
80 sort
79 } 81 }
80 82
81 return makeGetRequest({ 83 return makeGetRequest({