test: Mock bull, fix setInterval capturing memory in tests

Towards #3939
This commit is contained in:
Tom Moor
2022-08-08 13:15:06 +02:00
parent ba385e1507
commit e97cc61e2f
3 changed files with 53 additions and 4 deletions

43
server/__mocks__/bull.ts Normal file
View File

@@ -0,0 +1,43 @@
export default class Queue {
done() {
//
}
on() {
//
}
count() {
return 0;
}
getDelayedCount() {
return 0;
}
add = function (data: any) {
const job = this.createJob(data);
if (!this.handler) {
throw Error(
"Mocking version requires handler to be set before first add()"
);
}
this.handler(job, this.done);
};
process = function (handler: any) {
if (this.handler) {
throw Error("Cannot define a handler more than once per Queue instance");
}
this.handler = handler;
};
createJob = function (data: any) {
return {
data: data,
};
};
}