1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 cleanupTests, closeAllSequelize,
8 flushAndRunMultipleServers,
9 generateUserAccessToken,
15 setAccessTokensToServers,
17 setDefaultVideoChannel,
24 } from '../../../../shared/extra-utils'
25 import { getAccount } from '../../../../shared/extra-utils/users/accounts'
26 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
27 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
29 describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = []
31 let videoUUID1: string
32 let videoUUID2: string
33 let videoUUID3: string
34 let playlistUUID1: string
35 let playlistUUID2: string
37 before(async function () {
40 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
44 await setDefaultVideoChannel(servers)
47 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
48 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
49 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
53 const a1 = await generateUserAccessToken(servers[1], 'user1')
54 await uploadVideo(servers[1].url, a1, { name: 'video4' })
56 const a2 = await generateUserAccessToken(servers[1], 'user2')
57 await uploadVideo(servers[1].url, a2, { name: 'video5' })
61 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
62 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
63 playlistUUID1 = res.body.videoPlaylist.uuid
67 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
68 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
69 playlistUUID2 = res.body.videoPlaylist.uuid
72 await doubleFollow(servers[0], servers[1])
75 describe('Videos refresher', function () {
77 it('Should remove a deleted remote video', async function () {
82 // Change UUID so the remote server returns a 404
83 await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
85 await getVideo(servers[0].url, videoUUID1)
86 await getVideo(servers[0].url, videoUUID2)
88 await waitJobs(servers)
90 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
91 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
94 it('Should not update a remote video if the remote instance is down', async function () {
97 killallServers([ servers[1] ])
99 await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
101 // Video will need a refresh
104 await getVideo(servers[0].url, videoUUID3)
105 // The refresh should fail
106 await waitJobs([ servers[0] ])
108 await reRunServer(servers[1])
110 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
114 describe('Actors refresher', function () {
116 it('Should remove a deleted actor', async function () {
121 // Change actor name so the remote server returns a 404
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port)
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port)
128 await waitJobs(servers)
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200)
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404)
135 describe('Playlist refresher', function () {
137 it('Should remove a deleted playlist', async function () {
142 // Change UUID so the remote server returns a 404
143 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
145 await getVideoPlaylist(servers[0].url, playlistUUID1)
146 await getVideoPlaylist(servers[0].url, playlistUUID2)
148 await waitJobs(servers)
150 await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200)
151 await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404)
155 after(async function () {
158 await cleanupTests(servers)
160 await closeAllSequelize(servers)