added more tests

This commit is contained in:
mierenmanz 2021-04-28 20:22:54 +02:00
parent 9c18ec2d1f
commit e6c0c378de

View file

@ -1,28 +1,71 @@
import { parseArgs, Args } from "../src/utils/command.ts"; import { parseArgs, Args } from "../src/utils/command.ts";
import { assertEquals } from "https://deno.land/std@0.95.0/testing/asserts.ts" import { assertEquals, assertNotEquals } from "https://deno.land/std@0.95.0/testing/asserts.ts"
const commandArgs: Args[] = [{ // debugger
const commandArgs: Args[] = [
{
name: "permaban", name: "permaban",
match: "flag", match: "flag",
flag: "--permanent", flag: "--permanent",
defaultValue: true,
}, { }, {
name: "user", name: "user",
match: "mention", match: "mention",
}, { }, {
name: "reason", name: "reason",
match: "rest", match: "rest",
}]; defaultValue: "ree"
const messageArgs: string[] = ["<@!708544768342229012>","--permanent","bye","bye","Skyler"]; }
const expectedResult = { ];
const messageArgs1: string[] = ["<@!708544768342229012>","--permanent","bye","bye","Skyler"];
const expectedResult1 = {
permaban: true, permaban: true,
user: "708544768342229012", user: "708544768342229012",
reason: ["bye","bye","Skyler"] reason: ["bye","bye","Skyler"]
} }
Deno.test({ Deno.test({
name: "parse Args", name: "parse command arguments 1 (assertEquals)",
fn: () => { fn: () => {
const result = parseArgs(commandArgs,messageArgs); const result = parseArgs(commandArgs,messageArgs1);
assertEquals(result, expectedResult) assertEquals(result, expectedResult1)
},
sanitizeOps: true,
sanitizeResources: true,
sanitizeExit: true,
})
const messageArgs2: string[] = ["<@!708544768342229012>","bye","bye","Skyler"];
const expectedResult2 = {
permaban: true,
user: "708544768342229012",
reason: ["bye","bye","Skyler"]
}
Deno.test({
name: "parse command arguments 2 (assertEquals)",
fn: () => {
const result = parseArgs(commandArgs, messageArgs2);
assertEquals(result, expectedResult2)
},
sanitizeOps: true,
sanitizeResources: true,
sanitizeExit: true,
})
const messageArgs3: string[] = ["<@!708544768342229012>","bye","bye","Skyler"];
const expectedResult3 = {
permaban: false,
user: "708544768342229012",
reason: ["bye","bye","Skyler"]
}
Deno.test({
name: "parse command arguments 3 (assertNotEquals)",
fn: () => {
const result = parseArgs(commandArgs, messageArgs3);
assertNotEquals(result, expectedResult3)
}, },
sanitizeOps: true, sanitizeOps: true,
sanitizeResources: true, sanitizeResources: true,