hookshot/tests/utils/IntentMock.ts
Will Hunt 9b216afd2b
Fix GitHub/GitLab state config not being honoured (#346)
* 1.6.1

* Add new error type for validation errors

* Validate state for GitHubRepo properly

* Add tests to check labels

* Also check GitLab repo

* changelog

* add mock store

* remove nullable

* Be less strict for existing state

* Improve test coverage

* Improve expect error text

* ValidationApiError now takes falsey objects and errors on them

* Remove UserTokenMockStore

* Actually commit the new tests

* Whoops we need to include github
2022-05-12 11:28:55 +01:00

55 lines
1.5 KiB
TypeScript

import { expect } from "chai";
export class MatrixClientMock {
async setDisplayName() {
return;
}
}
export class IntentMock {
public readonly underlyingClient = new MatrixClientMock();
public sentEvents: {roomId: string, content: any}[] = [];
static create(){
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new this() as any;
}
sendText(roomId: string, noticeText: string, msgtype: string) {
this.sentEvents.push({
roomId,
content: {
msgtype,
body: noticeText,
}
});
}
sendEvent(roomId: string, content: any) {
this.sentEvents.push({
roomId,
content,
});
}
expectNoEvent() {
expect(this.sentEvents, 'Expected no events to be sent.').to.be.empty;
}
expectEventBodyContains(matcher: string|RegExp, eventIndex?: number) {
if (eventIndex !== undefined) {
expect(this.sentEvents[eventIndex], `Expected event ${eventIndex} to exist`).to.not.be.undefined;
const body = this.sentEvents[eventIndex].content.body;
expect(
body.includes(matcher),
`Expected event body ${eventIndex} to match '${matcher}'.\nMessage was: '${body}'`
).to.be.true;
}
expect(!!this.sentEvents.find(ev => ev.content.body.includes(matcher)), `Expected any event body to match '${matcher}'`).to.be.true;
}
async ensureRegistered() {
return true;
}
}