aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-17 11:58:15 +0100
committerChocobozzz <me@florianbigard.com>2021-12-17 12:24:03 +0100
commitc55e3d7227fe1453869e309025996b9d75256d5d (patch)
tree08e9b0ca210d75c82c8606fef0852eca020e8e0e /server/tests/shared/video.ts
parentbf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (diff)
downloadPeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.gz
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.zst
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.zip
Move test functions outside extra-utils
Diffstat (limited to 'server/tests/shared/video.ts')
-rw-r--r--server/tests/shared/video.ts150
1 files changed, 0 insertions, 150 deletions
diff --git a/server/tests/shared/video.ts b/server/tests/shared/video.ts
deleted file mode 100644
index cf923d4cd..000000000
--- a/server/tests/shared/video.ts
+++ /dev/null
@@ -1,150 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions */
2import { dateIsValid, makeRawRequest, PeerTubeServer, testImage, webtorrentAdd } from '@shared/server-commands'
3import { expect } from 'chai'
4import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '@server/initializers/constants'
5import { getLowercaseExtension, uuidRegex } from '@shared/core-utils'
6
7loadLanguages()
8
9export async function completeVideoCheck (
10 server: PeerTubeServer,
11 video: any,
12 attributes: {
13 name: string
14 category: number
15 licence: number
16 language: string
17 nsfw: boolean
18 commentsEnabled: boolean
19 downloadEnabled: boolean
20 description: string
21 publishedAt?: string
22 support: string
23 originallyPublishedAt?: string
24 account: {
25 name: string
26 host: string
27 }
28 isLocal: boolean
29 tags: string[]
30 privacy: number
31 likes?: number
32 dislikes?: number
33 duration: number
34 channel: {
35 displayName: string
36 name: string
37 description: string
38 isLocal: boolean
39 }
40 fixture: string
41 files: {
42 resolution: number
43 size: number
44 }[]
45 thumbnailfile?: string
46 previewfile?: string
47 }
48) {
49 if (!attributes.likes) attributes.likes = 0
50 if (!attributes.dislikes) attributes.dislikes = 0
51
52 const host = new URL(server.url).host
53 const originHost = attributes.account.host
54
55 expect(video.name).to.equal(attributes.name)
56 expect(video.category.id).to.equal(attributes.category)
57 expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
58 expect(video.licence.id).to.equal(attributes.licence)
59 expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
60 expect(video.language.id).to.equal(attributes.language)
61 expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
62 expect(video.privacy.id).to.deep.equal(attributes.privacy)
63 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
64 expect(video.nsfw).to.equal(attributes.nsfw)
65 expect(video.description).to.equal(attributes.description)
66 expect(video.account.id).to.be.a('number')
67 expect(video.account.host).to.equal(attributes.account.host)
68 expect(video.account.name).to.equal(attributes.account.name)
69 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
70 expect(video.channel.name).to.equal(attributes.channel.name)
71 expect(video.likes).to.equal(attributes.likes)
72 expect(video.dislikes).to.equal(attributes.dislikes)
73 expect(video.isLocal).to.equal(attributes.isLocal)
74 expect(video.duration).to.equal(attributes.duration)
75 expect(video.url).to.contain(originHost)
76 expect(dateIsValid(video.createdAt)).to.be.true
77 expect(dateIsValid(video.publishedAt)).to.be.true
78 expect(dateIsValid(video.updatedAt)).to.be.true
79
80 if (attributes.publishedAt) {
81 expect(video.publishedAt).to.equal(attributes.publishedAt)
82 }
83
84 if (attributes.originallyPublishedAt) {
85 expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
86 } else {
87 expect(video.originallyPublishedAt).to.be.null
88 }
89
90 const videoDetails = await server.videos.get({ id: video.uuid })
91
92 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
93 expect(videoDetails.tags).to.deep.equal(attributes.tags)
94 expect(videoDetails.account.name).to.equal(attributes.account.name)
95 expect(videoDetails.account.host).to.equal(attributes.account.host)
96 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
97 expect(video.channel.name).to.equal(attributes.channel.name)
98 expect(videoDetails.channel.host).to.equal(attributes.account.host)
99 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
100 expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
101 expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
102 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
103 expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled)
104
105 for (const attributeFile of attributes.files) {
106 const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)
107 expect(file).not.to.be.undefined
108
109 let extension = getLowercaseExtension(attributes.fixture)
110 // Transcoding enabled: extension will always be .mp4
111 if (attributes.files.length > 1) extension = '.mp4'
112
113 expect(file.magnetUri).to.have.lengthOf.above(2)
114
115 expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
116 expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
117
118 expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`))
119 expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`))
120
121 await Promise.all([
122 makeRawRequest(file.torrentUrl, 200),
123 makeRawRequest(file.torrentDownloadUrl, 200),
124 makeRawRequest(file.metadataUrl, 200)
125 ])
126
127 expect(file.resolution.id).to.equal(attributeFile.resolution)
128 expect(file.resolution.label).to.equal(attributeFile.resolution + 'p')
129
130 const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
131 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
132 expect(
133 file.size,
134 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')'
135 ).to.be.above(minSize).and.below(maxSize)
136
137 const torrent = await webtorrentAdd(file.magnetUri, true)
138 expect(torrent.files).to.be.an('array')
139 expect(torrent.files.length).to.equal(1)
140 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
141 }
142
143 expect(videoDetails.thumbnailPath).to.exist
144 await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
145
146 if (attributes.previewfile) {
147 expect(videoDetails.previewPath).to.exist
148 await testImage(server.url, attributes.previewfile, videoDetails.previewPath)
149 }
150}