mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 20:32:50 +02:00
Test invite interaction & code coverage
This commit is contained in:
parent
65170c1282
commit
bad8c5b8c2
15 changed files with 407 additions and 161 deletions
|
@ -1,12 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
const {test} = require("supertape")
|
||||
const power = require("./power")
|
||||
|
||||
test("power: get affected rooms", t => {
|
||||
t.deepEqual(power._getAffectedRooms(), [{
|
||||
mxid: "@test_auto_invite:example.org",
|
||||
power_level: 100,
|
||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
|
||||
}])
|
||||
})
|
|
@ -9,7 +9,7 @@ const registrationFilePath = path.join(process.cwd(), "registration.yaml")
|
|||
|
||||
/** @param {import("../types").AppServiceRegistrationConfig} reg */
|
||||
function checkRegistration(reg) {
|
||||
reg["ooye"].invite = (reg.ooye.invite || []).filter(mxid => mxid.endsWith(`:${reg.ooye.server_name}`)) // one day I will understand why typescript disagrees with dot notation on this line
|
||||
reg["ooye"].invite = reg.ooye.invite.filter(mxid => mxid.endsWith(`:${reg.ooye.server_name}`)) // one day I will understand why typescript disagrees with dot notation on this line
|
||||
assert(reg.ooye?.max_file_size)
|
||||
assert(reg.ooye?.namespace_prefix)
|
||||
assert(reg.ooye?.server_name)
|
||||
|
@ -19,6 +19,7 @@ function checkRegistration(reg) {
|
|||
assert.match(reg.url, /^https?:/, "url must start with http:// or https://")
|
||||
}
|
||||
|
||||
/* c8 ignore next 4 */
|
||||
/** @param {import("../types").AppServiceRegistrationConfig} reg */
|
||||
function writeRegistration(reg) {
|
||||
fs.writeFileSync(registrationFilePath, JSON.stringify(reg, null, 2))
|
||||
|
@ -52,6 +53,7 @@ function getTemplateRegistration(serverName) {
|
|||
socket: 6693,
|
||||
ooye: {
|
||||
namespace_prefix,
|
||||
server_name: serverName,
|
||||
max_file_size: 5000000,
|
||||
content_length_workaround: false,
|
||||
include_user_id_in_mxid: false,
|
||||
|
@ -66,6 +68,8 @@ function readRegistration() {
|
|||
try {
|
||||
const content = fs.readFileSync(registrationFilePath, "utf8")
|
||||
result = JSON.parse(content)
|
||||
result.ooye.invite ||= []
|
||||
/* c8 ignore next */
|
||||
} catch (e) {}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
// @ts-check
|
||||
|
||||
const tryToCatch = require("try-to-catch")
|
||||
const {test} = require("supertape")
|
||||
const {reg} = require("./read-registration")
|
||||
const {reg, checkRegistration, getTemplateRegistration} = require("./read-registration")
|
||||
|
||||
test("reg: has necessary parameters", t => {
|
||||
const propertiesToCheck = ["sender_localpart", "id", "as_token", "ooye"]
|
||||
|
@ -8,3 +11,19 @@ test("reg: has necessary parameters", t => {
|
|||
propertiesToCheck
|
||||
)
|
||||
})
|
||||
|
||||
test("check: passes on sample", t => {
|
||||
checkRegistration(reg)
|
||||
t.pass("all assertions passed")
|
||||
})
|
||||
|
||||
test("check: fails on template as template is missing some required values that are gathered during setup", t => {
|
||||
let err
|
||||
try {
|
||||
// @ts-ignore
|
||||
checkRegistration(getTemplateRegistration("cadence.moe"))
|
||||
} catch (e) {
|
||||
err = e
|
||||
}
|
||||
t.ok(err, "one of the assertions failed as expected")
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue