diff options
Diffstat (limited to 'server/tests/cli/create-generate-storyboard-job.ts')
-rw-r--r-- | server/tests/cli/create-generate-storyboard-job.ts | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/server/tests/cli/create-generate-storyboard-job.ts b/server/tests/cli/create-generate-storyboard-job.ts new file mode 100644 index 000000000..02a4be8ae --- /dev/null +++ b/server/tests/cli/create-generate-storyboard-job.ts | |||
@@ -0,0 +1,120 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { readdir, remove } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { HttpStatusCode } from '@shared/models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | createMultipleServers, | ||
10 | doubleFollow, | ||
11 | makeGetRequest, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { SQLCommand } from '../shared' | ||
17 | |||
18 | function listStoryboardFiles (server: PeerTubeServer) { | ||
19 | const storage = server.getDirectoryPath('storyboards') | ||
20 | |||
21 | return readdir(storage) | ||
22 | } | ||
23 | |||
24 | describe('Test create generate storyboard job', function () { | ||
25 | let servers: PeerTubeServer[] = [] | ||
26 | const uuids: string[] = [] | ||
27 | let sql: SQLCommand | ||
28 | let existingStoryboardName: string | ||
29 | |||
30 | before(async function () { | ||
31 | this.timeout(120000) | ||
32 | |||
33 | // Run server 2 to have transcoding enabled | ||
34 | servers = await createMultipleServers(2) | ||
35 | await setAccessTokensToServers(servers) | ||
36 | |||
37 | await doubleFollow(servers[0], servers[1]) | ||
38 | |||
39 | for (let i = 0; i < 3; i++) { | ||
40 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video ' + i }) | ||
41 | uuids.push(uuid) | ||
42 | } | ||
43 | |||
44 | await waitJobs(servers) | ||
45 | |||
46 | const storage = servers[0].getDirectoryPath('storyboards') | ||
47 | for (const storyboard of await listStoryboardFiles(servers[0])) { | ||
48 | await remove(join(storage, storyboard)) | ||
49 | } | ||
50 | |||
51 | sql = new SQLCommand(servers[0]) | ||
52 | await sql.deleteAll('storyboard') | ||
53 | |||
54 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 4' }) | ||
55 | uuids.push(uuid) | ||
56 | |||
57 | await waitJobs(servers) | ||
58 | |||
59 | const storyboards = await listStoryboardFiles(servers[0]) | ||
60 | existingStoryboardName = storyboards[0] | ||
61 | }) | ||
62 | |||
63 | it('Should create a storyboard of a video', async function () { | ||
64 | this.timeout(120000) | ||
65 | |||
66 | for (const uuid of [ uuids[0], uuids[3] ]) { | ||
67 | const command = `npm run create-generate-storyboard-job -- -v ${uuid}` | ||
68 | await servers[0].cli.execWithEnv(command) | ||
69 | } | ||
70 | |||
71 | await waitJobs(servers) | ||
72 | |||
73 | { | ||
74 | const storyboards = await listStoryboardFiles(servers[0]) | ||
75 | expect(storyboards).to.have.lengthOf(2) | ||
76 | expect(storyboards).to.not.include(existingStoryboardName) | ||
77 | |||
78 | existingStoryboardName = storyboards[0] | ||
79 | } | ||
80 | |||
81 | for (const server of servers) { | ||
82 | for (const uuid of [ uuids[0], uuids[3] ]) { | ||
83 | const { storyboards } = await server.storyboard.list({ id: uuid }) | ||
84 | expect(storyboards).to.have.lengthOf(1) | ||
85 | |||
86 | await makeGetRequest({ url: server.url, path: storyboards[0].storyboardPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
87 | } | ||
88 | } | ||
89 | }) | ||
90 | |||
91 | it('Should create missing storyboards', async function () { | ||
92 | this.timeout(120000) | ||
93 | |||
94 | const command = `npm run create-generate-storyboard-job -- -a` | ||
95 | await servers[0].cli.execWithEnv(command) | ||
96 | |||
97 | await waitJobs(servers) | ||
98 | |||
99 | { | ||
100 | const storyboards = await listStoryboardFiles(servers[0]) | ||
101 | expect(storyboards).to.have.lengthOf(4) | ||
102 | expect(storyboards).to.include(existingStoryboardName) | ||
103 | } | ||
104 | |||
105 | for (const server of servers) { | ||
106 | for (const uuid of uuids) { | ||
107 | const { storyboards } = await server.storyboard.list({ id: uuid }) | ||
108 | expect(storyboards).to.have.lengthOf(1) | ||
109 | |||
110 | await makeGetRequest({ url: server.url, path: storyboards[0].storyboardPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
111 | } | ||
112 | } | ||
113 | }) | ||
114 | |||
115 | after(async function () { | ||
116 | await sql.cleanup() | ||
117 | |||
118 | await cleanupTests(servers) | ||
119 | }) | ||
120 | }) | ||