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