splice returns removed items, not a new list with items removed

This commit is contained in:
jesopo 2022-02-07 13:05:14 +00:00
parent 58e228be7d
commit c174847764
2 changed files with 5 additions and 8 deletions

View File

@ -87,8 +87,7 @@ export class StringListProtectionSetting extends AbstractProtectionListSetting<s
return [...this.value, data];
}
removeValue(data: string): string[] {
const index = this.value.indexOf(data);
return this.value.splice(index, index + 1);
return this.value.filter(i => i !== data);
}
}

View File

@ -133,20 +133,18 @@ describe("Test: Protection settings", function() {
};
let reply = new Promise((resolve, reject) => {
let i = 0;
let reply = () => new Promise((resolve, reject) => {
client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => {
if (event.content.body.includes("Changed oXzT0E.test ")) {
if (++i == 2) {
resolve(event);
}
resolve(event);
}
}))
});
await client.sendMessage(this.mjolnir.managementRoomId, {msgtype: "m.text", body: "!mjolnir config add oXzT0E.test asd"})
await reply();
await client.sendMessage(this.mjolnir.managementRoomId, {msgtype: "m.text", body: "!mjolnir config remove oXzT0E.test asd"})
await reply
await reply();
assert.deepEqual(await this.mjolnir.getProtectionSettings("oXzT0E"), { "test": [] });
});