1
0
Fork 0

Introduce accounts command

This commit is contained in:
Chocobozzz 2021-07-07 13:38:26 +02:00
parent 87e2635a50
commit 9fff08cf83
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
15 changed files with 172 additions and 167 deletions

View File

@ -1,8 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, closeAllSequelize, cleanupTests,
closeAllSequelize,
createVideoPlaylist, createVideoPlaylist,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
@ -21,10 +23,8 @@ import {
uploadVideoAndGetId, uploadVideoAndGetId,
wait, wait,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { getAccount } from '../../../../shared/extra-utils/users/accounts' import { VideoPlaylistPrivacy } from '@shared/models'
import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test AP refresher', function () { describe('Test AP refresher', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
@ -116,19 +116,21 @@ describe('Test AP refresher', function () {
it('Should remove a deleted actor', async function () { it('Should remove a deleted actor', async function () {
this.timeout(60000) this.timeout(60000)
const command = servers[0].accountsCommand
await wait(10000) await wait(10000)
// Change actor name so the remote server returns a 404 // Change actor name so the remote server returns a 404
const to = 'http://localhost:' + servers[1].port + '/accounts/user2' const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) await command.get({ accountName: 'user1@localhost:' + servers[1].port })
await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) await command.get({ accountName: 'user2@localhost:' + servers[1].port })
await waitJobs(servers) await waitJobs(servers)
await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
}) })

View File

@ -1,15 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
import { import {
checkBadCountPagination, checkBadCountPagination,
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination checkBadStartPagination,
} from '../../../../shared/extra-utils/requests/check-api-params' cleanupTests,
import { getAccount } from '../../../../shared/extra-utils/users/accounts' flushAndRunServer,
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' ServerInfo
} from '@shared/extra-utils'
describe('Test accounts API validators', function () { describe('Test accounts API validators', function () {
const path = '/api/v1/accounts/' const path = '/api/v1/accounts/'
@ -38,8 +38,9 @@ describe('Test accounts API validators', function () {
}) })
describe('When getting an account', function () { describe('When getting an account', function () {
it('Should return 404 with a non existing name', async function () { it('Should return 404 with a non existing name', async function () {
await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
}) })

View File

@ -13,7 +13,6 @@ import {
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
generateUserAccessToken, generateUserAccessToken,
getAccount,
getVideoCommentThreads, getVideoCommentThreads,
getVideoIdFromUUID, getVideoIdFromUUID,
getVideosList, getVideosList,
@ -606,10 +605,8 @@ describe('Test abuses', function () {
describe('Account abuses', function () { describe('Account abuses', function () {
async function getAccountFromServer (url: string, name: string, server: ServerInfo) { function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
const res = await getAccount(url, name + '@' + server.host) return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
return res.body as Account
} }
before(async function () { before(async function () {
@ -626,7 +623,7 @@ describe('Test abuses', function () {
it('Should report abuse on an account', async function () { it('Should report abuse on an account', async function () {
this.timeout(15000) this.timeout(15000)
const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
const reason = 'it is a bad account' const reason = 'it is a bad account'
await commands[0].report({ accountId: account.id, reason }) await commands[0].report({ accountId: account.id, reason })
@ -664,7 +661,7 @@ describe('Test abuses', function () {
it('Should report abuse on a remote account', async function () { it('Should report abuse on a remote account', async function () {
this.timeout(10000) this.timeout(10000)
const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
const reason = 'it is a really bad account' const reason = 'it is a really bad account'
await commands[0].report({ accountId: account.id, reason }) await commands[0].report({ accountId: account.id, reason })
@ -718,7 +715,7 @@ describe('Test abuses', function () {
it('Should keep the account abuse when deleting the account', async function () { it('Should keep the account abuse when deleting the account', async function () {
this.timeout(10000) this.timeout(10000)
const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
await removeUser(servers[1].url, account.userId, servers[1].accessToken) await removeUser(servers[1].url, account.userId, servers[1].accessToken)
await waitJobs(servers) await waitJobs(servers)

View File

@ -22,7 +22,6 @@ import {
cleanupTests, cleanupTests,
createUser, createUser,
generateUserAccessToken, generateUserAccessToken,
getAccount,
getVideoCommentThreads, getVideoCommentThreads,
getVideoIdFromUUID, getVideoIdFromUUID,
immutableAssign, immutableAssign,
@ -157,8 +156,8 @@ describe('Test moderation notifications', function () {
await waitJobs(servers) await waitJobs(servers)
const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host })
await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' })
await waitJobs(servers) await waitJobs(servers)
await checkNewAccountAbuseForModerators(baseParams, username, 'presence') await checkNewAccountAbuseForModerators(baseParams, username, 'presence')

View File

@ -242,16 +242,16 @@ describe('Test follows', function () {
}) })
it('Should have the correct follows counts', async function () { it('Should have the correct follows counts', async function () {
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
// Server 2 and 3 does not know server 1 follow another server (there was not a refresh) // Server 2 and 3 does not know server 1 follow another server (there was not a refresh)
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
}) })
it('Should unfollow server 3 on server 1', async function () { it('Should unfollow server 3 on server 1', async function () {
@ -283,14 +283,14 @@ describe('Test follows', function () {
}) })
it('Should have the correct follows counts 2', async function () { it('Should have the correct follows counts 2', async function () {
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 })
}) })
it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
@ -404,15 +404,15 @@ describe('Test follows', function () {
}) })
it('Should have the correct follows counts 3', async function () { it('Should have the correct follows counts 3', async function () {
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
}) })
it('Should have propagated videos', async function () { it('Should have propagated videos', async function () {

View File

@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha' import 'mocha'
import { Account } from '../../../../shared/models/actors' import * as chai from 'chai'
import { import {
checkActorFilesWereRemoved,
checkTmpIsEmpty, checkTmpIsEmpty,
checkVideoFilesWereRemoved, checkVideoFilesWereRemoved,
cleanupTests, cleanupTests,
@ -11,17 +11,19 @@ import {
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos, getAccountVideos,
getMyUserInformation,
getVideoChannelsList, getVideoChannelsList,
removeUser, removeUser,
ServerInfo,
setAccessTokensToServers,
testImage,
updateMyAvatar,
updateMyUser, updateMyUser,
userLogin uploadVideo,
} from '../../../../shared/extra-utils' userLogin,
import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' waitJobs
import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' } from '@shared/extra-utils'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { User, VideoChannel } from '@shared/models'
import { User } from '../../../../shared/models/users'
import { VideoChannel } from '../../../../shared/models/videos'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
const expect = chai.expect const expect = chai.expect
@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () {
let createdAt: string | Date let createdAt: string | Date
for (const server of servers) { for (const server of servers) {
const resAccounts = await getAccountsList(server.url, '-createdAt') const body = await server.accountsCommand.list({ sort: '-createdAt' })
const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
expect(resList).not.to.be.undefined expect(resList).not.to.be.undefined
const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
const account = resAccount.body as Account
if (!createdAt) createdAt = account.createdAt if (!createdAt) createdAt = account.createdAt
@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () {
this.timeout(10_000) this.timeout(10_000)
for (const server of servers) { for (const server of servers) {
const resAccounts = await getAccountsList(server.url, '-createdAt') const body = await server.accountsCommand.list({ sort: '-createdAt' })
const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
expect(accountDeleted).not.to.be.undefined expect(accountDeleted).not.to.be.undefined
const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () {
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
const resAccounts = await getAccountsList(server.url, '-createdAt') const body = await server.accountsCommand.list({ sort: '-createdAt' })
const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
expect(accountDeleted).to.be.undefined expect(accountDeleted).to.be.undefined
const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)

View File

@ -11,7 +11,6 @@ import {
createUser, createUser,
deleteMe, deleteMe,
flushAndRunServer, flushAndRunServer,
getAccountRatings,
getBlacklistedVideosList, getBlacklistedVideosList,
getMyUserInformation, getMyUserInformation,
getMyUserVideoQuotaUsed, getMyUserVideoQuotaUsed,
@ -194,25 +193,22 @@ describe('Test users', function () {
it('Should retrieve ratings list', async function () { it('Should retrieve ratings list', async function () {
await rateVideo(server.url, accessToken, videoId, 'like') await rateVideo(server.url, accessToken, videoId, 'like')
const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
const ratings = res.body
expect(ratings.total).to.equal(1) expect(body.total).to.equal(1)
expect(ratings.data[0].video.id).to.equal(videoId) expect(body.data[0].video.id).to.equal(videoId)
expect(ratings.data[0].rating).to.equal('like') expect(body.data[0].rating).to.equal('like')
}) })
it('Should retrieve ratings list by rating type', async function () { it('Should retrieve ratings list by rating type', async function () {
{ {
const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })
const ratings = res.body expect(body.data.length).to.equal(1)
expect(ratings.data.length).to.equal(1)
} }
{ {
const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })
const ratings = res.body expect(body.data.length).to.equal(0)
expect(ratings.data.length).to.equal(0)
} }
}) })
}) })

View File

@ -5,7 +5,7 @@ import * as chai from 'chai'
import { createFile, readdir } from 'fs-extra' import { createFile, readdir } from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { buildUUID } from '@server/helpers/uuid' import { buildUUID } from '@server/helpers/uuid'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '@shared/core-utils'
import { import {
buildServerDirectory, buildServerDirectory,
cleanupTests, cleanupTests,
@ -13,7 +13,6 @@ import {
createVideoPlaylist, createVideoPlaylist,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccount,
killallServers, killallServers,
makeGetRequest, makeGetRequest,
ServerInfo, ServerInfo,
@ -21,10 +20,10 @@ import {
setDefaultVideoChannel, setDefaultVideoChannel,
updateMyAvatar, updateMyAvatar,
uploadVideo, uploadVideo,
wait wait,
} from '../../../shared/extra-utils' waitJobs
import { waitJobs } from '../../../shared/extra-utils/server/jobs' } from '@shared/extra-utils'
import { Account, VideoPlaylistPrivacy } from '../../../shared/models' import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
@ -94,8 +93,7 @@ describe('Test prune storage scripts', function () {
// Lazy load the remote avatar // Lazy load the remote avatar
{ {
const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port) const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port })
const account: Account = res.body
await makeGetRequest({ await makeGetRequest({
url: servers[0].url, url: servers[0].url,
path: account.avatar.path, path: account.avatar.path,
@ -104,8 +102,7 @@ describe('Test prune storage scripts', function () {
} }
{ {
const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port) const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port })
const account: Account = res.body
await makeGetRequest({ await makeGetRequest({
url: servers[1].url, url: servers[1].url,
path: account.avatar.path, path: account.avatar.path,

View File

@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import * as chai from 'chai'
import { import {
addVideoChannel, addVideoChannel,
addVideoCommentThread,
cleanupTests, cleanupTests,
createUser, createUser,
flushAndRunServer, flushAndRunServer,
@ -16,12 +16,10 @@ import {
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo uploadVideo,
} from '../../../shared/extra-utils' waitJobs
import { waitJobs } from '../../../shared/extra-utils/server/jobs' } from '@shared/extra-utils'
import { getAccountsList } from '../../../shared/extra-utils/users/accounts' import { VideoDetails } from '@shared/models'
import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
import { VideoDetails } from '../../../shared/models/videos'
const expect = chai.expect const expect = chai.expect
@ -104,10 +102,10 @@ describe('Test update host scripts', function () {
}) })
it('Should have updated accounts url', async function () { it('Should have updated accounts url', async function () {
const res = await getAccountsList(server.url) const body = await server.accountsCommand.list()
expect(res.body.total).to.equal(3) expect(body.total).to.equal(3)
for (const account of res.body.data) { for (const account of body.data) {
const usernameWithDomain = account.name const usernameWithDomain = account.name
const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)

View File

@ -11,7 +11,6 @@ import {
createVideoPlaylist, createVideoPlaylist,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccount,
getVideosList, getVideosList,
makeGetRequest, makeGetRequest,
makeHTMLRequest, makeHTMLRequest,
@ -105,8 +104,7 @@ describe('Test a client controllers', function () {
await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' }) await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`) account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
account = resAccountRequest.body
await waitJobs(servers) await waitJobs(servers)
}) })

View File

@ -10,17 +10,11 @@ export * from './overviews'
export * from './search' export * from './search'
export * from './server' export * from './server'
export * from './socket' export * from './socket'
export * from './users'
export * from './requests/check-api-params' export * from './requests/check-api-params'
export * from './requests/requests' export * from './requests/requests'
export * from './users/accounts'
export * from './users/blocklist'
export * from './users/login'
export * from './users/user-notifications'
export * from './users/user-subscriptions'
export * from './users/users'
export * from './videos/live' export * from './videos/live'
export * from './videos/services' export * from './videos/services'
export * from './videos/video-blacklist' export * from './videos/video-blacklist'

View File

@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews'
import { makeGetRequest } from '../requests/requests' import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search' import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket' import { SocketIOCommand } from '../socket'
import { AccountsCommand } from '../users'
import { ConfigCommand } from './config-command' import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command' import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command' import { DebugCommand } from './debug-command'
@ -95,6 +96,7 @@ interface ServerInfo {
statsCommand?: StatsCommand statsCommand?: StatsCommand
configCommand?: ConfigCommand configCommand?: ConfigCommand
socketIOCommand?: SocketIOCommand socketIOCommand?: SocketIOCommand
accountsCommand?: AccountsCommand
} }
function parallelTests () { function parallelTests () {
@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
server.statsCommand = new StatsCommand(server) server.statsCommand = new StatsCommand(server)
server.configCommand = new ConfigCommand(server) server.configCommand = new ConfigCommand(server)
server.socketIOCommand = new SocketIOCommand(server) server.socketIOCommand = new SocketIOCommand(server)
server.accountsCommand = new AccountsCommand(server)
res(server) res(server)
}) })

View File

@ -0,0 +1,54 @@
import { ResultList } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { Account } from '../../models/actors'
import { AccountVideoRate, VideoRateType } from '../../models/videos'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class AccountsCommand extends AbstractCommand {
list (options: OverrideCommandOptions & {
sort?: string // default -createdAt
} = {}) {
const { sort = '-createdAt' } = options
const path = '/api/v1/accounts'
return this.getRequestBody<ResultList<Account>>({
...options,
path,
query: { sort },
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
get (options: OverrideCommandOptions & {
accountName: string
}) {
const path = '/api/v1/accounts/' + options.accountName
return this.getRequestBody<Account>({
...options,
path,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
listRatings (options: OverrideCommandOptions & {
accountName: string
rating?: VideoRateType
}) {
const { rating, accountName } = options
const path = '/api/v1/accounts/' + accountName + '/ratings'
const query = { rating }
return this.getRequestBody<ResultList<AccountVideoRate>>({
...options,
path,
query,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}

View File

@ -1,43 +1,25 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as request from 'supertest'
import { expect } from 'chai' import { expect } from 'chai'
import { existsSync, readdir } from 'fs-extra' import { pathExists, readdir } from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { Account } from '../../models/actors' import { root } from '@server/helpers/core-utils'
import { root } from '../miscs/miscs' import { ServerInfo } from '../server'
import { makeGetRequest } from '../requests/requests'
import { VideoRateType } from '../../models/videos'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { async function expectAccountFollows (options: {
const path = '/api/v1/accounts' server: ServerInfo
handle: string
followers: number
following: number
}) {
const { server, handle, followers, following } = options
return makeGetRequest({ const body = await server.accountsCommand.list()
url, const account = body.data.find(a => a.name + '@' + a.host === handle)
query: { sort },
path,
statusCodeExpected
})
}
function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) { const message = `${handle} on ${server.url}`
const path = '/api/v1/accounts/' + accountName expect(account.followersCount).to.equal(followers, message)
expect(account.followingCount).to.equal(following, message)
return makeGetRequest({
url,
path,
statusCodeExpected
})
}
async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
const res = await getAccountsList(url)
const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
const message = `${nameWithDomain} on ${url}`
expect(account.followersCount).to.equal(followersCount, message)
expect(account.followingCount).to.equal(followingCount, message)
} }
async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
@ -46,7 +28,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
for (const directory of [ 'avatars' ]) { for (const directory of [ 'avatars' ]) {
const directoryPath = join(root(), testDirectory, directory) const directoryPath = join(root(), testDirectory, directory)
const directoryExists = existsSync(directoryPath) const directoryExists = await pathExists(directoryPath)
expect(directoryExists).to.be.true expect(directoryExists).to.be.true
const files = await readdir(directoryPath) const files = await readdir(directoryPath)
@ -56,32 +38,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
} }
} }
function getAccountRatings (
url: string,
accountName: string,
accessToken: string,
rating?: VideoRateType,
statusCodeExpected = HttpStatusCode.OK_200
) {
const path = '/api/v1/accounts/' + accountName + '/ratings'
const query = rating ? { rating } : {}
return request(url)
.get(path)
.query(query)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(statusCodeExpected)
.expect('Content-Type', /json/)
}
// ---------------------------------------------------------------------------
export { export {
getAccount,
expectAccountFollows, expectAccountFollows,
getAccountsList, checkActorFilesWereRemoved
checkActorFilesWereRemoved,
getAccountRatings
} }

View File

@ -0,0 +1,8 @@
export * from './accounts'
export * from './accounts-command'
export * from './blocklist'
export * from './login'
export * from './user-notifications'
export * from './user-subscriptions'
export * from './users'