Skip to content

Commit

Permalink
Fix test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
MTRNord committed Oct 24, 2023
1 parent 7e6c0ed commit 8a888e2
Showing 1 changed file with 14 additions and 46 deletions.
60 changes: 14 additions & 46 deletions test/integration/commands/queryAdminDetailsTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { strict as assert } from "assert";

import { newTestUser, noticeListener } from "../clientHelper";
import { newTestUser } from "../clientHelper";
import { getFirstReply } from "./commandUtils";

describe("Test: The queryAdmin command", function () {
// If a test has a timeout while awaitng on a promise then we never get given control back.
Expand All @@ -11,75 +12,42 @@ describe("Test: The queryAdmin command", function () {
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);

// 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 reply_event = await getFirstReply(this.mjolnir.matrixEmitter, this.mjolnir.managementRoomId, async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir queryAdmin http://localhost:8081` });
});

await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:8081` });


const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
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 () {
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);

// 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 reply_event = await getFirstReply(this.mjolnir.matrixEmitter, this.mjolnir.managementRoomId, async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir queryAdmin http://localhost:7072` });
});

await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7072` });

const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
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 () {
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);

// 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 reply_event = await getFirstReply(this.mjolnir.matrixEmitter, this.mjolnir.managementRoomId, async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir queryAdmin http://localhost:7071` });
});

await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7071` });

const reply_event = await reply;

assert.equal(reply_event.content.body, "", `Draupnir did not parse the json as expected: ${reply_event.content.body}.`)
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 () {
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
await moderator.joinRoom(this.config.managementRoom);

// 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 reply_event = await getFirstReply(this.mjolnir.matrixEmitter, this.mjolnir.managementRoomId, async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir queryAdmin http://localhost:7070` });
});

moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir queryAdmin http://localhost:7070` });

const reply_event = await reply;

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

0 comments on commit 8a888e2

Please sign in to comment.