From 0f91ae62df8a37194fea84ce1efa9e733d9c1fd8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 21 Nov 2017 13:43:29 +0100 Subject: Add follow tests --- server/helpers/database-utils.ts | 13 ++++++++----- server/helpers/webfinger.ts | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 169b80065..dacd747c9 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -4,12 +4,15 @@ import * as Bluebird from 'bluebird' import { logger } from './logger' type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } -function retryTransactionWrapper (functionToRetry: (...args) => Promise | Bluebird, options: RetryTransactionWrapperOptions) { +function retryTransactionWrapper ( + functionToRetry: (...args) => Promise | Bluebird, + options: RetryTransactionWrapperOptions +): Promise { const args = options.arguments ? options.arguments : [] - return transactionRetryer(callback => { + return transactionRetryer(callback => { functionToRetry.apply(this, args) - .then(result => callback(null, result)) + .then((result: T) => callback(null, result)) .catch(err => callback(err)) }) .catch(err => { @@ -18,8 +21,8 @@ function retryTransactionWrapper (functionToRetry: (...args) => Promise | B }) } -function transactionRetryer (func: Function) { - return new Promise((res, rej) => { +function transactionRetryer (func: (err: any, data: T) => any) { + return new Promise((res, rej) => { retry({ times: 5, diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts index b7408c845..a5b4785fe 100644 --- a/server/helpers/webfinger.ts +++ b/server/helpers/webfinger.ts @@ -1,9 +1,9 @@ import * as WebFinger from 'webfinger.js' import { WebFingerData } from '../../shared' +import { fetchRemoteAccount } from '../lib/activitypub/account' import { isTestInstance } from './core-utils' import { isActivityPubUrlValid } from './custom-validators' -import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account' const webfinger = new WebFinger({ webfist_fallback: false, @@ -22,10 +22,10 @@ async function getAccountFromWebfinger (nameWithHost: string) { throw new Error('Cannot find self link or href is not a valid URL.') } - const res = await fetchRemoteAccountAndCreateServer(selfLink.href) - if (res === undefined) throw new Error('Cannot fetch and create server of remote account ' + selfLink.href) + const account = await fetchRemoteAccount(selfLink.href) + if (account === undefined) throw new Error('Cannot fetch remote account ' + selfLink.href) - return res.account + return account } // --------------------------------------------------------------------------- -- cgit v1.2.3