✌️
This commit is contained in:
parent
b01a6cbbb7
commit
6b82d3a1d4
|
@ -26,11 +26,6 @@ export const meta = {
|
|||
},
|
||||
|
||||
errors: {
|
||||
noSuchMoveTarget: {
|
||||
message: 'No such move target.',
|
||||
code: 'NO_SUCH_MOVE_TARGET',
|
||||
id: 'b5c90186-4ab0-49c8-9bba-a1f76c202ba4',
|
||||
},
|
||||
destinationAccountForbids: {
|
||||
message:
|
||||
'Destination account doesn\'t have proper \'Known As\' alias. Did you remember to set it?',
|
||||
|
@ -89,25 +84,25 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
// check parameter
|
||||
if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||
if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchUser);
|
||||
// abort if user is the root
|
||||
if (me.isRoot) throw new ApiError(meta.errors.rootForbidden);
|
||||
// abort if user has already moved
|
||||
if (me.movedToUri) throw new ApiError(meta.errors.alreadyMoved);
|
||||
|
||||
let unfiltered = ps.moveToAccount;
|
||||
if (!unfiltered) throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||
if (!unfiltered) throw new ApiError(meta.errors.noSuchUser);
|
||||
|
||||
// parse user's input into the destination account
|
||||
if (unfiltered.startsWith('acct:')) unfiltered = unfiltered.substring(5);
|
||||
if (unfiltered.startsWith('@')) unfiltered = unfiltered.substring(1);
|
||||
if (!unfiltered.includes('@')) throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||
if (!unfiltered.includes('@')) throw new ApiError(meta.errors.noSuchUser);
|
||||
|
||||
const userAddress = unfiltered.split('@');
|
||||
// retrieve the destination account
|
||||
let moveTo = await this.remoteUserResolveService.resolveUser(userAddress[0], userAddress[1]).catch((e) => {
|
||||
this.apiLoggerService.logger.warn(`failed to resolve remote user: ${e}`);
|
||||
throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
});
|
||||
const destination = await this.getterService.getUser(moveTo.id);
|
||||
const newUri = this.accountMoveService.getUserUri(destination);
|
||||
|
|
|
@ -4,8 +4,9 @@ import * as assert from 'assert';
|
|||
// node-fetch only supports it's own Blob yet
|
||||
// https://github.com/node-fetch/node-fetch/pull/1664
|
||||
import { Blob } from 'node-fetch';
|
||||
import { startServer, signup, post, api, uploadFile, simpleGet } from '../utils.js';
|
||||
import { startServer, signup, post, api, uploadFile, simpleGet, initTestDb } from '../utils.js';
|
||||
import type { INestApplicationContext } from '@nestjs/common';
|
||||
import { User } from '@/models/index.js';
|
||||
|
||||
describe('Endpoints', () => {
|
||||
let app: INestApplicationContext;
|
||||
|
@ -289,6 +290,16 @@ describe('Endpoints', () => {
|
|||
}, bob);
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
|
||||
const connection = await initTestDb(false);
|
||||
const Users = connection.getRepository(User);
|
||||
const newBob = await Users.findOneByOrFail({ id: bob.id });
|
||||
assert.strictEqual(newBob.followersCount, 0);
|
||||
assert.strictEqual(newBob.followingCount, 1);
|
||||
const newAlice = await Users.findOneByOrFail({ id: alice.id });
|
||||
assert.strictEqual(newAlice.followersCount, 1);
|
||||
assert.strictEqual(newAlice.followingCount, 0);
|
||||
connection.destroy();
|
||||
});
|
||||
|
||||
test('既にフォローしている場合は怒る', async () => {
|
||||
|
@ -341,6 +352,16 @@ describe('Endpoints', () => {
|
|||
}, bob);
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
|
||||
const connection = await initTestDb(false);
|
||||
const Users = connection.getRepository(User);
|
||||
const newBob = await Users.findOneByOrFail({ id: bob.id });
|
||||
assert.strictEqual(newBob.followersCount, 0);
|
||||
assert.strictEqual(newBob.followingCount, 0);
|
||||
const newAlice = await Users.findOneByOrFail({ id: alice.id });
|
||||
assert.strictEqual(newAlice.followersCount, 0);
|
||||
assert.strictEqual(newAlice.followingCount, 0);
|
||||
connection.destroy();
|
||||
});
|
||||
|
||||
test('フォローしていない場合は怒る', async () => {
|
||||
|
|
Loading…
Reference in a new issue