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