1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
3 import { expect } from 'chai'
4 import { createReadStream, pathExists, readdir, readFile, stat } from 'fs-extra'
5 import got, { Response as GotResponse } from 'got/dist/source'
6 import * as parseTorrent from 'parse-torrent'
7 import { join } from 'path'
8 import * as request from 'supertest'
9 import validator from 'validator'
10 import { getLowercaseExtension } from '@server/helpers/core-utils'
11 import { buildUUID } from '@server/helpers/uuid'
12 import { HttpStatusCode } from '@shared/core-utils'
13 import { BooleanBothQuery, VideosCommonQuery } from '@shared/models'
14 import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
15 import { VideoDetails, VideoPrivacy } from '../../models/videos'
17 buildAbsoluteFixturePath,
24 } from '../miscs/miscs'
25 import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'
26 import { waitJobs } from '../server/jobs'
27 import { ServerInfo } from '../server/servers'
28 import { getMyUserInformation } from '../users/users'
32 type VideoAttributes = {
38 commentsEnabled?: boolean
39 downloadEnabled?: boolean
40 waitTranscoding?: boolean
42 originallyPublishedAt?: string
45 privacy?: VideoPrivacy
48 thumbnailfile?: string
52 privacy?: VideoPrivacy
56 function getVideoCategories (url: string) {
57 const path = '/api/v1/videos/categories'
59 return makeGetRequest({
62 statusCodeExpected: HttpStatusCode.OK_200
66 function getVideoLicences (url: string) {
67 const path = '/api/v1/videos/licences'
69 return makeGetRequest({
72 statusCodeExpected: HttpStatusCode.OK_200
76 function getVideoLanguages (url: string) {
77 const path = '/api/v1/videos/languages'
79 return makeGetRequest({
82 statusCodeExpected: HttpStatusCode.OK_200
86 function getVideoPrivacies (url: string) {
87 const path = '/api/v1/videos/privacies'
89 return makeGetRequest({
92 statusCodeExpected: HttpStatusCode.OK_200
96 function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
97 const path = '/api/v1/videos/' + id
101 .set('Accept', 'application/json')
102 .expect(expectedStatus)
105 async function getVideoIdFromUUID (url: string, uuid: string) {
106 const res = await getVideo(url, uuid)
111 function getVideoFileMetadataUrl (url: string) {
114 .set('Accept', 'application/json')
115 .expect(HttpStatusCode.OK_200)
116 .expect('Content-Type', /json/)
119 function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) {
120 const path = '/api/v1/videos/' + id + '/views'
122 const req = request(url)
124 .set('Accept', 'application/json')
127 req.set('X-Forwarded-For', xForwardedFor)
130 return req.expect(expectedStatus)
133 function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) {
134 const path = '/api/v1/videos/' + id
138 .set('Authorization', 'Bearer ' + token)
139 .set('Accept', 'application/json')
140 .expect(expectedStatus)
143 function getVideoDescription (url: string, descriptionPath: string) {
145 .get(descriptionPath)
146 .set('Accept', 'application/json')
147 .expect(HttpStatusCode.OK_200)
148 .expect('Content-Type', /json/)
151 function getVideosList (url: string) {
152 const path = '/api/v1/videos'
156 .query({ sort: 'name' })
157 .set('Accept', 'application/json')
158 .expect(HttpStatusCode.OK_200)
159 .expect('Content-Type', /json/)
162 function getVideosListWithToken (url: string, token: string, query: { nsfw?: BooleanBothQuery } = {}) {
163 const path = '/api/v1/videos'
167 .set('Authorization', 'Bearer ' + token)
168 .query(immutableAssign(query, { sort: 'name' }))
169 .set('Accept', 'application/json')
170 .expect(HttpStatusCode.OK_200)
171 .expect('Content-Type', /json/)
174 function getLocalVideos (url: string) {
175 const path = '/api/v1/videos'
179 .query({ sort: 'name', filter: 'local' })
180 .set('Accept', 'application/json')
181 .expect(HttpStatusCode.OK_200)
182 .expect('Content-Type', /json/)
185 function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string, search?: string) {
186 const path = '/api/v1/users/me/videos'
188 const req = request(url)
190 .query({ start: start })
191 .query({ count: count })
192 .query({ search: search })
194 if (sort) req.query({ sort })
196 return req.set('Accept', 'application/json')
197 .set('Authorization', 'Bearer ' + accessToken)
198 .expect(HttpStatusCode.OK_200)
199 .expect('Content-Type', /json/)
202 function getMyVideosWithFilter (url: string, accessToken: string, query: { isLive?: boolean }) {
203 const path = '/api/v1/users/me/videos'
205 return makeGetRequest({
210 statusCodeExpected: HttpStatusCode.OK_200
214 function getAccountVideos (
222 nsfw?: BooleanBothQuery
226 const path = '/api/v1/accounts/' + accountName + '/videos'
228 return makeGetRequest({
231 query: immutableAssign(query, {
237 statusCodeExpected: HttpStatusCode.OK_200
241 function getVideoChannelVideos (
244 videoChannelName: string,
248 query: { nsfw?: BooleanBothQuery } = {}
250 const path = '/api/v1/video-channels/' + videoChannelName + '/videos'
252 return makeGetRequest({
255 query: immutableAssign(query, {
261 statusCodeExpected: HttpStatusCode.OK_200
265 function getPlaylistVideos (
268 playlistId: number | string,
271 query: { nsfw?: boolean } = {}
273 const path = '/api/v1/video-playlists/' + playlistId + '/videos'
275 return makeGetRequest({
278 query: immutableAssign(query, {
283 statusCodeExpected: HttpStatusCode.OK_200
287 function getVideosListPagination (url: string, start: number, count: number, sort?: string, skipCount?: boolean) {
288 const path = '/api/v1/videos'
290 const req = request(url)
292 .query({ start: start })
293 .query({ count: count })
295 if (sort) req.query({ sort })
296 if (skipCount) req.query({ skipCount })
298 return req.set('Accept', 'application/json')
299 .expect(HttpStatusCode.OK_200)
300 .expect('Content-Type', /json/)
303 function getVideosListSort (url: string, sort: string) {
304 const path = '/api/v1/videos'
308 .query({ sort: sort })
309 .set('Accept', 'application/json')
310 .expect(HttpStatusCode.OK_200)
311 .expect('Content-Type', /json/)
314 function getVideosWithFilters (url: string, query: VideosCommonQuery) {
315 const path = '/api/v1/videos'
320 .set('Accept', 'application/json')
321 .expect(HttpStatusCode.OK_200)
322 .expect('Content-Type', /json/)
325 function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
326 const path = '/api/v1/videos'
329 .delete(path + '/' + id)
330 .set('Accept', 'application/json')
331 .set('Authorization', 'Bearer ' + token)
332 .expect(expectedStatus)
335 async function removeAllVideos (server: ServerInfo) {
336 const resVideos = await getVideosList(server.url)
338 for (const v of resVideos.body.data) {
339 await removeVideo(server.url, server.accessToken, v.id)
343 async function checkVideoFilesWereRemoved (
345 serverNumber: number,
353 join('playlists', 'hls'),
354 join('redundancy', 'hls')
357 for (const directory of directories) {
358 const directoryPath = buildServerDirectory({ internalServerNumber: serverNumber }, directory)
360 const directoryExists = await pathExists(directoryPath)
361 if (directoryExists === false) continue
363 const files = await readdir(directoryPath)
364 for (const file of files) {
365 expect(file, `File ${file} should not exist in ${directoryPath}`).to.not.contain(videoUUID)
370 async function uploadVideo (
373 videoAttributesArg: VideoAttributes,
374 specialStatus = HttpStatusCode.OK_200,
375 mode: 'legacy' | 'resumable' = 'legacy'
377 let defaultChannelId = '1'
380 const res = await getMyUserInformation(url, accessToken)
381 defaultChannelId = res.body.videoChannels[0].id
382 } catch (e) { /* empty */ }
384 // Override default attributes
385 const attributes = Object.assign({
386 name: 'my super video',
390 channelId: defaultChannelId,
392 waitTranscoding: false,
393 description: 'my super description',
394 support: 'my super support text',
396 privacy: VideoPrivacy.PUBLIC,
397 commentsEnabled: true,
398 downloadEnabled: true,
399 fixture: 'video_short.webm'
400 }, videoAttributesArg)
402 const res = mode === 'legacy'
403 ? await buildLegacyUpload(url, accessToken, attributes, specialStatus)
404 : await buildResumeUpload(url, accessToken, attributes, specialStatus)
406 // Wait torrent generation
407 if (specialStatus === HttpStatusCode.OK_200) {
408 let video: VideoDetails
410 const resVideo = await getVideoWithToken(url, accessToken, res.body.video.uuid)
411 video = resVideo.body
414 } while (!video.files[0].torrentUrl)
420 function checkUploadVideoParam (
423 attributes: Partial<VideoAttributes>,
424 specialStatus = HttpStatusCode.OK_200,
425 mode: 'legacy' | 'resumable' = 'legacy'
427 return mode === 'legacy'
428 ? buildLegacyUpload(url, token, attributes, specialStatus)
429 : buildResumeUpload(url, token, attributes, specialStatus)
432 async function buildLegacyUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) {
433 const path = '/api/v1/videos/upload'
434 const req = request(url)
436 .set('Accept', 'application/json')
437 .set('Authorization', 'Bearer ' + token)
439 buildUploadReq(req, attributes)
441 if (attributes.fixture !== undefined) {
442 req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture))
445 return req.expect(specialStatus)
448 async function buildResumeUpload (url: string, token: string, attributes: VideoAttributes, specialStatus = HttpStatusCode.OK_200) {
450 let videoFilePath: string
451 let mimetype = 'video/mp4'
453 if (attributes.fixture) {
454 videoFilePath = buildAbsoluteFixturePath(attributes.fixture)
455 size = (await stat(videoFilePath)).size
457 if (videoFilePath.endsWith('.mkv')) {
458 mimetype = 'video/x-matroska'
459 } else if (videoFilePath.endsWith('.webm')) {
460 mimetype = 'video/webm'
464 const initializeSessionRes = await prepareResumableUpload({ url, token, attributes, size, mimetype })
465 const initStatus = initializeSessionRes.status
467 if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) {
468 const locationHeader = initializeSessionRes.header['location']
469 expect(locationHeader).to.not.be.undefined
471 const pathUploadId = locationHeader.split('?')[1]
473 return sendResumableChunks({ url, token, pathUploadId, videoFilePath, size, specialStatus })
476 const expectedInitStatus = specialStatus === HttpStatusCode.OK_200
477 ? HttpStatusCode.CREATED_201
480 expect(initStatus).to.equal(expectedInitStatus)
482 return initializeSessionRes
485 async function prepareResumableUpload (options: {
488 attributes: VideoAttributes
492 const { url, token, attributes, size, mimetype } = options
494 const path = '/api/v1/videos/upload-resumable'
496 const req = request(url)
498 .set('Authorization', 'Bearer ' + token)
499 .set('X-Upload-Content-Type', mimetype)
500 .set('X-Upload-Content-Length', size.toString())
502 buildUploadReq(req, attributes)
504 if (attributes.fixture) {
505 req.field('filename', attributes.fixture)
511 function sendResumableChunks (options: {
515 videoFilePath: string
517 specialStatus?: HttpStatusCode
518 contentLength?: number
519 contentRangeBuilder?: (start: number, chunk: any) => string
521 const { url, token, pathUploadId, videoFilePath, size, specialStatus, contentLength, contentRangeBuilder } = options
523 const expectedStatus = specialStatus || HttpStatusCode.OK_200
525 const path = '/api/v1/videos/upload-resumable'
528 const readable = createReadStream(videoFilePath, { highWaterMark: 8 * 1024 })
529 return new Promise<GotResponse>((resolve, reject) => {
530 readable.on('data', async function onData (chunk) {
534 'Authorization': 'Bearer ' + token,
535 'Content-Type': 'application/octet-stream',
536 'Content-Range': contentRangeBuilder
537 ? contentRangeBuilder(start, chunk)
538 : `bytes ${start}-${start + chunk.length - 1}/${size}`,
539 'Content-Length': contentLength ? contentLength + '' : chunk.length + ''
542 const res = await got({
546 path: path + '?' + pathUploadId,
548 responseType: 'json',
549 throwHttpErrors: false
552 start += chunk.length
554 if (res.statusCode === expectedStatus) {
558 if (res.statusCode !== HttpStatusCode.PERMANENT_REDIRECT_308) {
559 readable.off('data', onData)
560 return reject(new Error('Incorrect transient behaviour sending intermediary chunks'))
568 function updateVideo (
572 attributes: VideoAttributes,
573 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
575 const path = '/api/v1/videos/' + id
578 if (attributes.name) body['name'] = attributes.name
579 if (attributes.category) body['category'] = attributes.category
580 if (attributes.licence) body['licence'] = attributes.licence
581 if (attributes.language) body['language'] = attributes.language
582 if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
583 if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
584 if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled)
585 if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt
586 if (attributes.description) body['description'] = attributes.description
587 if (attributes.tags) body['tags'] = attributes.tags
588 if (attributes.privacy) body['privacy'] = attributes.privacy
589 if (attributes.channelId) body['channelId'] = attributes.channelId
590 if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate
593 if (attributes.thumbnailfile || attributes.previewfile) {
594 const attaches: any = {}
595 if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile
596 if (attributes.previewfile) attaches.previewfile = attributes.previewfile
598 return makeUploadRequest({
609 return makePutBodyRequest({
618 function rateVideo (url: string, accessToken: string, id: number | string, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
619 const path = '/api/v1/videos/' + id + '/rate'
623 .set('Accept', 'application/json')
624 .set('Authorization', 'Bearer ' + accessToken)
626 .expect(specialStatus)
629 function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
630 return new Promise<any>((res, rej) => {
631 const torrentName = videoUUID + '-' + resolution + '.torrent'
632 const torrentPath = buildServerDirectory(server, join('torrents', torrentName))
634 readFile(torrentPath, (err, data) => {
635 if (err) return rej(err)
637 return res(parseTorrent(data))
642 async function completeVideoCheck (
651 commentsEnabled: boolean
652 downloadEnabled: boolean
656 originallyPublishedAt?: string
678 thumbnailfile?: string
682 if (!attributes.likes) attributes.likes = 0
683 if (!attributes.dislikes) attributes.dislikes = 0
685 const host = new URL(url).host
686 const originHost = attributes.account.host
688 expect(video.name).to.equal(attributes.name)
689 expect(video.category.id).to.equal(attributes.category)
690 expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
691 expect(video.licence.id).to.equal(attributes.licence)
692 expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
693 expect(video.language.id).to.equal(attributes.language)
694 expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
695 expect(video.privacy.id).to.deep.equal(attributes.privacy)
696 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
697 expect(video.nsfw).to.equal(attributes.nsfw)
698 expect(video.description).to.equal(attributes.description)
699 expect(video.account.id).to.be.a('number')
700 expect(video.account.host).to.equal(attributes.account.host)
701 expect(video.account.name).to.equal(attributes.account.name)
702 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
703 expect(video.channel.name).to.equal(attributes.channel.name)
704 expect(video.likes).to.equal(attributes.likes)
705 expect(video.dislikes).to.equal(attributes.dislikes)
706 expect(video.isLocal).to.equal(attributes.isLocal)
707 expect(video.duration).to.equal(attributes.duration)
708 expect(dateIsValid(video.createdAt)).to.be.true
709 expect(dateIsValid(video.publishedAt)).to.be.true
710 expect(dateIsValid(video.updatedAt)).to.be.true
712 if (attributes.publishedAt) {
713 expect(video.publishedAt).to.equal(attributes.publishedAt)
716 if (attributes.originallyPublishedAt) {
717 expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
719 expect(video.originallyPublishedAt).to.be.null
722 const res = await getVideo(url, video.uuid)
723 const videoDetails: VideoDetails = res.body
725 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
726 expect(videoDetails.tags).to.deep.equal(attributes.tags)
727 expect(videoDetails.account.name).to.equal(attributes.account.name)
728 expect(videoDetails.account.host).to.equal(attributes.account.host)
729 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
730 expect(video.channel.name).to.equal(attributes.channel.name)
731 expect(videoDetails.channel.host).to.equal(attributes.account.host)
732 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
733 expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
734 expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
735 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
736 expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled)
738 for (const attributeFile of attributes.files) {
739 const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)
740 expect(file).not.to.be.undefined
742 let extension = getLowercaseExtension(attributes.fixture)
743 // Transcoding enabled: extension will always be .mp4
744 if (attributes.files.length > 1) extension = '.mp4'
746 expect(file.magnetUri).to.have.lengthOf.above(2)
748 expect(file.torrentDownloadUrl).to.equal(`http://${host}/download/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`)
749 expect(file.torrentUrl).to.equal(`http://${host}/lazy-static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`)
751 expect(file.fileUrl).to.equal(`http://${originHost}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`)
752 expect(file.fileDownloadUrl).to.equal(`http://${originHost}/download/videos/${videoDetails.uuid}-${file.resolution.id}${extension}`)
755 makeRawRequest(file.torrentUrl, 200),
756 makeRawRequest(file.torrentDownloadUrl, 200),
757 makeRawRequest(file.metadataUrl, 200),
758 // Backward compatibility
759 makeRawRequest(`http://${originHost}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`, 200)
762 expect(file.resolution.id).to.equal(attributeFile.resolution)
763 expect(file.resolution.label).to.equal(attributeFile.resolution + 'p')
765 const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
766 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
769 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')'
770 ).to.be.above(minSize).and.below(maxSize)
772 const torrent = await webtorrentAdd(file.magnetUri, true)
773 expect(torrent.files).to.be.an('array')
774 expect(torrent.files.length).to.equal(1)
775 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
778 expect(videoDetails.thumbnailPath).to.exist
779 await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
781 if (attributes.previewfile) {
782 expect(videoDetails.previewPath).to.exist
783 await testImage(url, attributes.previewfile, videoDetails.previewPath)
787 async function videoUUIDToId (url: string, id: number | string) {
788 if (validator.isUUID('' + id) === false) return id
790 const res = await getVideo(url, id)
794 async function uploadVideoAndGetId (options: {
798 privacy?: VideoPrivacy
802 const videoAttrs: any = { name: options.videoName }
803 if (options.nsfw) videoAttrs.nsfw = options.nsfw
804 if (options.privacy) videoAttrs.privacy = options.privacy
805 if (options.fixture) videoAttrs.fixture = options.fixture
807 const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
809 return res.body.video as { id: number, uuid: string, shortUUID: string }
812 async function getLocalIdByUUID (url: string, uuid: string) {
813 const res = await getVideo(url, uuid)
818 // serverNumber starts from 1
819 async function uploadRandomVideoOnServers (servers: ServerInfo[], serverNumber: number, additionalParams: any = {}) {
820 const server = servers.find(s => s.serverNumber === serverNumber)
821 const res = await uploadRandomVideo(server, false, additionalParams)
823 await waitJobs(servers)
828 async function uploadRandomVideo (server: ServerInfo, wait = true, additionalParams: any = {}) {
829 const prefixName = additionalParams.prefixName || ''
830 const name = prefixName + buildUUID()
832 const data = Object.assign({ name }, additionalParams)
833 const res = await uploadVideo(server.url, server.accessToken, data)
835 if (wait) await waitJobs([ server ])
837 return { uuid: res.body.video.uuid, name }
840 // ---------------------------------------------------------------------------
852 getVideoChannelVideos,
854 getVideoFileMetadataUrl,
858 checkUploadVideoParam,
859 getVideosListPagination,
862 getVideosListWithToken,
865 getVideosWithFilters,
866 uploadRandomVideoOnServers,
873 checkVideoFilesWereRemoved,
875 getMyVideosWithFilter,
879 prepareResumableUpload
882 // ---------------------------------------------------------------------------
884 function buildUploadReq (req: request.Test, attributes: VideoAttributes) {
886 for (const key of [ 'name', 'support', 'channelId', 'description', 'originallyPublishedAt' ]) {
887 if (attributes[key] !== undefined) {
888 req.field(key, attributes[key])
892 for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) {
893 if (attributes[key] !== undefined) {
894 req.field(key, JSON.stringify(attributes[key]))
898 for (const key of [ 'language', 'privacy', 'category', 'licence' ]) {
899 if (attributes[key] !== undefined) {
900 req.field(key, attributes[key].toString())
904 const tags = attributes.tags || []
905 for (let i = 0; i < tags.length; i++) {
906 req.field('tags[' + i + ']', attributes.tags[i])
909 for (const key of [ 'thumbnailfile', 'previewfile' ]) {
910 if (attributes[key] !== undefined) {
911 req.attach(key, buildAbsoluteFixturePath(attributes[key]))
915 if (attributes.scheduleUpdate) {
916 if (attributes.scheduleUpdate.updateAt) {
917 req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt)
920 if (attributes.scheduleUpdate.privacy) {
921 req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy)