From d3ea89759104e6c14b00443526f2c2a0a13aeb97 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 22 Dec 2017 12:10:40 +0100 Subject: Begin unit tests --- server/lib/video-comment.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'server/lib/video-comment.ts') diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts index edb72d4e2..e3fe26e35 100644 --- a/server/lib/video-comment.ts +++ b/server/lib/video-comment.ts @@ -1,19 +1,20 @@ import * as Sequelize from 'sequelize' import { ResultList } from '../../shared/models' -import { VideoCommentThread } from '../../shared/models/videos/video-comment.model' +import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' import { VideoModel } from '../models/video/video' import { VideoCommentModel } from '../models/video/video-comment' import { getVideoCommentActivityPubUrl } from './activitypub' async function createVideoComment (obj: { text: string, - inReplyToComment: number, + inReplyToCommentId: number, video: VideoModel - actorId: number + accountId: number }, t: Sequelize.Transaction) { let originCommentId: number = null - if (obj.inReplyToComment) { - const repliedComment = await VideoCommentModel.loadById(obj.inReplyToComment) + + if (obj.inReplyToCommentId) { + const repliedComment = await VideoCommentModel.loadById(obj.inReplyToCommentId) if (!repliedComment) throw new Error('Unknown replied comment.') originCommentId = repliedComment.originCommentId || repliedComment.id @@ -22,22 +23,23 @@ async function createVideoComment (obj: { const comment = await VideoCommentModel.create({ text: obj.text, originCommentId, - inReplyToComment: obj.inReplyToComment, + inReplyToCommentId: obj.inReplyToCommentId, videoId: obj.video.id, - actorId: obj.actorId - }, { transaction: t }) + accountId: obj.accountId, + url: 'fake url' + }, { transaction: t, validate: false }) comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) return comment.save({ transaction: t }) } -function buildFormattedCommentTree (resultList: ResultList): VideoCommentThread { +function buildFormattedCommentTree (resultList: ResultList): VideoCommentThreadTree { // Comments are sorted by id ASC const comments = resultList.data const comment = comments.shift() - const thread: VideoCommentThread = { + const thread: VideoCommentThreadTree = { comment: comment.toFormattedJSON(), children: [] } @@ -48,7 +50,7 @@ function buildFormattedCommentTree (resultList: ResultList): while (comments.length !== 0) { const childComment = comments.shift() - const childCommentThread: VideoCommentThread = { + const childCommentThread: VideoCommentThreadTree = { comment: childComment.toFormattedJSON(), children: [] } -- cgit v1.2.3