diff options
Diffstat (limited to 'packages/tests/src/api/videos/video-schedule-update.ts')
-rw-r--r-- | packages/tests/src/api/videos/video-schedule-update.ts | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/packages/tests/src/api/videos/video-schedule-update.ts b/packages/tests/src/api/videos/video-schedule-update.ts new file mode 100644 index 000000000..96d71933e --- /dev/null +++ b/packages/tests/src/api/videos/video-schedule-update.ts | |||
@@ -0,0 +1,155 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { wait } from '@peertube/peertube-core-utils' | ||
5 | import { VideoPrivacy } from '@peertube/peertube-models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | waitJobs | ||
13 | } from '@peertube/peertube-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 | const attributes = { | ||
39 | name: 'video 1', | ||
40 | privacy: VideoPrivacy.PRIVATE, | ||
41 | scheduleUpdate: { | ||
42 | updateAt: in10Seconds().toISOString(), | ||
43 | privacy: VideoPrivacy.PUBLIC | ||
44 | } | ||
45 | } | ||
46 | |||
47 | await servers[0].videos.upload({ attributes }) | ||
48 | |||
49 | await waitJobs(servers) | ||
50 | }) | ||
51 | |||
52 | it('Should not list the video (in privacy mode)', async function () { | ||
53 | for (const server of servers) { | ||
54 | const { total } = await server.videos.list() | ||
55 | |||
56 | expect(total).to.equal(0) | ||
57 | } | ||
58 | }) | ||
59 | |||
60 | it('Should have my scheduled video in my account videos', async function () { | ||
61 | const { total, data } = await servers[0].videos.listMyVideos() | ||
62 | expect(total).to.equal(1) | ||
63 | |||
64 | const videoFromList = data[0] | ||
65 | const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) | ||
66 | |||
67 | for (const video of [ videoFromList, videoFromGet ]) { | ||
68 | expect(video.name).to.equal('video 1') | ||
69 | expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE) | ||
70 | expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date()) | ||
71 | expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC) | ||
72 | } | ||
73 | }) | ||
74 | |||
75 | it('Should wait some seconds and have the video in public privacy', async function () { | ||
76 | this.timeout(50000) | ||
77 | |||
78 | await wait(15000) | ||
79 | await waitJobs(servers) | ||
80 | |||
81 | for (const server of servers) { | ||
82 | const { total, data } = await server.videos.list() | ||
83 | |||
84 | expect(total).to.equal(1) | ||
85 | expect(data[0].name).to.equal('video 1') | ||
86 | } | ||
87 | }) | ||
88 | |||
89 | it('Should upload a video without scheduling an update', async function () { | ||
90 | const attributes = { | ||
91 | name: 'video 2', | ||
92 | privacy: VideoPrivacy.PRIVATE | ||
93 | } | ||
94 | |||
95 | const { uuid } = await servers[0].videos.upload({ attributes }) | ||
96 | video2UUID = uuid | ||
97 | |||
98 | await waitJobs(servers) | ||
99 | }) | ||
100 | |||
101 | it('Should update a video by scheduling an update', async function () { | ||
102 | const attributes = { | ||
103 | name: 'video 2 updated', | ||
104 | scheduleUpdate: { | ||
105 | updateAt: in10Seconds().toISOString(), | ||
106 | privacy: VideoPrivacy.PUBLIC | ||
107 | } | ||
108 | } | ||
109 | |||
110 | await servers[0].videos.update({ id: video2UUID, attributes }) | ||
111 | await waitJobs(servers) | ||
112 | }) | ||
113 | |||
114 | it('Should not display the updated video', async function () { | ||
115 | for (const server of servers) { | ||
116 | const { total } = await server.videos.list() | ||
117 | |||
118 | expect(total).to.equal(1) | ||
119 | } | ||
120 | }) | ||
121 | |||
122 | it('Should have my scheduled updated video in my account videos', async function () { | ||
123 | const { total, data } = await servers[0].videos.listMyVideos() | ||
124 | expect(total).to.equal(2) | ||
125 | |||
126 | const video = data.find(v => v.uuid === video2UUID) | ||
127 | expect(video).not.to.be.undefined | ||
128 | |||
129 | expect(video.name).to.equal('video 2 updated') | ||
130 | expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE) | ||
131 | |||
132 | expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date()) | ||
133 | expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC) | ||
134 | }) | ||
135 | |||
136 | it('Should wait some seconds and have the updated video in public privacy', async function () { | ||
137 | this.timeout(20000) | ||
138 | |||
139 | await wait(15000) | ||
140 | await waitJobs(servers) | ||
141 | |||
142 | for (const server of servers) { | ||
143 | const { total, data } = await server.videos.list() | ||
144 | expect(total).to.equal(2) | ||
145 | |||
146 | const video = data.find(v => v.uuid === video2UUID) | ||
147 | expect(video).not.to.be.undefined | ||
148 | expect(video.name).to.equal('video 2 updated') | ||
149 | } | ||
150 | }) | ||
151 | |||
152 | after(async function () { | ||
153 | await cleanupTests(servers) | ||
154 | }) | ||
155 | }) | ||