mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 05:26:44 +02:00
test: added test to ensure that Likes do not get processed when privilege is rescinded
closes #14019
This commit is contained in:
@@ -10,6 +10,7 @@ const user = require('../../src/user');
|
|||||||
const categories = require('../../src/categories');
|
const categories = require('../../src/categories');
|
||||||
const topics = require('../../src/topics');
|
const topics = require('../../src/topics');
|
||||||
const posts = require('../../src/posts');
|
const posts = require('../../src/posts');
|
||||||
|
const privileges = require('../../src/privileges');
|
||||||
const activitypub = require('../../src/activitypub');
|
const activitypub = require('../../src/activitypub');
|
||||||
const utils = require('../../src/utils');
|
const utils = require('../../src/utils');
|
||||||
|
|
||||||
@@ -108,7 +109,6 @@ describe('Inbox', () => {
|
|||||||
|
|
||||||
describe('Create', () => {
|
describe('Create', () => {
|
||||||
let uid;
|
let uid;
|
||||||
let cid;
|
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
uid = await user.create({ username: utils.generateUUID() });
|
uid = await user.create({ username: utils.generateUUID() });
|
||||||
@@ -173,38 +173,6 @@ describe('Inbox', () => {
|
|||||||
assert.strictEqual(cid, -1);
|
assert.strictEqual(cid, -1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('(Like)', () => {
|
|
||||||
let pid;
|
|
||||||
let voterUid;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
({ cid } = await categories.create({ name: utils.generateUUID() }));
|
|
||||||
const { postData } = await topics.post({
|
|
||||||
uid,
|
|
||||||
cid,
|
|
||||||
title: utils.generateUUID(),
|
|
||||||
content: utils.generateUUID(),
|
|
||||||
});
|
|
||||||
pid = postData.pid;
|
|
||||||
const object = await activitypub.mocks.notes.public(postData);
|
|
||||||
const { activity } = helpers.mocks.like({ object });
|
|
||||||
voterUid = activity.actor;
|
|
||||||
await activitypub.inbox.like({ body: activity });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should increment a like for the post', async () => {
|
|
||||||
const voted = await posts.hasVoted(pid, voterUid);
|
|
||||||
const count = await posts.getPostField(pid, 'upvotes');
|
|
||||||
assert(voted);
|
|
||||||
assert.strictEqual(count, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not append to the uid upvotes zset', async () => {
|
|
||||||
const exists = await db.exists(`uid:${voterUid}:upvote`);
|
|
||||||
assert(!exists);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Announce', () => {
|
describe('Announce', () => {
|
||||||
@@ -406,6 +374,58 @@ describe('Inbox', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Like', () => {
|
||||||
|
before(async function () {
|
||||||
|
const uid = await user.create({ username: utils.generateUUID() });
|
||||||
|
const { cid } = await categories.create({ name: utils.generateUUID() });
|
||||||
|
this.cid = cid;
|
||||||
|
const { postData } = await topics.post({
|
||||||
|
uid,
|
||||||
|
cid,
|
||||||
|
title: utils.generateUUID(),
|
||||||
|
content: utils.generateUUID(),
|
||||||
|
});
|
||||||
|
this.postData = postData;
|
||||||
|
const object = await activitypub.mocks.notes.public(postData);
|
||||||
|
const { activity } = helpers.mocks.like({ object });
|
||||||
|
this.voterUid = activity.actor;
|
||||||
|
await activitypub.inbox.like({ body: activity });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should increment a like for the post', async function () {
|
||||||
|
const voted = await posts.hasVoted(this.postData.pid, this.voterUid);
|
||||||
|
const count = await posts.getPostField(this.postData.pid, 'upvotes');
|
||||||
|
assert(voted);
|
||||||
|
assert.strictEqual(count, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not append to the uid upvotes zset', async function () {
|
||||||
|
const exists = await db.exists(`uid:${this.voterUid}:upvote`);
|
||||||
|
assert(!exists);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with privilege revoked (from fediverse pseudo-user)', () => {
|
||||||
|
before(async function () {
|
||||||
|
await privileges.categories.rescind(['groups:posts:upvote'], this.cid, 'fediverse');
|
||||||
|
const object = await activitypub.mocks.notes.public(this.postData);
|
||||||
|
const { activity } = helpers.mocks.like({ object });
|
||||||
|
this.voterUid = activity.actor;
|
||||||
|
await activitypub.inbox.like({ body: activity });
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await privileges.categories.give(['groups:posts:upvote'], this.cid, 'fediverse');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not increment a like for the post', async function () {
|
||||||
|
const { upvoted } = await posts.hasVoted(this.postData.pid, this.voterUid);
|
||||||
|
const count = await posts.getPostField(this.postData.pid, 'upvotes');
|
||||||
|
assert.strictEqual(upvoted, false);
|
||||||
|
assert.strictEqual(count, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Inbox Synchronization', () => {
|
describe('Inbox Synchronization', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user