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