Add get old comment on follow tests

This commit is contained in:
Chocobozzz 2017-12-28 11:45:10 +01:00
parent da854ddd50
commit db799da3d2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 67 additions and 11 deletions

View File

@ -103,8 +103,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
@BelongsTo(() => VideoCommentModel, { @BelongsTo(() => VideoCommentModel, {
foreignKey: { foreignKey: {
name: 'originCommentId',
allowNull: true allowNull: true
}, },
as: 'OriginVideoComment',
onDelete: 'CASCADE' onDelete: 'CASCADE'
}) })
OriginVideoComment: VideoCommentModel OriginVideoComment: VideoCommentModel
@ -115,6 +117,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
@BelongsTo(() => VideoCommentModel, { @BelongsTo(() => VideoCommentModel, {
foreignKey: { foreignKey: {
name: 'inReplyToCommentId',
allowNull: true allowNull: true
}, },
as: 'InReplyToVideoComment', as: 'InReplyToVideoComment',

View File

@ -2,21 +2,17 @@
import * as chai from 'chai' import * as chai from 'chai'
import 'mocha' import 'mocha'
import { VideoComment, VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
import { import {
flushAndRunMultipleServers, flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
flushTests,
getVideosList,
killallServers,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
wait wait
} from '../utils' } from '../utils'
import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows' import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows'
import { getUserAccessToken } from '../utils/login' import { getUserAccessToken } from '../utils/login'
import { dateIsValid, webtorrentAdd } from '../utils/miscs' import { dateIsValid, webtorrentAdd } from '../utils/miscs'
import { createUser } from '../utils/users' import { createUser } from '../utils/users'
import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments } from '../utils/video-comments'
import { getVideo, rateVideo, testVideoImage } from '../utils/videos' import { getVideo, rateVideo, testVideoImage } from '../utils/videos'
const expect = chai.expect const expect = chai.expect
@ -186,13 +182,31 @@ describe('Test follows', function () {
await createUser(servers[2].url, servers[2].accessToken, user.username, user.password) await createUser(servers[2].url, servers[2].accessToken, user.username, user.password)
const userAccessToken = await getUserAccessToken(servers[2], user) const userAccessToken = await getUserAccessToken(servers[2], user)
const res = await getVideosList(servers[2].url) const resVideos = await getVideosList(servers[ 2 ].url)
const video4 = res.body.data.find(v => v.name === 'server3-4') const video4 = resVideos.body.data.find(v => v.name === 'server3-4')
{
await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like') await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like')
await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike') await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike')
} }
{
const text = 'my super first comment'
const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text)
const threadId = res.body.comment.id
const text1 = 'my super answer to thread 1'
const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1)
const childCommentId = childCommentRes.body.comment.id
const text2 = 'my super answer to answer of thread 1'
await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2)
const text3 = 'my second answer to thread 1'
await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
}
}
await wait(5000) await wait(5000)
// Server 1 follows server 3 // Server 1 follows server 3
@ -249,6 +263,45 @@ describe('Test follows', function () {
expect(torrent.files).to.be.an('array') expect(torrent.files).to.be.an('array')
expect(torrent.files.length).to.equal(1) expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('') expect(torrent.files[0].path).to.exist.and.to.not.equal('')
{
const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5)
expect(res1.body.total).to.equal(1)
expect(res1.body.data).to.be.an('array')
expect(res1.body.data).to.have.lengthOf(1)
const comment: VideoComment = res1.body.data[0]
expect(comment.inReplyToCommentId).to.be.null
expect(comment.text).equal('my super first comment')
expect(comment.videoId).to.equal(video4.id)
expect(comment.id).to.equal(comment.threadId)
expect(comment.account.name).to.equal('root')
expect(comment.account.host).to.equal('localhost:9003')
expect(comment.totalReplies).to.equal(3)
expect(dateIsValid(comment.createdAt as string)).to.be.true
expect(dateIsValid(comment.updatedAt as string)).to.be.true
const threadId = comment.threadId
const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId)
const tree: VideoCommentThreadTree = res2.body
expect(tree.comment.text).equal('my super first comment')
expect(tree.children).to.have.lengthOf(2)
const firstChild = tree.children[0]
expect(firstChild.comment.text).to.equal('my super answer to thread 1')
expect(firstChild.children).to.have.lengthOf(1)
const childOfFirstChild = firstChild.children[0]
expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
expect(childOfFirstChild.children).to.have.lengthOf(0)
const secondChild = tree.children[1]
expect(secondChild.comment.text).to.equal('my second answer to thread 1')
expect(secondChild.children).to.have.lengthOf(0)
}
}) })
after(async function () { after(async function () {