hookshot/tests/utils/AppserviceMock.ts
Michael Weimann 1b51189db1
Fix generic webhook 'user is already in the room error' (#627)
* Fix generic webhook 'user is already in the room error'

* Add changelog

* Cleanup to support usecases without slamming the homeserver.

* Fix fallthrough

* Add some tests

* Add tests for intentutils

* Refactor the rest of the app

Co-authored-by: Half-Shot <will@half-shot.uk>
2023-01-16 14:58:23 +00:00

30 lines
820 B
TypeScript

import { IntentMock } from "./IntentMock";
export class AppserviceMock {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public readonly intentMap = new Map<string, any>();
public readonly botIntent = IntentMock.create(`@bot:example.com`);
static create(){
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new this() as any;
}
get botUserId() {
return this.botIntent.userId;
}
get botClient() {
return this.botIntent.underlyingClient;
}
public getIntentForUserId(userId: string) {
let intent = this.intentMap.get(userId);
if (intent) {
return intent;
}
intent = IntentMock.create(userId);
this.intentMap.set(userId, intent);
return intent;
}
}