+ describe('Element type', function () {
+ let groupUser1: ServerInfo[]
+ let groupWithoutToken1: ServerInfo[]
+ let group1: ServerInfo[]
+ let group2: ServerInfo[]
+
+ let video1: string
+ let video2: string
+ let video3: string
+
+ before(async function () {
+ this.timeout(30000)
+
+ groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ]
+ groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ]
+ group1 = [ servers[0] ]
+ group2 = [ servers[1], servers[2] ]
+
+ const res = await createVideoPlaylist({
+ url: servers[0].url,
+ token: userAccessTokenServer1,
+ playlistAttrs: {
+ displayName: 'playlist 56',
+ privacy: VideoPlaylistPrivacy.PUBLIC,
+ videoChannelId: servers[0].videoChannel.id
+ }
+ })
+
+ const playlistServer1Id2 = res.body.videoPlaylist.id
+ playlistServer1UUID2 = res.body.videoPlaylist.uuid
+
+ const addVideo = (elementAttrs: any) => {
+ return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs })
+ }
+
+ video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid
+ video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid
+ video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid
+
+ await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 })
+ await addVideo({ videoId: video2, startTimestamp: 35 })
+ await addVideo({ videoId: video3 })
+
+ await waitJobs(servers)
+ })
+
+ it('Should update the element type if the video is private', async function () {
+ this.timeout(20000)
+
+ const name = 'video 89'
+ const position = 1
+
+ {
+ await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE })
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
+ await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
+ }
+
+ {
+ await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC })
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ // We deleted the video, so even if we recreated it, the old entry is still deleted
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
+ }
+ })
+
+ it('Should update the element type if the video is blacklisted', async function () {
+ this.timeout(20000)
+
+ const name = 'video 89'
+ const position = 1
+
+ {
+ await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
+ }
+
+ {
+ await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ // We deleted the video (because unfederated), so even if we recreated it, the old entry is still deleted
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
+ }
+ })
+
+ it('Should update the element type if the account or server of the video is blocked', async function () {
+ this.timeout(90000)
+
+ const name = 'video 90'
+ const position = 2
+
+ {
+ await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+
+ await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ }
+
+ {
+ await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+
+ await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ }
+
+ {
+ await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+
+ await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ }
+
+ {
+ await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+
+ await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await waitJobs(servers)
+
+ await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
+ }
+ })
+
+ it('Should hide the video if it is NSFW', async function () {
+ const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false })
+ expect(res.body.total).to.equal(3)
+
+ const elements: VideoPlaylistElement[] = res.body.data
+ const element = elements.find(e => e.position === 3)
+
+ expect(element).to.exist
+ expect(element.video).to.be.null
+ expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
+ })