1 /* tslint:disable:no-unused-expression */
5 cleanupTests, closeAllSequelize,
8 flushAndRunMultipleServers,
9 generateUserAccessToken,
15 setAccessTokensToServers,
17 setDefaultVideoChannel,
24 } from '../../../../shared/extra-utils'
25 import { getAccount } from '../../../../shared/extra-utils/users/accounts'
26 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
28 describe('Test AP refresher', function () {
29 let servers: ServerInfo[] = []
30 let videoUUID1: string
31 let videoUUID2: string
32 let videoUUID3: string
33 let playlistUUID1: string
34 let playlistUUID2: string
36 before(async function () {
39 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
41 // Get the access tokens
42 await setAccessTokensToServers(servers)
43 await setDefaultVideoChannel(servers)
46 videoUUID1 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video1' })).uuid
47 videoUUID2 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video2' })).uuid
48 videoUUID3 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video3' })).uuid
52 const a1 = await generateUserAccessToken(servers[ 1 ], 'user1')
53 await uploadVideo(servers[ 1 ].url, a1, { name: 'video4' })
55 const a2 = await generateUserAccessToken(servers[ 1 ], 'user2')
56 await uploadVideo(servers[ 1 ].url, a2, { name: 'video5' })
60 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
61 const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
62 playlistUUID1 = res.body.videoPlaylist.uuid
66 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
67 const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
68 playlistUUID2 = res.body.videoPlaylist.uuid
71 await doubleFollow(servers[ 0 ], servers[ 1 ])
74 describe('Videos refresher', function () {
76 it('Should remove a deleted remote video', async function () {
81 // Change UUID so the remote server returns a 404
82 await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
84 await getVideo(servers[ 0 ].url, videoUUID1)
85 await getVideo(servers[ 0 ].url, videoUUID2)
87 await waitJobs(servers)
89 await getVideo(servers[ 0 ].url, videoUUID1, 404)
90 await getVideo(servers[ 0 ].url, videoUUID2, 200)
93 it('Should not update a remote video if the remote instance is down', async function () {
96 killallServers([ servers[ 1 ] ])
98 await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
100 // Video will need a refresh
103 await getVideo(servers[ 0 ].url, videoUUID3)
104 // The refresh should fail
105 await waitJobs([ servers[ 0 ] ])
107 await reRunServer(servers[ 1 ])
109 // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
110 await getVideo(servers[ 0 ].url, videoUUID3)
111 await waitJobs(servers)
113 await getVideo(servers[ 0 ].url, videoUUID3, 200)
117 describe('Actors refresher', function () {
119 it('Should remove a deleted actor', async function () {
124 // Change actor name so the remote server returns a 404
125 const to = 'http://localhost:' + servers[ 1 ].port + '/accounts/user2'
126 await setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto')
128 await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port)
129 await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port)
131 await waitJobs(servers)
133 await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200)
134 await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404)
138 describe('Playlist refresher', function () {
140 it('Should remove a deleted playlist', async function () {
145 // Change UUID so the remote server returns a 404
146 await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
148 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
149 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
151 await waitJobs(servers)
153 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
154 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
158 after(async function () {
161 await cleanupTests(servers)
163 await closeAllSequelize(servers)