forked from FoundKeyGang/FoundKey
Add unit tests for block & unblock federation
This commit is contained in:
parent
5038eb3ac4
commit
4c72343d03
3 changed files with 150 additions and 4 deletions
|
@ -49,6 +49,7 @@
|
|||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"cross-env": "7.0.3",
|
||||
"cypress": "10.3.0",
|
||||
"sinon": "11.1.2",
|
||||
"start-server-and-test": "1.14.0",
|
||||
"typescript": "4.8.3"
|
||||
},
|
||||
|
|
60
packages/backend/test/services/blocking.ts
Normal file
60
packages/backend/test/services/blocking.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as childProcess from 'child_process';
|
||||
import { async, signup, request, post, startServer, shutdownServer, initTestDb } from '../utils';
|
||||
import * as sinon from 'sinon';
|
||||
import config from '@/config/index';
|
||||
|
||||
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 activityPub.federateBlocks is false', 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');
|
||||
config.activityPub = {
|
||||
federateBlocks: false
|
||||
};
|
||||
const spy = sinon.spy(queues, 'deliver');
|
||||
await createBlock(alice, carol);
|
||||
await deleteBlock(alice, carol);
|
||||
assert(spy.notCalled);
|
||||
});
|
||||
});
|
93
yarn.lock
93
yarn.lock
|
@ -1440,7 +1440,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/commons@npm:^1.7.0":
|
||||
"@sinonjs/commons@npm:^1.6.0, @sinonjs/commons@npm:^1.7.0, @sinonjs/commons@npm:^1.8.3":
|
||||
version: 1.8.3
|
||||
resolution: "@sinonjs/commons@npm:1.8.3"
|
||||
dependencies:
|
||||
|
@ -1449,7 +1449,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/fake-timers@npm:9.1.2":
|
||||
"@sinonjs/fake-timers@npm:9.1.2, @sinonjs/fake-timers@npm:>=5":
|
||||
version: 9.1.2
|
||||
resolution: "@sinonjs/fake-timers@npm:9.1.2"
|
||||
dependencies:
|
||||
|
@ -1458,6 +1458,15 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/fake-timers@npm:^7.1.2":
|
||||
version: 7.1.2
|
||||
resolution: "@sinonjs/fake-timers@npm:7.1.2"
|
||||
dependencies:
|
||||
"@sinonjs/commons": ^1.7.0
|
||||
checksum: c84773d7973edad5511a31d2cc75023447b5cf714a84de9bb50eda45dda88a0d3bd2c30bf6e6e936da50a048d5352e2151c694e13e59b97d187ba1f329e9a00c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/fake-timers@npm:^8.0.1":
|
||||
version: 8.1.0
|
||||
resolution: "@sinonjs/fake-timers@npm:8.1.0"
|
||||
|
@ -1467,6 +1476,24 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/samsam@npm:^6.0.2":
|
||||
version: 6.1.1
|
||||
resolution: "@sinonjs/samsam@npm:6.1.1"
|
||||
dependencies:
|
||||
"@sinonjs/commons": ^1.6.0
|
||||
lodash.get: ^4.4.2
|
||||
type-detect: ^4.0.8
|
||||
checksum: a09b0914bf573f0da82bd03c64ba413df81a7c173818dc3f0a90c2652240ac835ef583f4d52f0b215e626633c91a4095c255e0669f6ead97241319f34f05e7fc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinonjs/text-encoding@npm:^0.7.1":
|
||||
version: 0.7.2
|
||||
resolution: "@sinonjs/text-encoding@npm:0.7.2"
|
||||
checksum: fe690002a32ba06906cf87e2e8fe84d1590294586f2a7fd180a65355b53660c155c3273d8011a5f2b77209b819aa7306678ae6e4aea0df014bd7ffd4bbbcf1ab
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sqltools/formatter@npm:^1.2.2":
|
||||
version: 1.2.3
|
||||
resolution: "@sqltools/formatter@npm:1.2.3"
|
||||
|
@ -5917,6 +5944,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"diff@npm:^5.0.0":
|
||||
version: 5.1.0
|
||||
resolution: "diff@npm:5.1.0"
|
||||
checksum: c7bf0df7c9bfbe1cf8a678fd1b2137c4fb11be117a67bc18a0e03ae75105e8533dbfb1cda6b46beb3586ef5aed22143ef9d70713977d5fb1f9114e21455fba90
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dijkstrajs@npm:^1.0.1":
|
||||
version: 1.0.2
|
||||
resolution: "dijkstrajs@npm:1.0.2"
|
||||
|
@ -7866,6 +7900,7 @@ __metadata:
|
|||
gulp-replace: 1.1.3
|
||||
gulp-terser: 2.1.0
|
||||
js-yaml: 4.1.0
|
||||
sinon: 11.1.2
|
||||
start-server-and-test: 1.14.0
|
||||
typescript: 4.8.3
|
||||
languageName: unknown
|
||||
|
@ -9764,6 +9799,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"isarray@npm:0.0.1":
|
||||
version: 0.0.1
|
||||
resolution: "isarray@npm:0.0.1"
|
||||
checksum: 49191f1425681df4a18c2f0f93db3adb85573bcdd6a4482539d98eac9e705d8961317b01175627e860516a2fc45f8f9302db26e5a380a97a520e272e2a40a8d4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"isarray@npm:1.0.0, isarray@npm:^1.0.0, isarray@npm:~1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "isarray@npm:1.0.0"
|
||||
|
@ -10808,6 +10850,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"just-extend@npm:^4.0.2":
|
||||
version: 4.2.1
|
||||
resolution: "just-extend@npm:4.2.1"
|
||||
checksum: ff9fdede240fad313efeeeb68a660b942e5586d99c0058064c78884894a2690dc09bba44c994ad4e077e45d913fef01a9240c14a72c657b53687ac58de53b39c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jwa@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "jwa@npm:2.0.0"
|
||||
|
@ -12262,6 +12311,19 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"nise@npm:^5.1.0":
|
||||
version: 5.1.1
|
||||
resolution: "nise@npm:5.1.1"
|
||||
dependencies:
|
||||
"@sinonjs/commons": ^1.8.3
|
||||
"@sinonjs/fake-timers": ">=5"
|
||||
"@sinonjs/text-encoding": ^0.7.1
|
||||
just-extend: ^4.0.2
|
||||
path-to-regexp: ^1.7.0
|
||||
checksum: d8be29e84a014743c9a10f428fac86f294ac5f92bed1f606fe9b551e935f494d8e0ce1af8a12673c6014010ec7f771f2d48aa5c8e116f223eb4f40c5e1ab44b3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-abi@npm:^3.3.0":
|
||||
version: 3.24.0
|
||||
resolution: "node-abi@npm:3.24.0"
|
||||
|
@ -13133,6 +13195,15 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"path-to-regexp@npm:^1.7.0":
|
||||
version: 1.8.0
|
||||
resolution: "path-to-regexp@npm:1.8.0"
|
||||
dependencies:
|
||||
isarray: 0.0.1
|
||||
checksum: 709f6f083c0552514ef4780cb2e7e4cf49b0cc89a97439f2b7cc69a608982b7690fb5d1720a7473a59806508fc2dae0be751ba49f495ecf89fd8fbc62abccbcd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"path-to-regexp@npm:^6.1.0":
|
||||
version: 6.2.1
|
||||
resolution: "path-to-regexp@npm:6.2.1"
|
||||
|
@ -15353,6 +15424,20 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"sinon@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "sinon@npm:11.1.2"
|
||||
dependencies:
|
||||
"@sinonjs/commons": ^1.8.3
|
||||
"@sinonjs/fake-timers": ^7.1.2
|
||||
"@sinonjs/samsam": ^6.0.2
|
||||
diff: ^5.0.0
|
||||
nise: ^5.1.0
|
||||
supports-color: ^7.2.0
|
||||
checksum: 1d01377e230c9ba976bf33f28b588bae7901b0b5a503d2f6b2a7914b0dbaa9f09823481926c6f2abed820123c7fa865519695af3ae2e9ba18d8b025616163501
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"sisteransi@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "sisteransi@npm:1.0.5"
|
||||
|
@ -16054,7 +16139,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0":
|
||||
"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0, supports-color@npm:^7.2.0":
|
||||
version: 7.2.0
|
||||
resolution: "supports-color@npm:7.2.0"
|
||||
dependencies:
|
||||
|
@ -16764,7 +16849,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"type-detect@npm:4.0.8":
|
||||
"type-detect@npm:4.0.8, type-detect@npm:^4.0.8":
|
||||
version: 4.0.8
|
||||
resolution: "type-detect@npm:4.0.8"
|
||||
checksum: 62b5628bff67c0eb0b66afa371bd73e230399a8d2ad30d852716efcc4656a7516904570cd8631a49a3ce57c10225adf5d0cbdcb47f6b0255fe6557c453925a15
|
||||
|
|
Loading…
Reference in a new issue