1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { wait } from '@shared/core-utils'
4 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 } from '@shared/server-commands'
16 describe('Test AP refresher', function () {
17 let servers: PeerTubeServer[] = []
18 let videoUUID1: string
19 let videoUUID2: string
20 let videoUUID3: string
21 let playlistUUID1: string
22 let playlistUUID2: string
24 before(async function () {
27 servers = await createMultipleServers(2)
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
31 await setDefaultVideoChannel(servers)
33 for (const server of servers) {
34 await server.config.disableTranscoding()
38 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
39 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
40 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
44 const token1 = await servers[1].users.generateUserAndToken('user1')
45 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
47 const token2 = await servers[1].users.generateUserAndToken('user2')
48 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
52 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
53 const created = await servers[1].playlists.create({ attributes })
54 playlistUUID1 = created.uuid
58 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
59 const created = await servers[1].playlists.create({ attributes })
60 playlistUUID2 = created.uuid
63 await doubleFollow(servers[0], servers[1])
66 describe('Videos refresher', function () {
68 it('Should remove a deleted remote video', async function () {
73 // Change UUID so the remote server returns a 404
74 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
76 await servers[0].videos.get({ id: videoUUID1 })
77 await servers[0].videos.get({ id: videoUUID2 })
79 await waitJobs(servers)
81 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
82 await servers[0].videos.get({ id: videoUUID2 })
85 it('Should not update a remote video if the remote instance is down', async function () {
88 await killallServers([ servers[1] ])
90 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
92 // Video will need a refresh
95 await servers[0].videos.get({ id: videoUUID3 })
96 // The refresh should fail
97 await waitJobs([ servers[0] ])
99 await servers[1].run()
101 await servers[0].videos.get({ id: videoUUID3 })
105 describe('Actors refresher', function () {
107 it('Should remove a deleted actor', async function () {
110 const command = servers[0].accounts
114 // Change actor name so the remote server returns a 404
115 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
116 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
118 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
119 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
121 await waitJobs(servers)
123 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
124 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
128 describe('Playlist refresher', function () {
130 it('Should remove a deleted playlist', async function () {
135 // Change UUID so the remote server returns a 404
136 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
138 await servers[0].playlists.get({ playlistId: playlistUUID1 })
139 await servers[0].playlists.get({ playlistId: playlistUUID2 })
141 await waitJobs(servers)
143 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
144 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
148 after(async function () {
151 await cleanupTests(servers)