1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
8 flushAndRunMultipleServers,
9 generateUserAccessToken,
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
20 } from '@shared/extra-utils'
21 import { VideoPlaylistPrivacy } from '@shared/models'
23 describe('Test AP refresher', function () {
24 let servers: ServerInfo[] = []
25 let videoUUID1: string
26 let videoUUID2: string
27 let videoUUID3: string
28 let playlistUUID1: string
29 let playlistUUID2: string
31 before(async function () {
34 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
36 // Get the access tokens
37 await setAccessTokensToServers(servers)
38 await setDefaultVideoChannel(servers)
41 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
42 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
43 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
47 const a1 = await generateUserAccessToken(servers[1], 'user1')
48 await uploadVideo(servers[1].url, a1, { name: 'video4' })
50 const a2 = await generateUserAccessToken(servers[1], 'user2')
51 await uploadVideo(servers[1].url, a2, { name: 'video5' })
55 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
56 const created = await servers[1].playlistsCommand.create({ attributes })
57 playlistUUID1 = created.uuid
61 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
62 const created = await servers[1].playlistsCommand.create({ attributes })
63 playlistUUID2 = created.uuid
66 await doubleFollow(servers[0], servers[1])
69 describe('Videos refresher', function () {
71 it('Should remove a deleted remote video', async function () {
76 // Change UUID so the remote server returns a 404
77 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
79 await getVideo(servers[0].url, videoUUID1)
80 await getVideo(servers[0].url, videoUUID2)
82 await waitJobs(servers)
84 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
85 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
88 it('Should not update a remote video if the remote instance is down', async function () {
91 await killallServers([ servers[1] ])
93 await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
95 // Video will need a refresh
98 await getVideo(servers[0].url, videoUUID3)
99 // The refresh should fail
100 await waitJobs([ servers[0] ])
102 await reRunServer(servers[1])
104 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
108 describe('Actors refresher', function () {
110 it('Should remove a deleted actor', async function () {
113 const command = servers[0].accountsCommand
117 // Change actor name so the remote server returns a 404
118 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
119 await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto')
121 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
122 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
124 await waitJobs(servers)
126 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
127 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
131 describe('Playlist refresher', function () {
133 it('Should remove a deleted playlist', async function () {
138 // Change UUID so the remote server returns a 404
139 await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
141 await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
142 await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
144 await waitJobs(servers)
146 await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
147 await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
151 after(async function () {
154 await cleanupTests(servers)