Add originallyPublishedAt unit tests
This commit is contained in:
parent
6913f69134
commit
7519127b5c
|
@ -34,7 +34,8 @@ function activityPubContextify <T> (data: T) {
|
||||||
expires: 'sc:expires',
|
expires: 'sc:expires',
|
||||||
support: 'sc:Text',
|
support: 'sc:Text',
|
||||||
CacheFile: 'pt:CacheFile',
|
CacheFile: 'pt:CacheFile',
|
||||||
Infohash: 'pt:Infohash'
|
Infohash: 'pt:Infohash',
|
||||||
|
originallyPublishedAt: 'sc:DateTime'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
likes: {
|
likes: {
|
||||||
|
|
|
@ -54,6 +54,7 @@ function sanitizeAndCheckVideoTorrentObject (video: any) {
|
||||||
isBooleanValid(video.downloadEnabled) &&
|
isBooleanValid(video.downloadEnabled) &&
|
||||||
isDateValid(video.published) &&
|
isDateValid(video.published) &&
|
||||||
isDateValid(video.updated) &&
|
isDateValid(video.updated) &&
|
||||||
|
(!video.originallyPublishedAt || isDateValid(video.originallyPublishedAt)) &&
|
||||||
(!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) &&
|
(!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) &&
|
||||||
isRemoteVideoIconValid(video.icon) &&
|
isRemoteVideoIconValid(video.icon) &&
|
||||||
video.url.length !== 0 &&
|
video.url.length !== 0 &&
|
||||||
|
|
|
@ -249,6 +249,7 @@ async function updateVideoFromAP (options: {
|
||||||
options.video.set('duration', videoData.duration)
|
options.video.set('duration', videoData.duration)
|
||||||
options.video.set('createdAt', videoData.createdAt)
|
options.video.set('createdAt', videoData.createdAt)
|
||||||
options.video.set('publishedAt', videoData.publishedAt)
|
options.video.set('publishedAt', videoData.publishedAt)
|
||||||
|
options.video.set('originallyPublishedAt', videoData.originallyPublishedAt)
|
||||||
options.video.set('privacy', videoData.privacy)
|
options.video.set('privacy', videoData.privacy)
|
||||||
options.video.set('channelId', videoData.channelId)
|
options.video.set('channelId', videoData.channelId)
|
||||||
options.video.set('views', videoData.views)
|
options.video.set('views', videoData.views)
|
||||||
|
@ -511,6 +512,7 @@ async function videoActivityObjectToDBAttributes (
|
||||||
duration: parseInt(duration, 10),
|
duration: parseInt(duration, 10),
|
||||||
createdAt: new Date(videoObject.published),
|
createdAt: new Date(videoObject.published),
|
||||||
publishedAt: new Date(videoObject.published),
|
publishedAt: new Date(videoObject.published),
|
||||||
|
originallyPublishedAt: videoObject.originallyPublishedAt ? new Date(videoObject.originallyPublishedAt) : null,
|
||||||
// FIXME: updatedAt does not seems to be considered by Sequelize
|
// FIXME: updatedAt does not seems to be considered by Sequelize
|
||||||
updatedAt: new Date(videoObject.updated),
|
updatedAt: new Date(videoObject.updated),
|
||||||
views: videoObject.views,
|
views: videoObject.views,
|
||||||
|
|
|
@ -324,9 +324,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
|
||||||
commentsEnabled: video.commentsEnabled,
|
commentsEnabled: video.commentsEnabled,
|
||||||
downloadEnabled: video.downloadEnabled,
|
downloadEnabled: video.downloadEnabled,
|
||||||
published: video.publishedAt.toISOString(),
|
published: video.publishedAt.toISOString(),
|
||||||
originallyPublishedAt: video.originallyPublishedAt ?
|
originallyPublishedAt: video.originallyPublishedAt ? video.originallyPublishedAt.toISOString() : null,
|
||||||
video.originallyPublishedAt.toISOString() :
|
|
||||||
null,
|
|
||||||
updated: video.updatedAt.toISOString(),
|
updated: video.updatedAt.toISOString(),
|
||||||
mediaType: 'text/markdown',
|
mediaType: 'text/markdown',
|
||||||
content: video.getTruncatedDescription(),
|
content: video.getTruncatedDescription(),
|
||||||
|
|
|
@ -40,7 +40,7 @@ import {
|
||||||
isVideoDurationValid,
|
isVideoDurationValid,
|
||||||
isVideoLanguageValid,
|
isVideoLanguageValid,
|
||||||
isVideoLicenceValid,
|
isVideoLicenceValid,
|
||||||
isVideoNameValid,
|
isVideoNameValid, isVideoOriginallyPublishedAtValid,
|
||||||
isVideoPrivacyValid,
|
isVideoPrivacyValid,
|
||||||
isVideoStateValid,
|
isVideoStateValid,
|
||||||
isVideoSupportValid
|
isVideoSupportValid
|
||||||
|
@ -103,10 +103,17 @@ const indexes: Sequelize.DefineIndexesOptions[] = [
|
||||||
|
|
||||||
{ fields: [ 'createdAt' ] },
|
{ fields: [ 'createdAt' ] },
|
||||||
{ fields: [ 'publishedAt' ] },
|
{ fields: [ 'publishedAt' ] },
|
||||||
{ fields: [ 'originallyPublishedAt' ] },
|
|
||||||
{ fields: [ 'duration' ] },
|
{ fields: [ 'duration' ] },
|
||||||
{ fields: [ 'views' ] },
|
{ fields: [ 'views' ] },
|
||||||
{ fields: [ 'channelId' ] },
|
{ fields: [ 'channelId' ] },
|
||||||
|
{
|
||||||
|
fields: [ 'originallyPublishedAt' ],
|
||||||
|
where: {
|
||||||
|
originallyPublishedAt: {
|
||||||
|
[Sequelize.Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
fields: [ 'category' ], // We don't care videos with an unknown category
|
fields: [ 'category' ], // We don't care videos with an unknown category
|
||||||
where: {
|
where: {
|
||||||
|
@ -741,6 +748,8 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
@Column
|
@Column
|
||||||
publishedAt: Date
|
publishedAt: Date
|
||||||
|
|
||||||
|
@AllowNull(true)
|
||||||
|
@Default(null)
|
||||||
@Column
|
@Column
|
||||||
originallyPublishedAt: Date
|
originallyPublishedAt: Date
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,8 @@ describe('Test videos API validator', function () {
|
||||||
support: 'my super support text',
|
support: 'my super support text',
|
||||||
tags: [ 'tag1', 'tag2' ],
|
tags: [ 'tag1', 'tag2' ],
|
||||||
privacy: VideoPrivacy.PUBLIC,
|
privacy: VideoPrivacy.PUBLIC,
|
||||||
channelId: channelId
|
channelId: channelId,
|
||||||
|
originallyPublishedAt: new Date().toISOString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -313,6 +314,13 @@ describe('Test videos API validator', function () {
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail with a bad originally published at attribute', async function () {
|
||||||
|
const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
|
||||||
|
const attaches = baseCorrectAttaches
|
||||||
|
|
||||||
|
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||||
|
})
|
||||||
|
|
||||||
it('Should fail without an input file', async function () {
|
it('Should fail without an input file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {}
|
const attaches = {}
|
||||||
|
@ -534,6 +542,12 @@ describe('Test videos API validator', function () {
|
||||||
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail with a bad originally published at param', async function () {
|
||||||
|
const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
|
||||||
|
|
||||||
|
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
||||||
|
})
|
||||||
|
|
||||||
it('Should fail with an incorrect thumbnail file', async function () {
|
it('Should fail with an incorrect thumbnail file', async function () {
|
||||||
const fields = baseCorrectParams
|
const fields = baseCorrectParams
|
||||||
const attaches = {
|
const attaches = {
|
||||||
|
|
|
@ -98,6 +98,7 @@ describe('Test multiple servers', function () {
|
||||||
nsfw: true,
|
nsfw: true,
|
||||||
description: 'my super description for server 1',
|
description: 'my super description for server 1',
|
||||||
support: 'my super support text for server 1',
|
support: 'my super support text for server 1',
|
||||||
|
originallyPublishedAt: '2019-02-10T13:38:14.449Z',
|
||||||
tags: [ 'tag1p1', 'tag2p1' ],
|
tags: [ 'tag1p1', 'tag2p1' ],
|
||||||
channelId: videoChannelId,
|
channelId: videoChannelId,
|
||||||
fixture: 'video_short1.webm'
|
fixture: 'video_short1.webm'
|
||||||
|
@ -118,6 +119,7 @@ describe('Test multiple servers', function () {
|
||||||
nsfw: true,
|
nsfw: true,
|
||||||
description: 'my super description for server 1',
|
description: 'my super description for server 1',
|
||||||
support: 'my super support text for server 1',
|
support: 'my super support text for server 1',
|
||||||
|
originallyPublishedAt: '2019-02-10T13:38:14.449Z',
|
||||||
account: {
|
account: {
|
||||||
name: 'root',
|
name: 'root',
|
||||||
host: 'localhost:9001'
|
host: 'localhost:9001'
|
||||||
|
@ -625,6 +627,7 @@ describe('Test multiple servers', function () {
|
||||||
support: 'my super support text updated',
|
support: 'my super support text updated',
|
||||||
tags: [ 'tag_up_1', 'tag_up_2' ],
|
tags: [ 'tag_up_1', 'tag_up_2' ],
|
||||||
thumbnailfile: 'thumbnail.jpg',
|
thumbnailfile: 'thumbnail.jpg',
|
||||||
|
originallyPublishedAt: '2019-02-11T13:38:14.449Z',
|
||||||
previewfile: 'preview.jpg'
|
previewfile: 'preview.jpg'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,6 +655,7 @@ describe('Test multiple servers', function () {
|
||||||
nsfw: true,
|
nsfw: true,
|
||||||
description: 'my super description updated',
|
description: 'my super description updated',
|
||||||
support: 'my super support text updated',
|
support: 'my super support text updated',
|
||||||
|
originallyPublishedAt: '2019-02-11T13:38:14.449Z',
|
||||||
account: {
|
account: {
|
||||||
name: 'root',
|
name: 'root',
|
||||||
host: 'localhost:9003'
|
host: 'localhost:9003'
|
||||||
|
@ -983,7 +987,7 @@ describe('Test multiple servers', function () {
|
||||||
isLocal,
|
isLocal,
|
||||||
duration: 5,
|
duration: 5,
|
||||||
commentsEnabled: false,
|
commentsEnabled: false,
|
||||||
downloadEnabled: false,
|
downloadEnabled: true,
|
||||||
tags: [ ],
|
tags: [ ],
|
||||||
privacy: VideoPrivacy.PUBLIC,
|
privacy: VideoPrivacy.PUBLIC,
|
||||||
channel: {
|
channel: {
|
||||||
|
|
|
@ -31,6 +31,7 @@ type VideoAttributes = {
|
||||||
downloadEnabled?: boolean
|
downloadEnabled?: boolean
|
||||||
waitTranscoding?: boolean
|
waitTranscoding?: boolean
|
||||||
description?: string
|
description?: string
|
||||||
|
originallyPublishedAt?: string
|
||||||
tags?: string[]
|
tags?: string[]
|
||||||
channelId?: number
|
channelId?: number
|
||||||
privacy?: VideoPrivacy
|
privacy?: VideoPrivacy
|
||||||
|
@ -349,6 +350,9 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
|
||||||
if (attributes.licence !== undefined) {
|
if (attributes.licence !== undefined) {
|
||||||
req.field('licence', attributes.licence.toString())
|
req.field('licence', attributes.licence.toString())
|
||||||
}
|
}
|
||||||
|
if (attributes.originallyPublishedAt !== undefined) {
|
||||||
|
req.field('originallyPublishedAt', attributes.originallyPublishedAt)
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < attributes.tags.length; i++) {
|
for (let i = 0; i < attributes.tags.length; i++) {
|
||||||
req.field('tags[' + i + ']', attributes.tags[i])
|
req.field('tags[' + i + ']', attributes.tags[i])
|
||||||
|
@ -384,6 +388,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att
|
||||||
if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
|
if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
|
||||||
if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
|
if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
|
||||||
if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled)
|
if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled)
|
||||||
|
if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt
|
||||||
if (attributes.description) body['description'] = attributes.description
|
if (attributes.description) body['description'] = attributes.description
|
||||||
if (attributes.tags) body['tags'] = attributes.tags
|
if (attributes.tags) body['tags'] = attributes.tags
|
||||||
if (attributes.privacy) body['privacy'] = attributes.privacy
|
if (attributes.privacy) body['privacy'] = attributes.privacy
|
||||||
|
@ -453,6 +458,7 @@ async function completeVideoCheck (
|
||||||
description: string
|
description: string
|
||||||
publishedAt?: string
|
publishedAt?: string
|
||||||
support: string
|
support: string
|
||||||
|
originallyPublishedAt?: string,
|
||||||
account: {
|
account: {
|
||||||
name: string
|
name: string
|
||||||
host: string
|
host: string
|
||||||
|
@ -510,6 +516,12 @@ async function completeVideoCheck (
|
||||||
expect(video.publishedAt).to.equal(attributes.publishedAt)
|
expect(video.publishedAt).to.equal(attributes.publishedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attributes.originallyPublishedAt) {
|
||||||
|
expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
|
||||||
|
} else {
|
||||||
|
expect(video.originallyPublishedAt).to.be.null
|
||||||
|
}
|
||||||
|
|
||||||
const res = await getVideo(url, video.uuid)
|
const res = await getVideo(url, video.uuid)
|
||||||
const videoDetails: VideoDetails = res.body
|
const videoDetails: VideoDetails = res.body
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue