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