Skip to content

Commit

Permalink
Fix event handler for queryAdmin Test
Browse files Browse the repository at this point in the history
  • Loading branch information
MTRNord committed Oct 24, 2023
1 parent 7563a44 commit 7e6c0ed
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions test/integration/commands/queryAdminDetailsTest.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,85 @@
import { strict as assert } from "assert";

import { newTestUser } from "../clientHelper";
import { getMessagesByUserIn } from "../../../src/utils";
import { newTestUser, noticeListener } from "../clientHelper";

describe("Test: The queryAdmin command", function () {
// If a test has a timeout while awaitng on a promise then we never get given control back.
afterEach(function () { this.moderator?.stop(); });

it('Mjölnir can query and display the query results for a complete json.', async function () {
let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);
moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:8081` });

// listener for getting the event reply
const reply = new Promise<any>((resolve, reject) => {
moderator.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
resolve(event);
}))
});

const draupnir = this.config.RUNTIME.client!
let draupnirUserId = await draupnir.getUserId();
await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:8081` });

// Check if draupnir replied
await getMessagesByUserIn(moderator, draupnirUserId, this.mjolnir.managementRoomId, 1000, function (events) {
events.map(e => {
if (e.type === 'm.room.message') {
assert.equal(e.content.body, "", `Draupnir did not parse the json as expected: ${e.content.body}.`)
}
})
});

const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
})

it('Mjölnir can query and display the query results for a partial contacts-only json.', async function () {
let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);
moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7072` });

// listener for getting the event reply
const reply = new Promise<any>((resolve, reject) => {
moderator.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
resolve(event);
}))
});

const draupnir = this.config.RUNTIME.client!
let draupnirUserId = await draupnir.getUserId();
await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7072` });

// Check if draupnir replied
await getMessagesByUserIn(moderator, draupnirUserId, this.mjolnir.managementRoomId, 1000, function (events) {
events.map(e => {
if (e.type === 'm.room.message') {
assert.equal(e.content.body, "", `Draupnir did not parse the json as expected: ${e.content.body}.`)
}
})
});
const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
})

it('Mjölnir can query and display the query results for a partial support_page-only json.', async function () {
let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);
moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7071` });

// listener for getting the event reply
const reply = new Promise<any>((resolve, reject) => {
moderator.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
resolve(event);
}))
});

const draupnir = this.config.RUNTIME.client!
let draupnirUserId = await draupnir.getUserId();
await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7071` });

// Check if draupnir replied
await getMessagesByUserIn(moderator, draupnirUserId, this.mjolnir.managementRoomId, 1000, function (events) {
events.map(e => {
if (e.type === 'm.room.message') {
assert.equal(e.content.body, "", `Draupnir did not parse the json as expected: ${e.content.body}.`)
}
})
});
const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
})

it('Mjölnir can query and display an error for a non well-formed json.', async function () {
let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);
moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7070` });

// listener for getting the event reply
const reply = new Promise<any>((resolve, reject) => {
moderator.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
resolve(event);
}))
});

const draupnir = this.config.RUNTIME.client!
let draupnirUserId = await draupnir.getUserId();
moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7070` });

// Check if draupnir replied
await getMessagesByUserIn(moderator, draupnirUserId, this.mjolnir.managementRoomId, 1000, function (events) {
events.map(e => {
if (e.type === 'm.room.message') {
assert.equal(e.content.body, "", `Draupnir did not parse the json as expected: ${e.content.body}.`)
}
})
});
const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
})
});

0 comments on commit 7e6c0ed

Please sign in to comment.