1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { SQLCommand } from '@server/tests/shared'
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 sqlCommandServer2: SQLCommand
20 let videoUUID1: string
21 let videoUUID2: string
22 let videoUUID3: string
23 let playlistUUID1: string
24 let playlistUUID2: string
26 before(async function () {
29 servers = await createMultipleServers(2)
31 // Get the access tokens
32 await setAccessTokensToServers(servers)
33 await setDefaultVideoChannel(servers)
35 for (const server of servers) {
36 await server.config.disableTranscoding()
40 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
41 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
42 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
46 const token1 = await servers[1].users.generateUserAndToken('user1')
47 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
49 const token2 = await servers[1].users.generateUserAndToken('user2')
50 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
54 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
55 const created = await servers[1].playlists.create({ attributes })
56 playlistUUID1 = created.uuid
60 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
61 const created = await servers[1].playlists.create({ attributes })
62 playlistUUID2 = created.uuid
65 await doubleFollow(servers[0], servers[1])
67 sqlCommandServer2 = new SQLCommand(servers[1])
70 describe('Videos refresher', function () {
72 it('Should remove a deleted remote video', async function () {
77 // Change UUID so the remote server returns a 404
78 await sqlCommandServer2.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
80 await servers[0].videos.get({ id: videoUUID1 })
81 await servers[0].videos.get({ id: videoUUID2 })
83 await waitJobs(servers)
85 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
86 await servers[0].videos.get({ id: videoUUID2 })
89 it('Should not update a remote video if the remote instance is down', async function () {
92 await killallServers([ servers[1] ])
94 await sqlCommandServer2.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
96 // Video will need a refresh
99 await servers[0].videos.get({ id: videoUUID3 })
100 // The refresh should fail
101 await waitJobs([ servers[0] ])
103 await servers[1].run()
105 await servers[0].videos.get({ id: videoUUID3 })
109 describe('Actors refresher', function () {
111 it('Should remove a deleted actor', async function () {
114 const command = servers[0].accounts
118 // Change actor name so the remote server returns a 404
119 const to = servers[1].url + '/accounts/user2'
120 await sqlCommandServer2.setActorField(to, 'preferredUsername', 'toto')
122 await command.get({ accountName: 'user1@' + servers[1].host })
123 await command.get({ accountName: 'user2@' + servers[1].host })
125 await waitJobs(servers)
127 await command.get({ accountName: 'user1@' + servers[1].host, expectedStatus: HttpStatusCode.OK_200 })
128 await command.get({ accountName: 'user2@' + servers[1].host, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
132 describe('Playlist refresher', function () {
134 it('Should remove a deleted playlist', async function () {
139 // Change UUID so the remote server returns a 404
140 await sqlCommandServer2.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
142 await servers[0].playlists.get({ playlistId: playlistUUID1 })
143 await servers[0].playlists.get({ playlistId: playlistUUID2 })
145 await waitJobs(servers)
147 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
148 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
152 after(async function () {
155 await sqlCommandServer2.cleanup()
157 await cleanupTests(servers)