From: Chocobozzz Date: Mon, 19 Nov 2018 16:08:18 +0000 (+0100) Subject: Cleanup tests imports X-Git-Tag: v1.1.0-rc.1~18 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d175a6f7ab9dd53e36f9f52769ac02dbfdc57e3e;p=oweals%2Fpeertube.git Cleanup tests imports --- diff --git a/scripts/travis.sh b/scripts/travis.sh index 49b7233e1..509b40d87 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -11,28 +11,25 @@ killall -q peertube || true if [ "$1" = "misc" ]; then npm run build -- --light-fr - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/client.ts \ + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/client.ts \ server/tests/feeds/index.ts \ server/tests/misc-endpoints.ts \ server/tests/helpers/index.ts -elif [ "$1" = "api" ]; then - npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/api/index.ts elif [ "$1" = "cli" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/cli/index.ts + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/cli/index.ts elif [ "$1" = "api-1" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/api/index-1.ts + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-1.ts elif [ "$1" = "api-2" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/api/index-2.ts + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-2.ts elif [ "$1" = "api-3" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/api/index-3.ts + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-3.ts elif [ "$1" = "api-4" ]; then npm run build:server - mocha --timeout 5000 --exit --require ts-node/register/type-check --bail server/tests/api/index-4.ts + mocha --timeout 5000 --exit --require ts-node/register --bail server/tests/api/index-4.ts elif [ "$1" = "lint" ]; then npm run tslint -- --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" "shared/**/*.ts" diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 8b9045038..b59e7e40e 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -1,7 +1,7 @@ import * as ffmpeg from 'fluent-ffmpeg' import { join } from 'path' import { getTargetBitrate, VideoResolution } from '../../shared/models/videos' -import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers' +import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' import { processImage } from './image-utils' import { logger } from './logger' import { checkFFmpegEncoders } from '../initializers/checker-before-init' diff --git a/server/lib/user.ts b/server/lib/user.ts index acb883e23..29d6d087d 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -17,10 +17,8 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse validate: validateUser } - const [ userCreated, accountCreated ] = await Promise.all([ - userToCreate.save(userOptions), - createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) - ]) + const userCreated = await userToCreate.save(userOptions) + const accountCreated = await createLocalAccountWithoutKeys(userCreated.username, userCreated.id, null, t) userCreated.Account = accountCreated let channelName = userCreated.username + '_channel' diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 34aafa1a7..1843603f1 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -1,6 +1,6 @@ import * as Sequelize from 'sequelize' import { - AfterDelete, + AfterDestroy, AfterUpdate, AllowNull, BeforeCreate, @@ -179,7 +179,7 @@ export class UserModel extends Model { } @AfterUpdate - @AfterDelete + @AfterDestroy static removeTokenCache (instance: UserModel) { return clearCacheByUserId(instance.id) } diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index ecf846821..08d892da4 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts @@ -1,5 +1,5 @@ import { - AfterDelete, + AfterDestroy, AfterUpdate, AllowNull, BelongsTo, @@ -126,7 +126,7 @@ export class OAuthTokenModel extends Model { OAuthClients: OAuthClientModel[] @AfterUpdate - @AfterDelete + @AfterDestroy static removeTokenCache (token: OAuthTokenModel) { return clearCacheByToken(token.accessToken) } diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index e7899bb14..7349749f1 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -2,12 +2,13 @@ import 'mocha' -import { flushAndRunMultipleServers, flushTests, killallServers, makePOSTAPRequest, makeFollowRequest, ServerInfo } from '../../utils' +import { flushAndRunMultipleServers, flushTests, killallServers, ServerInfo } from '../../utils' import { HTTP_SIGNATURE } from '../../../initializers' import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' import * as chai from 'chai' import { setActorField } from '../../utils/miscs/sql' import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' +import { makeFollowRequest, makePOSTAPRequest } from '../../utils/requests/activitypub' const expect = chai.expect diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts index 0a1b8b0b2..ff433315d 100644 --- a/server/tests/api/users/index.ts +++ b/server/tests/api/users/index.ts @@ -1,5 +1,5 @@ import './blocklist' import './user-subscriptions' import './users' -import './users-verification' import './users-multiple-servers' +import './users-verification' diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts index 7bf39dc99..fab577b30 100644 --- a/server/tests/api/videos/video-blacklist-management.ts +++ b/server/tests/api/videos/video-blacklist-management.ts @@ -1,7 +1,7 @@ /* tslint:disable:no-unused-expression */ import * as chai from 'chai' -import * as lodash from 'lodash' +import { orderBy } from 'lodash' import 'mocha' import { addVideoToBlacklist, @@ -22,7 +22,6 @@ import { waitJobs } from '../../utils/server/jobs' import { VideoAbuse } from '../../../../shared/models/videos' const expect = chai.expect -const orderBy = lodash.orderBy describe('Test video blacklist management', function () { let servers: ServerInfo[] = [] diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 8138c65d6..41429a3d8 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -7,10 +7,12 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getVideoChannelVideos, serverLogin, testImage, + getVideoChannelVideos, + testImage, updateVideo, updateVideoChannelAvatar, - uploadVideo, wait, userLogin + uploadVideo, + userLogin } from '../../utils' import { addVideoChannel, diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index a260fa4da..b226a9d50 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -16,7 +16,6 @@ import { uploadVideo, wait } from '../../utils' -import { join } from 'path' import { waitJobs } from '../../utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 85795d2ed..23920d452 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -3,13 +3,13 @@ import * as chai from 'chai' import 'mocha' import { omit } from 'lodash' -import * as ffmpeg from 'fluent-ffmpeg' import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { buildAbsoluteFixturePath, doubleFollow, flushAndRunMultipleServers, + generateHighBitrateVideo, getMyVideos, getVideo, getVideosList, @@ -18,12 +18,10 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - webtorrentAdd, - generateHighBitrateVideo + webtorrentAdd } from '../../utils' import { join } from 'path' import { waitJobs } from '../../utils/server/jobs' -import { pathExists } from 'fs-extra' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' const expect = chai.expect diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 905d93823..8349631c9 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts @@ -7,7 +7,6 @@ export * from './miscs/miscs' export * from './miscs/stubs' export * from './server/follows' export * from './requests/requests' -export * from './requests/activitypub' export * from './server/servers' export * from './videos/services' export * from './users/users' diff --git a/server/tests/utils/requests/check-api-params.ts b/server/tests/utils/requests/check-api-params.ts index edb47e0e9..a2a549682 100644 --- a/server/tests/utils/requests/check-api-params.ts +++ b/server/tests/utils/requests/check-api-params.ts @@ -1,5 +1,5 @@ import { makeGetRequest } from './requests' -import { immutableAssign } from '..' +import { immutableAssign } from '../miscs/miscs' function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { return makeGetRequest({ diff --git a/server/tests/utils/search/videos.ts b/server/tests/utils/search/videos.ts index 3a0c10e42..8c0037ccc 100644 --- a/server/tests/utils/search/videos.ts +++ b/server/tests/utils/search/videos.ts @@ -2,7 +2,7 @@ import * as request from 'supertest' import { VideosSearchQuery } from '../../../../shared/models/search' -import { immutableAssign } from '..' +import { immutableAssign } from '../miscs/miscs' function searchVideo (url: string, search: string) { const path = '/api/v1/search/videos' diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index b85e02ab7..aa3100d34 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts @@ -1,4 +1,4 @@ -import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' +import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' import { CustomConfig } from '../../../../shared/models/server/custom-config.model' function getConfig (url: string) { diff --git a/server/tests/utils/server/jobs.ts b/server/tests/utils/server/jobs.ts index 4c02cace5..26180ec72 100644 --- a/server/tests/utils/server/jobs.ts +++ b/server/tests/utils/server/jobs.ts @@ -1,6 +1,7 @@ import * as request from 'supertest' import { Job, JobState } from '../../../../shared/models' -import { ServerInfo, wait } from '../index' +import { ServerInfo } from './servers' +import { wait } from '../miscs/miscs' function getJobsList (url: string, accessToken: string, state: JobState) { const path = '/api/v1/jobs/' + state diff --git a/server/tests/utils/server/stats.ts b/server/tests/utils/server/stats.ts index 01989d952..6f079ad18 100644 --- a/server/tests/utils/server/stats.ts +++ b/server/tests/utils/server/stats.ts @@ -1,4 +1,4 @@ -import { makeGetRequest } from '../' +import { makeGetRequest } from '../requests/requests' function getStats (url: string, useCache = false) { const path = '/api/v1/server/stats' diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts index f82b8d906..257fa5b27 100644 --- a/server/tests/utils/users/accounts.ts +++ b/server/tests/utils/users/accounts.ts @@ -4,7 +4,7 @@ import { expect } from 'chai' import { existsSync, readdir } from 'fs-extra' import { join } from 'path' import { Account } from '../../../../shared/models/actors' -import { root } from '../index' +import { root } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { diff --git a/server/tests/utils/users/blocklist.ts b/server/tests/utils/users/blocklist.ts index 35b537571..0ead5e5f6 100644 --- a/server/tests/utils/users/blocklist.ts +++ b/server/tests/utils/users/blocklist.ts @@ -1,6 +1,6 @@ /* tslint:disable:no-unused-expression */ -import { makeDeleteRequest, makePostBodyRequest } from '../index' +import { makeDeleteRequest, makePostBodyRequest } from '../requests/requests' import { makeGetRequest } from '../requests/requests' function getAccountBlocklistByAccount ( diff --git a/server/tests/utils/users/user-subscriptions.ts b/server/tests/utils/users/user-subscriptions.ts index b0e7da7cc..7148fbfca 100644 --- a/server/tests/utils/users/user-subscriptions.ts +++ b/server/tests/utils/users/user-subscriptions.ts @@ -1,4 +1,4 @@ -import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../' +import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests' function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = 204) { const path = '/api/v1/users/me/subscriptions' diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index d77233d62..2c21a9ecf 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -1,5 +1,5 @@ import * as request from 'supertest' -import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../' +import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' import { UserRole } from '../../../../shared/index' import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type' diff --git a/server/tests/utils/videos/video-abuses.ts b/server/tests/utils/videos/video-abuses.ts index 14907e6a0..4ad82ad8c 100644 --- a/server/tests/utils/videos/video-abuses.ts +++ b/server/tests/utils/videos/video-abuses.ts @@ -1,6 +1,6 @@ import * as request from 'supertest' import { VideoAbuseUpdate } from '../../../../shared/models/videos/abuse/video-abuse-update.model' -import { makeDeleteRequest, makePutBodyRequest } from '..' +import { makeDeleteRequest, makePutBodyRequest } from '../requests/requests' function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 200) { const path = '/api/v1/videos/' + videoId + '/abuse' diff --git a/server/tests/utils/videos/video-captions.ts b/server/tests/utils/videos/video-captions.ts index 41e52be07..8d67f617b 100644 --- a/server/tests/utils/videos/video-captions.ts +++ b/server/tests/utils/videos/video-captions.ts @@ -1,7 +1,7 @@ -import { makeDeleteRequest, makeGetRequest } from '../' -import { buildAbsoluteFixturePath, makeUploadRequest } from '../index' +import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests' import * as request from 'supertest' import * as chai from 'chai' +import { buildAbsoluteFixturePath } from '../miscs/miscs' const expect = chai.expect diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts index 092985777..70e8d1a6b 100644 --- a/server/tests/utils/videos/video-channels.ts +++ b/server/tests/utils/videos/video-channels.ts @@ -1,6 +1,6 @@ import * as request from 'supertest' import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' -import { updateAvatarRequest } from '../index' +import { updateAvatarRequest } from '../requests/requests' function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/video-channels' diff --git a/server/tests/utils/videos/video-comments.ts b/server/tests/utils/videos/video-comments.ts index 7d4cae364..0ebf69ced 100644 --- a/server/tests/utils/videos/video-comments.ts +++ b/server/tests/utils/videos/video-comments.ts @@ -1,5 +1,5 @@ import * as request from 'supertest' -import { makeDeleteRequest } from '../' +import { makeDeleteRequest } from '../requests/requests' function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { const path = '/api/v1/videos/' + videoId + '/comment-threads' diff --git a/server/tests/utils/videos/video-imports.ts b/server/tests/utils/videos/video-imports.ts index 59dfd481a..eb985a5b1 100644 --- a/server/tests/utils/videos/video-imports.ts +++ b/server/tests/utils/videos/video-imports.ts @@ -1,5 +1,5 @@ import { VideoImportCreate } from '../../../../shared/models/videos' -import { makeGetRequest, makeUploadRequest } from '..' +import { makeGetRequest, makeUploadRequest } from '../requests/requests' function getYoutubeVideoUrl () { return 'https://youtu.be/msX3jv1XdvM' diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 87c385f38..d6c3e5dac 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -17,8 +17,8 @@ import { testImage } from '../' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' -import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' -import { dateIsValid, webtorrentAdd } from '../index' +import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' +import { dateIsValid, webtorrentAdd } from '../miscs/miscs' type VideoAttributes = { name?: string