FoundKey/packages/backend/test/services/blocking.ts
Norm 71b3b5a60c backend: implement not forwarding block activities (#212)
Fixes FoundKeyGang/FoundKey#211

Commits pulled from https://github.com/misskey-dev/misskey/pull/7799

Changelog: Added
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk>
Co-authored-by: Johann150 <johann.galle@protonmail.com>
Co-authored-by: Francis Dinh <normandy@biribiri.dev>
Reviewed-on: FoundKeyGang/FoundKey#212
2022-11-17 21:24:38 +00:00

58 lines
1.7 KiB
TypeScript

process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import * as childProcess from 'child_process';
import * as sinon from 'sinon';
import { async, signup, startServer, shutdownServer, initTestDb } from '../utils.js';
describe('Creating a block activity', () => {
let p: childProcess.ChildProcess;
// alice blocks bob
let alice: any;
let bob: any;
let carol: any;
before(async () => {
await initTestDb();
p = await startServer();
alice = await signup({ username: 'alice' });
bob = await signup({ username: 'bob' });
carol = await signup({ username: 'carol' });
bob.host = 'http://remote';
carol.host = 'http://remote';
});
beforeEach(() => {
sinon.restore();
});
after(async () => {
await shutdownServer(p);
});
it('Should federate blocks normally', async(async () => {
const createBlock = (await import('../../src/services/blocking/create')).default;
const deleteBlock = (await import('../../src/services/blocking/delete')).default;
const queues = await import('../../src/queue/index');
const spy = sinon.spy(queues, 'deliver');
await createBlock(alice, bob);
assert(spy.calledOnce);
await deleteBlock(alice, bob);
assert(spy.calledTwice);
}));
it('Should not federate blocks if federateBlocks is false', async () => {
const createBlock = (await import('../../src/services/blocking/create')).default;
const deleteBlock = (await import('../../src/services/blocking/delete')).default;
alice.federateBlocks = true;
const queues = await import('../../src/queue/index');
const spy = sinon.spy(queues, 'deliver');
await createBlock(alice, carol);
await deleteBlock(alice, carol);
assert(spy.notCalled);
});
});