Support reporting token on envelope

This commit is contained in:
Fedor Indutny
2023-02-07 16:55:12 -08:00
committed by GitHub
parent dc8d8e529d
commit 486cbe0471
12 changed files with 98 additions and 26 deletions

View File

@@ -2,8 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
import * as sinon from 'sinon';
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
import { Job } from '../../../jobs/Job';
import { UUID } from '../../../types/UUID';
import { addReportSpamJob } from '../../../jobs/helpers/addReportSpamJob';
@@ -11,6 +11,12 @@ describe('addReportSpamJob', () => {
let getMessageServerGuidsForSpam: sinon.SinonStub;
let jobQueue: { add: sinon.SinonStub };
const conversation = {
id: 'convo',
type: 'private' as const,
uuid: UUID.generate().toString(),
};
beforeEach(() => {
getMessageServerGuidsForSpam = sinon.stub().resolves(['abc', 'xyz']);
jobQueue = {
@@ -31,7 +37,10 @@ describe('addReportSpamJob', () => {
it('does nothing if the conversation lacks a UUID', async () => {
await addReportSpamJob({
conversation: getDefaultConversation({ uuid: undefined }),
conversation: {
...conversation,
uuid: undefined,
},
getMessageServerGuidsForSpam,
jobQueue,
});
@@ -44,7 +53,7 @@ describe('addReportSpamJob', () => {
getMessageServerGuidsForSpam.resolves([]);
await addReportSpamJob({
conversation: getDefaultConversation(),
conversation,
getMessageServerGuidsForSpam,
jobQueue,
});
@@ -52,9 +61,7 @@ describe('addReportSpamJob', () => {
sinon.assert.notCalled(jobQueue.add);
});
it('enqueues a job', async () => {
const conversation = getDefaultConversation();
it('enqueues a job without a token', async () => {
await addReportSpamJob({
conversation,
getMessageServerGuidsForSpam,
@@ -68,6 +75,28 @@ describe('addReportSpamJob', () => {
sinon.assert.calledWith(jobQueue.add, {
uuid: conversation.uuid,
serverGuids: ['abc', 'xyz'],
token: undefined,
});
});
it('enqueues a job with a token', async () => {
await addReportSpamJob({
conversation: {
...conversation,
reportingToken: 'uvw',
},
getMessageServerGuidsForSpam,
jobQueue,
});
sinon.assert.calledOnce(getMessageServerGuidsForSpam);
sinon.assert.calledWith(getMessageServerGuidsForSpam, conversation.id);
sinon.assert.calledOnce(jobQueue.add);
sinon.assert.calledWith(jobQueue.add, {
uuid: conversation.uuid,
serverGuids: ['abc', 'xyz'],
token: 'uvw',
});
});
});