]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2baea0c7 | 2 | |
2baea0c7 | 3 | import 'mocha' |
d23dd9fb | 4 | import * as chai from 'chai' |
c55e3d72 C |
5 | import { wait } from '@shared/core-utils' |
6 | import { VideoPrivacy } from '@shared/models' | |
2baea0c7 | 7 | import { |
7c3b7976 | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
bbe0f064 | 12 | setAccessTokensToServers, |
d23dd9fb | 13 | waitJobs |
bf54587a | 14 | } from '@shared/server-commands' |
2baea0c7 C |
15 | |
16 | const expect = chai.expect | |
17 | ||
18 | function in10Seconds () { | |
19 | const now = new Date() | |
20 | now.setSeconds(now.getSeconds() + 10) | |
21 | ||
22 | return now | |
23 | } | |
24 | ||
25 | describe('Test video update scheduler', function () { | |
254d3579 | 26 | let servers: PeerTubeServer[] = [] |
2baea0c7 C |
27 | let video2UUID: string |
28 | ||
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | // Run servers | |
254d3579 | 33 | servers = await createMultipleServers(2) |
2baea0c7 C |
34 | |
35 | await setAccessTokensToServers(servers) | |
36 | ||
37 | await doubleFollow(servers[0], servers[1]) | |
38 | }) | |
39 | ||
40 | it('Should upload a video and schedule an update in 10 seconds', async function () { | |
41 | this.timeout(10000) | |
42 | ||
d23dd9fb | 43 | const attributes = { |
2baea0c7 C |
44 | name: 'video 1', |
45 | privacy: VideoPrivacy.PRIVATE, | |
46 | scheduleUpdate: { | |
47 | updateAt: in10Seconds().toISOString(), | |
d23dd9fb | 48 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
2baea0c7 C |
49 | } |
50 | } | |
51 | ||
89d241a7 | 52 | await servers[0].videos.upload({ attributes }) |
2baea0c7 C |
53 | |
54 | await waitJobs(servers) | |
55 | }) | |
56 | ||
57 | it('Should not list the video (in privacy mode)', async function () { | |
58 | for (const server of servers) { | |
89d241a7 | 59 | const { total } = await server.videos.list() |
2baea0c7 | 60 | |
d23dd9fb | 61 | expect(total).to.equal(0) |
2baea0c7 C |
62 | } |
63 | }) | |
64 | ||
65 | it('Should have my scheduled video in my account videos', async function () { | |
89d241a7 | 66 | const { total, data } = await servers[0].videos.listMyVideos() |
d23dd9fb | 67 | expect(total).to.equal(1) |
2baea0c7 | 68 | |
d23dd9fb | 69 | const videoFromList = data[0] |
89d241a7 | 70 | const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) |
bbe0f064 C |
71 | |
72 | for (const video of [ videoFromList, videoFromGet ]) { | |
73 | expect(video.name).to.equal('video 1') | |
74 | expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE) | |
75 | expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date()) | |
76 | expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC) | |
77 | } | |
2baea0c7 C |
78 | }) |
79 | ||
80 | it('Should wait some seconds and have the video in public privacy', async function () { | |
2284f202 | 81 | this.timeout(50000) |
2baea0c7 | 82 | |
bbe0f064 | 83 | await wait(15000) |
2baea0c7 C |
84 | await waitJobs(servers) |
85 | ||
86 | for (const server of servers) { | |
89d241a7 | 87 | const { total, data } = await server.videos.list() |
2baea0c7 | 88 | |
d23dd9fb C |
89 | expect(total).to.equal(1) |
90 | expect(data[0].name).to.equal('video 1') | |
2baea0c7 C |
91 | } |
92 | }) | |
93 | ||
94 | it('Should upload a video without scheduling an update', async function () { | |
95 | this.timeout(10000) | |
96 | ||
d23dd9fb | 97 | const attributes = { |
2baea0c7 C |
98 | name: 'video 2', |
99 | privacy: VideoPrivacy.PRIVATE | |
100 | } | |
101 | ||
89d241a7 | 102 | const { uuid } = await servers[0].videos.upload({ attributes }) |
d23dd9fb | 103 | video2UUID = uuid |
2baea0c7 C |
104 | |
105 | await waitJobs(servers) | |
106 | }) | |
107 | ||
108 | it('Should update a video by scheduling an update', async function () { | |
109 | this.timeout(10000) | |
110 | ||
d23dd9fb | 111 | const attributes = { |
2baea0c7 C |
112 | name: 'video 2 updated', |
113 | scheduleUpdate: { | |
114 | updateAt: in10Seconds().toISOString(), | |
d23dd9fb | 115 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
2baea0c7 C |
116 | } |
117 | } | |
118 | ||
89d241a7 | 119 | await servers[0].videos.update({ id: video2UUID, attributes }) |
2baea0c7 C |
120 | await waitJobs(servers) |
121 | }) | |
122 | ||
123 | it('Should not display the updated video', async function () { | |
124 | for (const server of servers) { | |
89d241a7 | 125 | const { total } = await server.videos.list() |
2baea0c7 | 126 | |
d23dd9fb | 127 | expect(total).to.equal(1) |
2baea0c7 C |
128 | } |
129 | }) | |
130 | ||
131 | it('Should have my scheduled updated video in my account videos', async function () { | |
89d241a7 | 132 | const { total, data } = await servers[0].videos.listMyVideos() |
d23dd9fb | 133 | expect(total).to.equal(2) |
2baea0c7 | 134 | |
d23dd9fb | 135 | const video = data.find(v => v.uuid === video2UUID) |
2baea0c7 C |
136 | expect(video).not.to.be.undefined |
137 | ||
138 | expect(video.name).to.equal('video 2 updated') | |
139 | expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE) | |
140 | ||
141 | expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date()) | |
142 | expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC) | |
143 | }) | |
144 | ||
145 | it('Should wait some seconds and have the updated video in public privacy', async function () { | |
146 | this.timeout(20000) | |
147 | ||
bbe0f064 | 148 | await wait(15000) |
2baea0c7 C |
149 | await waitJobs(servers) |
150 | ||
151 | for (const server of servers) { | |
89d241a7 | 152 | const { total, data } = await server.videos.list() |
d23dd9fb | 153 | expect(total).to.equal(2) |
2baea0c7 | 154 | |
d23dd9fb | 155 | const video = data.find(v => v.uuid === video2UUID) |
2baea0c7 C |
156 | expect(video).not.to.be.undefined |
157 | expect(video.name).to.equal('video 2 updated') | |
158 | } | |
159 | }) | |
160 | ||
7c3b7976 C |
161 | after(async function () { |
162 | await cleanupTests(servers) | |
2baea0c7 C |
163 | }) |
164 | }) |