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