mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-06 08:50:50 +08:00
feat(server): delay subscription after invitation accepted or approved (#11992)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { interval, map, take, takeUntil } from 'rxjs';
|
||||
import Sinon from 'sinon';
|
||||
|
||||
import { Mailer } from '../../core/mail';
|
||||
@@ -22,6 +23,35 @@ export class MockMailer {
|
||||
return last as any;
|
||||
}
|
||||
|
||||
waitFor<Mail extends MailName>(
|
||||
name: Mail,
|
||||
timeout: number = 1000
|
||||
): Promise<Extract<Jobs['notification.sendMail'], { name: Mail }>> {
|
||||
const { promise, reject, resolve } = Promise.withResolvers<any>();
|
||||
|
||||
interval(10)
|
||||
.pipe(
|
||||
take(Math.floor(timeout / 10)),
|
||||
takeUntil(promise),
|
||||
map(() => {
|
||||
const last = this.send.lastCall.args[0];
|
||||
return last.name === name ? last : undefined;
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: val => {
|
||||
if (val) {
|
||||
resolve(val);
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
reject(new Error('Timeout wait for job coming'));
|
||||
},
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
count(name: MailName) {
|
||||
return this.send.getCalls().filter(call => call.args[0].name === name)
|
||||
.length;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { interval, map, take, takeUntil } from 'rxjs';
|
||||
import Sinon from 'sinon';
|
||||
|
||||
import { JobQueue } from '../../base';
|
||||
@@ -20,6 +21,36 @@ export class MockJobQueue {
|
||||
return { name, payload };
|
||||
}
|
||||
|
||||
waitFor<Job extends JobName>(name: Job, timeout: number = 1000) {
|
||||
const { promise, reject, resolve } = Promise.withResolvers<{
|
||||
name: Job;
|
||||
payload: Jobs[Job];
|
||||
}>();
|
||||
|
||||
interval(10)
|
||||
.pipe(
|
||||
take(Math.floor(timeout / 10)),
|
||||
takeUntil(promise),
|
||||
map(() => {
|
||||
const addJobName = this.add.lastCall?.args[0];
|
||||
const payload = this.add.lastCall?.args[1];
|
||||
return addJobName === name ? payload : undefined;
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: val => {
|
||||
if (val) {
|
||||
resolve({ name, payload: val });
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
reject(new Error('Timeout wait for job coming'));
|
||||
},
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
count(name: JobName) {
|
||||
return this.add.getCalls().filter(call => call.args[0] === name).length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user