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