-
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.
Merge pull request #567 from the-draupnir-project/gnuxie/safe-mode-ap…
…pservice-integration-test appservice provisioned draupnir safe mode test the-draupnir-project/planning#26
- Loading branch information
Showing
7 changed files
with
204 additions
and
9 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-FileCopyrightText: 2024 Gnuxie <Gnuxie@protonmail.com> | ||
// | ||
// SPDX-License-Identifier: AFL-3.0 | ||
|
||
import { StringUserID } from "@the-draupnir-project/matrix-basic-types"; | ||
import { MjolnirAppService } from "../../../src/appservice/AppService"; | ||
import { newTestUser } from "../../integration/clientHelper"; | ||
import { StandardProvisionHelper } from "../utils/ProvisionHelper"; | ||
import { setupHarness } from "../utils/harness"; | ||
import { SafeModeDraupnir } from "../../../src/safemode/DraupnirSafeMode"; | ||
|
||
interface Context extends Mocha.Context { | ||
appservice?: MjolnirAppService; | ||
} | ||
|
||
describe("Test safe mode commands on a provisioned Draupnir", function () { | ||
beforeEach(async function (this: Context) { | ||
this.appservice = await setupHarness(); | ||
}); | ||
afterEach(function (this: Context) { | ||
if (this.appservice) { | ||
return this.appservice.close(); | ||
} else { | ||
console.warn("Missing Appservice in this context, so cannot stop it."); | ||
return Promise.resolve(); // TS7030: Not all code paths return a value. | ||
} | ||
}); | ||
it("Provisioned draupnir can switch to safe mode and back.", async function (this: Context) { | ||
const appservice = this.appservice; | ||
if (appservice === undefined) { | ||
throw new TypeError(`Test setup failed`); | ||
} | ||
const provisionHelper = new StandardProvisionHelper(appservice); | ||
const moderator = await newTestUser(appservice.config.homeserver.url, { | ||
name: { contains: "moderator" }, | ||
}); | ||
const moderatorUserID = (await moderator.getUserId()) as StringUserID; | ||
const initialDraupnir = ( | ||
await provisionHelper.provisionDraupnir(moderatorUserID) | ||
).expect("Failed to provision a draupnir for the test"); | ||
const safeModeDraupnir = ( | ||
await initialDraupnir.sendTextCommand<SafeModeDraupnir>( | ||
moderatorUserID, | ||
"!draupnir safe mode" | ||
) | ||
).expect("Failed to switch to safe mode"); | ||
( | ||
await safeModeDraupnir.sendTextCommand( | ||
moderatorUserID, | ||
"!draupnir restart" | ||
) | ||
).expect("Failed to restart back to draupnir from safe mode"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-FileCopyrightText: 2024 Gnuxie <Gnuxie@protonmail.com> | ||
// | ||
// SPDX-License-Identifier: AFL-3.0 | ||
|
||
import { Ok, Result, ResultError, isError } from "@gnuxie/typescript-result"; | ||
import { Draupnir } from "../../../src/Draupnir"; | ||
import { MjolnirAppService } from "../../../src/appservice/AppService"; | ||
import { StringUserID } from "@the-draupnir-project/matrix-basic-types"; | ||
|
||
export interface ProvisionHelper { | ||
/** | ||
* Automatically make a draupnir and a management room. | ||
*/ | ||
provisionDraupnir(requestingUserID: StringUserID): Promise<Result<Draupnir>>; | ||
} | ||
|
||
export class StandardProvisionHelper implements ProvisionHelper { | ||
public constructor(private readonly appservice: MjolnirAppService) { | ||
// nothing to do. | ||
} | ||
async provisionDraupnir( | ||
requestingUserID: StringUserID | ||
): Promise<Result<Draupnir>> { | ||
const provisionResult = | ||
await this.appservice.draupnirManager.provisionNewDraupnir( | ||
requestingUserID | ||
); | ||
if (isError(provisionResult)) { | ||
return provisionResult; | ||
} | ||
const draupnir = await this.appservice.draupnirManager.getRunningDraupnir( | ||
this.appservice.draupnirManager.draupnirMXID(provisionResult.ok), | ||
requestingUserID | ||
); | ||
if (draupnir === undefined) { | ||
return ResultError.Result(`Failed to find draupnir after provisioning`); | ||
} | ||
return Ok(draupnir); | ||
} | ||
} |