1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
14 } from '@shared/extra-utils'
15 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
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, { transcoding: { enabled: false } })
30 // Get the access tokens
31 await setAccessTokensToServers(servers)
32 await setDefaultVideoChannel(servers)
35 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
36 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
37 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
41 const token1 = await servers[1].users.generateUserAndToken('user1')
42 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
44 const token2 = await servers[1].users.generateUserAndToken('user2')
45 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
49 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
50 const created = await servers[1].playlists.create({ attributes })
51 playlistUUID1 = created.uuid
55 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
56 const created = await servers[1].playlists.create({ attributes })
57 playlistUUID2 = created.uuid
60 await doubleFollow(servers[0], servers[1])
63 describe('Videos refresher', function () {
65 it('Should remove a deleted remote video', async function () {
70 // Change UUID so the remote server returns a 404
71 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
73 await servers[0].videos.get({ id: videoUUID1 })
74 await servers[0].videos.get({ id: videoUUID2 })
76 await waitJobs(servers)
78 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
79 await servers[0].videos.get({ id: videoUUID2 })
82 it('Should not update a remote video if the remote instance is down', async function () {
85 await killallServers([ servers[1] ])
87 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
89 // Video will need a refresh
92 await servers[0].videos.get({ id: videoUUID3 })
93 // The refresh should fail
94 await waitJobs([ servers[0] ])
96 await servers[1].run()
98 await servers[0].videos.get({ id: videoUUID3 })
102 describe('Actors refresher', function () {
104 it('Should remove a deleted actor', async function () {
107 const command = servers[0].accounts
111 // Change actor name so the remote server returns a 404
112 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
113 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
115 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
116 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
118 await waitJobs(servers)
120 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
121 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
125 describe('Playlist refresher', function () {
127 it('Should remove a deleted playlist', async function () {
132 // Change UUID so the remote server returns a 404
133 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
135 await servers[0].playlists.get({ playlistId: playlistUUID1 })
136 await servers[0].playlists.get({ playlistId: playlistUUID2 })
138 await waitJobs(servers)
140 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
141 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
145 after(async function () {
148 await cleanupTests(servers)