-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix event handler for queryAdmin Test
- Loading branch information
Showing
1 changed file
with
46 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.`) | ||
}) | ||
}); |