Send viewed receipt when you start listening to an audio message

This commit is contained in:
Evan Hahn 2021-08-17 10:43:26 -05:00 committed by GitHub
parent caf544b3a1
commit 75f0cd50be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 483 additions and 109 deletions

View file

@ -0,0 +1,54 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as sinon from 'sinon';
import { JobLogger } from '../../jobs/JobLogger';
describe('JobLogger', () => {
const LEVELS = ['fatal', 'error', 'warn', 'info', 'debug', 'trace'] as const;
const createFakeLogger = () => ({
fatal: sinon.fake(),
error: sinon.fake(),
warn: sinon.fake(),
info: sinon.fake(),
debug: sinon.fake(),
trace: sinon.fake(),
});
LEVELS.forEach(level => {
describe(level, () => {
it('logs its arguments with a prefix', () => {
const fakeLogger = createFakeLogger();
const logger = new JobLogger(
{ id: 'abc', queueType: 'test queue' },
fakeLogger
);
logger.attempt = 123;
logger[level]('foo', 456);
sinon.assert.calledOnce(fakeLogger[level]);
sinon.assert.calledWith(
fakeLogger[level],
sinon.match(
(arg: unknown) =>
typeof arg === 'string' &&
arg.includes('test queue') &&
arg.includes('abc') &&
arg.includes('123')
),
'foo',
456
);
LEVELS.filter(l => l !== level).forEach(otherLevel => {
sinon.assert.notCalled(fakeLogger[otherLevel]);
});
});
});
});
});

View file

@ -12,6 +12,7 @@ import { JobError } from '../../jobs/JobError';
import { TestJobQueueStore } from './TestJobQueueStore';
import { missingCaseError } from '../../util/missingCaseError';
import { assertRejects } from '../helpers';
import type { LoggerType } from '../../logging/log';
import { JobQueue } from '../../jobs/JobQueue';
import { ParsedJob, StoredJob, JobQueueStore } from '../../jobs/types';
@ -240,6 +241,62 @@ describe('JobQueue', () => {
assert.deepStrictEqual(attempts, [1, 2, 3, 4, 5, 6]);
});
it('passes a logger to the run function', async () => {
const uniqueString = uuid();
const fakeLogger = {
fatal: sinon.fake(),
error: sinon.fake(),
warn: sinon.fake(),
info: sinon.fake(),
debug: sinon.fake(),
trace: sinon.fake(),
};
class TestQueue extends JobQueue<number> {
parseData(data: unknown): number {
return z.number().parse(data);
}
async run(
_: unknown,
{ log }: Readonly<{ log: LoggerType }>
): Promise<void> {
log.info(uniqueString);
log.warn(uniqueString);
log.error(uniqueString);
}
}
const queue = new TestQueue({
store: new TestJobQueueStore(),
queueType: 'test queue 123',
maxAttempts: 6,
logger: fakeLogger,
});
queue.streamJobs();
const job = await queue.add(1);
await job.completion;
[fakeLogger.info, fakeLogger.warn, fakeLogger.error].forEach(logFn => {
sinon.assert.calledWith(
logFn,
sinon.match(
(arg: unknown) =>
typeof arg === 'string' &&
arg.includes(job.id) &&
arg.includes('test queue 123')
),
sinon.match(
(arg: unknown) =>
typeof arg === 'string' && arg.includes(uniqueString)
)
);
});
});
it('makes job.completion reject if parseData throws', async () => {
class TestQueue extends JobQueue<string> {
parseData(data: unknown): string {