Fix tests

pull/2071/head
Chocobozzz 2019-08-20 10:22:05 +02:00
parent 453e83ea5d
commit 96ca24f00e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 13 additions and 10 deletions

View File

@ -28,6 +28,7 @@ import {
MChannelActorAccountDefault, MChannelActorAccountDefault,
MThumbnail, MThumbnail,
MUser, MUser,
MVideoTag,
MVideoThumbnailAccountDefault, MVideoThumbnailAccountDefault,
MVideoWithBlacklistLight MVideoWithBlacklistLight
} from '@server/typings/models' } from '@server/typings/models'
@ -244,7 +245,7 @@ function insertIntoDB (parameters: {
const sequelizeOptions = { transaction: t } const sequelizeOptions = { transaction: t }
// Save video object in database // Save video object in database
const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight) const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag)
videoCreated.VideoChannel = videoChannel videoCreated.VideoChannel = videoChannel
if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
@ -264,6 +265,9 @@ function insertIntoDB (parameters: {
const tagInstances = await TagModel.findOrCreateTags(tags, t) const tagInstances = await TagModel.findOrCreateTags(tags, t)
await videoCreated.$set('Tags', tagInstances, sequelizeOptions) await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
videoCreated.Tags = tagInstances
} else {
videoCreated.Tags = []
} }
// Create video import object in database // Create video import object in database

View File

@ -63,7 +63,7 @@ import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding'
import { Hooks } from '../../../lib/plugins/hooks' import { Hooks } from '../../../lib/plugins/hooks'
import { MVideoFullLight } from '@server/typings/models' import { MVideoDetails, MVideoFullLight } from '@server/typings/models'
const auditLogger = auditLoggerFactory('videos') const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router() const videosRouter = express.Router()
@ -198,7 +198,7 @@ async function addVideo (req: express.Request, res: express.Response) {
originallyPublishedAt: videoInfo.originallyPublishedAt originallyPublishedAt: videoInfo.originallyPublishedAt
} }
const video = new VideoModel(videoData) const video = new VideoModel(videoData) as MVideoDetails
video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
const videoFile = new VideoFileModel({ const videoFile = new VideoFileModel({

View File

@ -65,9 +65,7 @@ import {
MVideoFile, MVideoFile,
MVideoFullLight, MVideoFullLight,
MVideoId, MVideoId,
MVideoTag, MVideoThumbnail
MVideoThumbnail,
MVideoWithAllFiles
} from '../../typings/models' } from '../../typings/models'
import { MThumbnail } from '../../typings/models/video/thumbnail' import { MThumbnail } from '../../typings/models/video/thumbnail'

View File

@ -6,6 +6,7 @@ import { throwIfNotValid } from '../utils'
import { VideoModel } from './video' import { VideoModel } from './video'
import { VideoTagModel } from './video-tag' import { VideoTagModel } from './video-tag'
import { VideoPrivacy, VideoState } from '../../../shared/models/videos' import { VideoPrivacy, VideoState } from '../../../shared/models/videos'
import { MTag } from '@server/typings/models'
@Table({ @Table({
tableName: 'tag', tableName: 'tag',
@ -37,10 +38,10 @@ export class TagModel extends Model<TagModel> {
}) })
Videos: VideoModel[] Videos: VideoModel[]
static findOrCreateTags (tags: string[], transaction: Transaction) { static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
if (tags === null) return [] if (tags === null) return Promise.resolve([])
const tasks: Bluebird<TagModel>[] = [] const tasks: Bluebird<MTag>[] = []
tags.forEach(tag => { tags.forEach(tag => {
const query = { const query = {
where: { where: {
@ -52,7 +53,7 @@ export class TagModel extends Model<TagModel> {
transaction transaction
} }
const promise = TagModel.findOrCreate(query) const promise = TagModel.findOrCreate<MTag>(query)
.then(([ tagInstance ]) => tagInstance) .then(([ tagInstance ]) => tagInstance)
tasks.push(promise) tasks.push(promise)
}) })