1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { wait } from '@shared/core-utils'
5 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
15 } from '@shared/server-commands'
17 describe('Test AP refresher', function () {
18 let servers: PeerTubeServer[] = []
19 let videoUUID1: string
20 let videoUUID2: string
21 let videoUUID3: string
22 let playlistUUID1: string
23 let playlistUUID2: string
25 before(async function () {
28 servers = await createMultipleServers(2)
30 // Get the access tokens
31 await setAccessTokensToServers(servers)
32 await setDefaultVideoChannel(servers)
34 for (const server of servers) {
35 await server.config.disableTranscoding()
39 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
40 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
41 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
45 const token1 = await servers[1].users.generateUserAndToken('user1')
46 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
48 const token2 = await servers[1].users.generateUserAndToken('user2')
49 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
53 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
54 const created = await servers[1].playlists.create({ attributes })
55 playlistUUID1 = created.uuid
59 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
60 const created = await servers[1].playlists.create({ attributes })
61 playlistUUID2 = created.uuid
64 await doubleFollow(servers[0], servers[1])
67 describe('Videos refresher', function () {
69 it('Should remove a deleted remote video', async function () {
74 // Change UUID so the remote server returns a 404
75 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
77 await servers[0].videos.get({ id: videoUUID1 })
78 await servers[0].videos.get({ id: videoUUID2 })
80 await waitJobs(servers)
82 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
83 await servers[0].videos.get({ id: videoUUID2 })
86 it('Should not update a remote video if the remote instance is down', async function () {
89 await killallServers([ servers[1] ])
91 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
93 // Video will need a refresh
96 await servers[0].videos.get({ id: videoUUID3 })
97 // The refresh should fail
98 await waitJobs([ servers[0] ])
100 await servers[1].run()
102 await servers[0].videos.get({ id: videoUUID3 })
106 describe('Actors refresher', function () {
108 it('Should remove a deleted actor', async function () {
111 const command = servers[0].accounts
115 // Change actor name so the remote server returns a 404
116 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
117 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
119 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
120 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
122 await waitJobs(servers)
124 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
125 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
129 describe('Playlist refresher', function () {
131 it('Should remove a deleted playlist', async function () {
136 // Change UUID so the remote server returns a 404
137 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
139 await servers[0].playlists.get({ playlistId: playlistUUID1 })
140 await servers[0].playlists.get({ playlistId: playlistUUID2 })
142 await waitJobs(servers)
144 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
145 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
149 after(async function () {
152 await cleanupTests(servers)