]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/activitypub/refresher.ts
Correctly fix octet stream fallback for video ext
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
CommitLineData
04b8c3fb
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
2a8c5d0a 4import {
48f07b4a 5 cleanupTests, closeAllSequelize,
9f79ade6 6 createVideoPlaylist,
2a8c5d0a
C
7 doubleFollow,
8 flushAndRunMultipleServers,
9f79ade6 9 generateUserAccessToken,
2a8c5d0a 10 getVideo,
9f79ade6 11 getVideoPlaylist,
48f07b4a 12 killallServers,
2a8c5d0a
C
13 reRunServer,
14 ServerInfo,
15 setAccessTokensToServers,
9f79ade6
C
16 setActorField,
17 setDefaultVideoChannel,
18 setPlaylistField,
19 setVideoField,
2a8c5d0a 20 uploadVideo,
9f79ade6 21 uploadVideoAndGetId,
2a8c5d0a 22 wait,
2a8c5d0a 23 waitJobs
94565d52
C
24} from '../../../../shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts'
9f79ade6 26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
04b8c3fb
C
27
28describe('Test AP refresher', function () {
29 let servers: ServerInfo[] = []
30 let videoUUID1: string
31 let videoUUID2: string
32 let videoUUID3: string
9f79ade6
C
33 let playlistUUID1: string
34 let playlistUUID2: string
04b8c3fb
C
35
36 before(async function () {
89ada4e2 37 this.timeout(60000)
04b8c3fb 38
9f79ade6 39 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
04b8c3fb
C
40
41 // Get the access tokens
42 await setAccessTokensToServers(servers)
9f79ade6
C
43 await setDefaultVideoChannel(servers)
44
45 {
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
49 }
04b8c3fb
C
50
51 {
48f07b4a
C
52 const a1 = await generateUserAccessToken(servers[ 1 ], 'user1')
53 await uploadVideo(servers[ 1 ].url, a1, { name: 'video4' })
9f79ade6 54
48f07b4a
C
55 const a2 = await generateUserAccessToken(servers[ 1 ], 'user2')
56 await uploadVideo(servers[ 1 ].url, a2, { name: 'video5' })
04b8c3fb
C
57 }
58
59 {
48f07b4a
C
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 })
9f79ade6 62 playlistUUID1 = res.body.videoPlaylist.uuid
04b8c3fb
C
63 }
64
65 {
48f07b4a
C
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 })
9f79ade6 68 playlistUUID2 = res.body.videoPlaylist.uuid
04b8c3fb
C
69 }
70
48f07b4a 71 await doubleFollow(servers[ 0 ], servers[ 1 ])
04b8c3fb
C
72 })
73
9f79ade6
C
74 describe('Videos refresher', function () {
75
76 it('Should remove a deleted remote video', async function () {
77 this.timeout(60000)
78
79 await wait(10000)
80
81 // Change UUID so the remote server returns a 404
48f07b4a 82 await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
9f79ade6
C
83
84 await getVideo(servers[ 0 ].url, videoUUID1)
85 await getVideo(servers[ 0 ].url, videoUUID2)
86
87 await waitJobs(servers)
04b8c3fb 88
9f79ade6
C
89 await getVideo(servers[ 0 ].url, videoUUID1, 404)
90 await getVideo(servers[ 0 ].url, videoUUID2, 200)
91 })
04b8c3fb 92
9f79ade6 93 it('Should not update a remote video if the remote instance is down', async function () {
6848b9f4 94 this.timeout(70000)
04b8c3fb 95
9f79ade6 96 killallServers([ servers[ 1 ] ])
04b8c3fb 97
48f07b4a 98 await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
04b8c3fb 99
9f79ade6
C
100 // Video will need a refresh
101 await wait(10000)
102
103 await getVideo(servers[ 0 ].url, videoUUID3)
104 // The refresh should fail
105 await waitJobs([ servers[ 0 ] ])
106
107 await reRunServer(servers[ 1 ])
108
9f79ade6
C
109 await getVideo(servers[ 0 ].url, videoUUID3, 200)
110 })
04b8c3fb
C
111 })
112
9f79ade6
C
113 describe('Actors refresher', function () {
114
115 it('Should remove a deleted actor', async function () {
116 this.timeout(60000)
117
118 await wait(10000)
119
120 // Change actor name so the remote server returns a 404
48f07b4a
C
121 const to = 'http://localhost:' + servers[ 1 ].port + '/accounts/user2'
122 await setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto')
9f79ade6 123
48f07b4a
C
124 await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port)
125 await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port)
9f79ade6
C
126
127 await waitJobs(servers)
128
48f07b4a
C
129 await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200)
130 await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404)
9f79ade6
C
131 })
132 })
04b8c3fb 133
9f79ade6 134 describe('Playlist refresher', function () {
04b8c3fb 135
9f79ade6
C
136 it('Should remove a deleted playlist', async function () {
137 this.timeout(60000)
04b8c3fb 138
9f79ade6 139 await wait(10000)
04b8c3fb 140
9f79ade6 141 // Change UUID so the remote server returns a 404
48f07b4a 142 await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
04b8c3fb 143
9f79ade6
C
144 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
145 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
04b8c3fb 146
9f79ade6 147 await waitJobs(servers)
04b8c3fb 148
9f79ade6
C
149 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
150 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
151 })
04b8c3fb
C
152 })
153
48f07b4a
C
154 after(async function () {
155 this.timeout(10000)
156
157 await cleanupTests(servers)
158
159 await closeAllSequelize(servers)
04b8c3fb
C
160 })
161})