]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { wait } from '@shared/core-utils' | |
6 | import { VideoPrivacy } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | waitJobs | |
14 | } from '@shared/server-commands' | |
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 () { | |
26 | let servers: PeerTubeServer[] = [] | |
27 | let video2UUID: string | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | // Run servers | |
33 | servers = await createMultipleServers(2) | |
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 | ||
43 | const attributes = { | |
44 | name: 'video 1', | |
45 | privacy: VideoPrivacy.PRIVATE, | |
46 | scheduleUpdate: { | |
47 | updateAt: in10Seconds().toISOString(), | |
48 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | |
49 | } | |
50 | } | |
51 | ||
52 | await servers[0].videos.upload({ attributes }) | |
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) { | |
59 | const { total } = await server.videos.list() | |
60 | ||
61 | expect(total).to.equal(0) | |
62 | } | |
63 | }) | |
64 | ||
65 | it('Should have my scheduled video in my account videos', async function () { | |
66 | const { total, data } = await servers[0].videos.listMyVideos() | |
67 | expect(total).to.equal(1) | |
68 | ||
69 | const videoFromList = data[0] | |
70 | const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) | |
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 | } | |
78 | }) | |
79 | ||
80 | it('Should wait some seconds and have the video in public privacy', async function () { | |
81 | this.timeout(50000) | |
82 | ||
83 | await wait(15000) | |
84 | await waitJobs(servers) | |
85 | ||
86 | for (const server of servers) { | |
87 | const { total, data } = await server.videos.list() | |
88 | ||
89 | expect(total).to.equal(1) | |
90 | expect(data[0].name).to.equal('video 1') | |
91 | } | |
92 | }) | |
93 | ||
94 | it('Should upload a video without scheduling an update', async function () { | |
95 | this.timeout(10000) | |
96 | ||
97 | const attributes = { | |
98 | name: 'video 2', | |
99 | privacy: VideoPrivacy.PRIVATE | |
100 | } | |
101 | ||
102 | const { uuid } = await servers[0].videos.upload({ attributes }) | |
103 | video2UUID = uuid | |
104 | ||
105 | await waitJobs(servers) | |
106 | }) | |
107 | ||
108 | it('Should update a video by scheduling an update', async function () { | |
109 | this.timeout(10000) | |
110 | ||
111 | const attributes = { | |
112 | name: 'video 2 updated', | |
113 | scheduleUpdate: { | |
114 | updateAt: in10Seconds().toISOString(), | |
115 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC | |
116 | } | |
117 | } | |
118 | ||
119 | await servers[0].videos.update({ id: video2UUID, attributes }) | |
120 | await waitJobs(servers) | |
121 | }) | |
122 | ||
123 | it('Should not display the updated video', async function () { | |
124 | for (const server of servers) { | |
125 | const { total } = await server.videos.list() | |
126 | ||
127 | expect(total).to.equal(1) | |
128 | } | |
129 | }) | |
130 | ||
131 | it('Should have my scheduled updated video in my account videos', async function () { | |
132 | const { total, data } = await servers[0].videos.listMyVideos() | |
133 | expect(total).to.equal(2) | |
134 | ||
135 | const video = data.find(v => v.uuid === video2UUID) | |
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 | ||
148 | await wait(15000) | |
149 | await waitJobs(servers) | |
150 | ||
151 | for (const server of servers) { | |
152 | const { total, data } = await server.videos.list() | |
153 | expect(total).to.equal(2) | |
154 | ||
155 | const video = data.find(v => v.uuid === video2UUID) | |
156 | expect(video).not.to.be.undefined | |
157 | expect(video.name).to.equal('video 2 updated') | |
158 | } | |
159 | }) | |
160 | ||
161 | after(async function () { | |
162 | await cleanupTests(servers) | |
163 | }) | |
164 | }) |