]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2baea0c7 | 2 | |
86347717 | 3 | import { expect } from 'chai' |
c55e3d72 C |
4 | import { wait } from '@shared/core-utils' |
5 | import { VideoPrivacy } from '@shared/models' | |
2baea0c7 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
254d3579 | 8 | createMultipleServers, |
4c7e60bc | 9 | doubleFollow, |
254d3579 | 10 | PeerTubeServer, |
bbe0f064 | 11 | setAccessTokensToServers, |
d23dd9fb | 12 | waitJobs |
bf54587a | 13 | } from '@shared/server-commands' |
2baea0c7 | 14 | |
2baea0c7 C |
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 () { | |
254d3579 | 23 | let servers: PeerTubeServer[] = [] |
2baea0c7 C |
24 | let video2UUID: string |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
29 | // Run servers | |
254d3579 | 30 | servers = await createMultipleServers(2) |
2baea0c7 C |
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 () { | |
d23dd9fb | 38 | const attributes = { |
2baea0c7 C |
39 | name: 'video 1', |
40 | privacy: VideoPrivacy.PRIVATE, | |
41 | scheduleUpdate: { | |
42 | updateAt: in10Seconds().toISOString(), | |
d23dd9fb | 43 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
2baea0c7 C |
44 | } |
45 | } | |
46 | ||
89d241a7 | 47 | await servers[0].videos.upload({ attributes }) |
2baea0c7 C |
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) { | |
89d241a7 | 54 | const { total } = await server.videos.list() |
2baea0c7 | 55 | |
d23dd9fb | 56 | expect(total).to.equal(0) |
2baea0c7 C |
57 | } |
58 | }) | |
59 | ||
60 | it('Should have my scheduled video in my account videos', async function () { | |
89d241a7 | 61 | const { total, data } = await servers[0].videos.listMyVideos() |
d23dd9fb | 62 | expect(total).to.equal(1) |
2baea0c7 | 63 | |
d23dd9fb | 64 | const videoFromList = data[0] |
89d241a7 | 65 | const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) |
bbe0f064 C |
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 | } | |
2baea0c7 C |
73 | }) |
74 | ||
75 | it('Should wait some seconds and have the video in public privacy', async function () { | |
2284f202 | 76 | this.timeout(50000) |
2baea0c7 | 77 | |
bbe0f064 | 78 | await wait(15000) |
2baea0c7 C |
79 | await waitJobs(servers) |
80 | ||
81 | for (const server of servers) { | |
89d241a7 | 82 | const { total, data } = await server.videos.list() |
2baea0c7 | 83 | |
d23dd9fb C |
84 | expect(total).to.equal(1) |
85 | expect(data[0].name).to.equal('video 1') | |
2baea0c7 C |
86 | } |
87 | }) | |
88 | ||
89 | it('Should upload a video without scheduling an update', async function () { | |
d23dd9fb | 90 | const attributes = { |
2baea0c7 C |
91 | name: 'video 2', |
92 | privacy: VideoPrivacy.PRIVATE | |
93 | } | |
94 | ||
89d241a7 | 95 | const { uuid } = await servers[0].videos.upload({ attributes }) |
d23dd9fb | 96 | video2UUID = uuid |
2baea0c7 C |
97 | |
98 | await waitJobs(servers) | |
99 | }) | |
100 | ||
101 | it('Should update a video by scheduling an update', async function () { | |
d23dd9fb | 102 | const attributes = { |
2baea0c7 C |
103 | name: 'video 2 updated', |
104 | scheduleUpdate: { | |
105 | updateAt: in10Seconds().toISOString(), | |
d23dd9fb | 106 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
2baea0c7 C |
107 | } |
108 | } | |
109 | ||
89d241a7 | 110 | await servers[0].videos.update({ id: video2UUID, attributes }) |
2baea0c7 C |
111 | await waitJobs(servers) |
112 | }) | |
113 | ||
114 | it('Should not display the updated video', async function () { | |
115 | for (const server of servers) { | |
89d241a7 | 116 | const { total } = await server.videos.list() |
2baea0c7 | 117 | |
d23dd9fb | 118 | expect(total).to.equal(1) |
2baea0c7 C |
119 | } |
120 | }) | |
121 | ||
122 | it('Should have my scheduled updated video in my account videos', async function () { | |
89d241a7 | 123 | const { total, data } = await servers[0].videos.listMyVideos() |
d23dd9fb | 124 | expect(total).to.equal(2) |
2baea0c7 | 125 | |
d23dd9fb | 126 | const video = data.find(v => v.uuid === video2UUID) |
2baea0c7 C |
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 | ||
bbe0f064 | 139 | await wait(15000) |
2baea0c7 C |
140 | await waitJobs(servers) |
141 | ||
142 | for (const server of servers) { | |
89d241a7 | 143 | const { total, data } = await server.videos.list() |
d23dd9fb | 144 | expect(total).to.equal(2) |
2baea0c7 | 145 | |
d23dd9fb | 146 | const video = data.find(v => v.uuid === video2UUID) |
2baea0c7 C |
147 | expect(video).not.to.be.undefined |
148 | expect(video.name).to.equal('video 2 updated') | |
149 | } | |
150 | }) | |
151 | ||
7c3b7976 C |
152 | after(async function () { |
153 | await cleanupTests(servers) | |
2baea0c7 C |
154 | }) |
155 | }) |