1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
15 } from '@shared/extra-utils'
16 import { VideoPlaylistPrivacy } from '@shared/models'
18 describe('Test AP refresher', function () {
19 let servers: PeerTubeServer[] = []
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, { transcoding: { enabled: false } })
31 // Get the access tokens
32 await setAccessTokensToServers(servers)
33 await setDefaultVideoChannel(servers)
36 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
37 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
38 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
42 const token1 = await servers[1].users.generateUserAndToken('user1')
43 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
45 const token2 = await servers[1].users.generateUserAndToken('user2')
46 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
50 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
51 const created = await servers[1].playlists.create({ attributes })
52 playlistUUID1 = created.uuid
56 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
57 const created = await servers[1].playlists.create({ attributes })
58 playlistUUID2 = created.uuid
61 await doubleFollow(servers[0], servers[1])
64 describe('Videos refresher', function () {
66 it('Should remove a deleted remote video', async function () {
71 // Change UUID so the remote server returns a 404
72 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
74 await servers[0].videos.get({ id: videoUUID1 })
75 await servers[0].videos.get({ id: videoUUID2 })
77 await waitJobs(servers)
79 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
80 await servers[0].videos.get({ id: videoUUID2 })
83 it('Should not update a remote video if the remote instance is down', async function () {
86 await killallServers([ servers[1] ])
88 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
90 // Video will need a refresh
93 await servers[0].videos.get({ id: videoUUID3 })
94 // The refresh should fail
95 await waitJobs([ servers[0] ])
97 await servers[1].run()
99 await servers[0].videos.get({ id: videoUUID3 })
103 describe('Actors refresher', function () {
105 it('Should remove a deleted actor', async function () {
108 const command = servers[0].accounts
112 // Change actor name so the remote server returns a 404
113 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
114 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
116 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
117 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
119 await waitJobs(servers)
121 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
122 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
126 describe('Playlist refresher', function () {
128 it('Should remove a deleted playlist', async function () {
133 // Change UUID so the remote server returns a 404
134 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
136 await servers[0].playlists.get({ playlistId: playlistUUID1 })
137 await servers[0].playlists.get({ playlistId: playlistUUID2 })
139 await waitJobs(servers)
141 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
142 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
146 after(async function () {
149 await cleanupTests(servers)