diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-22 12:10:40 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-22 12:12:33 +0100 |
commit | d3ea89759104e6c14b00443526f2c2a0a13aeb97 (patch) | |
tree | e30dc7025f284c163a450cb08f7060875e368e6c /server/lib/video-comment.ts | |
parent | bf1f650817dadfd5eeee9e5e0b6b6938c136e25d (diff) | |
download | PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.gz PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.zst PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.zip |
Begin unit tests
Diffstat (limited to 'server/lib/video-comment.ts')
-rw-r--r-- | server/lib/video-comment.ts | 24 |
1 files changed, 13 insertions, 11 deletions
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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { ResultList } from '../../shared/models' | 2 | import { ResultList } from '../../shared/models' |
3 | import { VideoCommentThread } from '../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' |
4 | import { VideoModel } from '../models/video/video' | 4 | import { VideoModel } from '../models/video/video' |
5 | import { VideoCommentModel } from '../models/video/video-comment' | 5 | import { VideoCommentModel } from '../models/video/video-comment' |
6 | import { getVideoCommentActivityPubUrl } from './activitypub' | 6 | import { getVideoCommentActivityPubUrl } from './activitypub' |
7 | 7 | ||
8 | async function createVideoComment (obj: { | 8 | async function createVideoComment (obj: { |
9 | text: string, | 9 | text: string, |
10 | inReplyToComment: number, | 10 | inReplyToCommentId: number, |
11 | video: VideoModel | 11 | video: VideoModel |
12 | actorId: number | 12 | accountId: number |
13 | }, t: Sequelize.Transaction) { | 13 | }, t: Sequelize.Transaction) { |
14 | let originCommentId: number = null | 14 | let originCommentId: number = null |
15 | if (obj.inReplyToComment) { | 15 | |
16 | const repliedComment = await VideoCommentModel.loadById(obj.inReplyToComment) | 16 | if (obj.inReplyToCommentId) { |
17 | const repliedComment = await VideoCommentModel.loadById(obj.inReplyToCommentId) | ||
17 | if (!repliedComment) throw new Error('Unknown replied comment.') | 18 | if (!repliedComment) throw new Error('Unknown replied comment.') |
18 | 19 | ||
19 | originCommentId = repliedComment.originCommentId || repliedComment.id | 20 | originCommentId = repliedComment.originCommentId || repliedComment.id |
@@ -22,22 +23,23 @@ async function createVideoComment (obj: { | |||
22 | const comment = await VideoCommentModel.create({ | 23 | const comment = await VideoCommentModel.create({ |
23 | text: obj.text, | 24 | text: obj.text, |
24 | originCommentId, | 25 | originCommentId, |
25 | inReplyToComment: obj.inReplyToComment, | 26 | inReplyToCommentId: obj.inReplyToCommentId, |
26 | videoId: obj.video.id, | 27 | videoId: obj.video.id, |
27 | actorId: obj.actorId | 28 | accountId: obj.accountId, |
28 | }, { transaction: t }) | 29 | url: 'fake url' |
30 | }, { transaction: t, validate: false }) | ||
29 | 31 | ||
30 | comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) | 32 | comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) |
31 | 33 | ||
32 | return comment.save({ transaction: t }) | 34 | return comment.save({ transaction: t }) |
33 | } | 35 | } |
34 | 36 | ||
35 | function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThread { | 37 | function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThreadTree { |
36 | // Comments are sorted by id ASC | 38 | // Comments are sorted by id ASC |
37 | const comments = resultList.data | 39 | const comments = resultList.data |
38 | 40 | ||
39 | const comment = comments.shift() | 41 | const comment = comments.shift() |
40 | const thread: VideoCommentThread = { | 42 | const thread: VideoCommentThreadTree = { |
41 | comment: comment.toFormattedJSON(), | 43 | comment: comment.toFormattedJSON(), |
42 | children: [] | 44 | children: [] |
43 | } | 45 | } |
@@ -48,7 +50,7 @@ function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): | |||
48 | while (comments.length !== 0) { | 50 | while (comments.length !== 0) { |
49 | const childComment = comments.shift() | 51 | const childComment = comments.shift() |
50 | 52 | ||
51 | const childCommentThread: VideoCommentThread = { | 53 | const childCommentThread: VideoCommentThreadTree = { |
52 | comment: childComment.toFormattedJSON(), | 54 | comment: childComment.toFormattedJSON(), |
53 | children: [] | 55 | children: [] |
54 | } | 56 | } |