]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/activitypub/refresher.ts
Introduce channels command
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
04b8c3fb
C
2
3import 'mocha'
9fff08cf 4import { HttpStatusCode } from '@shared/core-utils'
2a8c5d0a 5import {
9fff08cf
C
6 cleanupTests,
7 closeAllSequelize,
2a8c5d0a
C
8 doubleFollow,
9 flushAndRunMultipleServers,
9f79ade6 10 generateUserAccessToken,
2a8c5d0a 11 getVideo,
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
9fff08cf
C
24} from '@shared/extra-utils'
25import { VideoPlaylistPrivacy } from '@shared/models'
04b8c3fb
C
26
27describe('Test AP refresher', function () {
28 let servers: ServerInfo[] = []
29 let videoUUID1: string
30 let videoUUID2: string
31 let videoUUID3: string
9f79ade6
C
32 let playlistUUID1: string
33 let playlistUUID2: string
04b8c3fb
C
34
35 before(async function () {
89ada4e2 36 this.timeout(60000)
04b8c3fb 37
9f79ade6 38 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
04b8c3fb
C
39
40 // Get the access tokens
41 await setAccessTokensToServers(servers)
9f79ade6
C
42 await setDefaultVideoChannel(servers)
43
44 {
a1587156
C
45 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
46 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
47 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
9f79ade6 48 }
04b8c3fb
C
49
50 {
a1587156
C
51 const a1 = await generateUserAccessToken(servers[1], 'user1')
52 await uploadVideo(servers[1].url, a1, { name: 'video4' })
9f79ade6 53
a1587156
C
54 const a2 = await generateUserAccessToken(servers[1], 'user2')
55 await uploadVideo(servers[1].url, a2, { name: 'video5' })
04b8c3fb
C
56 }
57
58 {
e6346d59
C
59 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
60 const created = await servers[1].playlistsCommand.create({ attributes })
61 playlistUUID1 = created.uuid
04b8c3fb
C
62 }
63
64 {
e6346d59
C
65 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
66 const created = await servers[1].playlistsCommand.create({ attributes })
67 playlistUUID2 = created.uuid
04b8c3fb
C
68 }
69
a1587156 70 await doubleFollow(servers[0], servers[1])
04b8c3fb
C
71 })
72
9f79ade6
C
73 describe('Videos refresher', function () {
74
75 it('Should remove a deleted remote video', async function () {
76 this.timeout(60000)
77
78 await wait(10000)
79
80 // Change UUID so the remote server returns a 404
a1587156 81 await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
9f79ade6 82
a1587156
C
83 await getVideo(servers[0].url, videoUUID1)
84 await getVideo(servers[0].url, videoUUID2)
9f79ade6
C
85
86 await waitJobs(servers)
04b8c3fb 87
f2eb23cd
RK
88 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
89 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
9f79ade6 90 })
04b8c3fb 91
9f79ade6 92 it('Should not update a remote video if the remote instance is down', async function () {
6848b9f4 93 this.timeout(70000)
04b8c3fb 94
a1587156 95 killallServers([ servers[1] ])
04b8c3fb 96
a1587156 97 await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
04b8c3fb 98
9f79ade6
C
99 // Video will need a refresh
100 await wait(10000)
101
a1587156 102 await getVideo(servers[0].url, videoUUID3)
9f79ade6 103 // The refresh should fail
a1587156 104 await waitJobs([ servers[0] ])
9f79ade6 105
a1587156 106 await reRunServer(servers[1])
9f79ade6 107
f2eb23cd 108 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
9f79ade6 109 })
04b8c3fb
C
110 })
111
9f79ade6
C
112 describe('Actors refresher', function () {
113
114 it('Should remove a deleted actor', async function () {
115 this.timeout(60000)
116
9fff08cf
C
117 const command = servers[0].accountsCommand
118
9f79ade6
C
119 await wait(10000)
120
121 // Change actor name so the remote server returns a 404
a1587156
C
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
9f79ade6 124
9fff08cf
C
125 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
126 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
9f79ade6
C
127
128 await waitJobs(servers)
129
9fff08cf
C
130 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
131 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
9f79ade6
C
132 })
133 })
04b8c3fb 134
9f79ade6 135 describe('Playlist refresher', function () {
04b8c3fb 136
9f79ade6
C
137 it('Should remove a deleted playlist', async function () {
138 this.timeout(60000)
04b8c3fb 139
9f79ade6 140 await wait(10000)
04b8c3fb 141
9f79ade6 142 // Change UUID so the remote server returns a 404
a1587156 143 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
04b8c3fb 144
e6346d59
C
145 await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
146 await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
04b8c3fb 147
9f79ade6 148 await waitJobs(servers)
04b8c3fb 149
e6346d59
C
150 await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
151 await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
9f79ade6 152 })
04b8c3fb
C
153 })
154
48f07b4a
C
155 after(async function () {
156 this.timeout(10000)
157
158 await cleanupTests(servers)
159
160 await closeAllSequelize(servers)
04b8c3fb
C
161 })
162})