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 { 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",
match: "flag",
flag: "--permanent",
defaultValue: true,
}, {
name: "user",
match: "mention",
}, {
name: "reason",
match: "rest",
}];
const messageArgs: string[] = ["<@!708544768342229012>","--permanent","bye","bye","Skyler"];
const expectedResult = {
defaultValue: "ree"
}
];
const messageArgs1: string[] = ["<@!708544768342229012>","--permanent","bye","bye","Skyler"];
const expectedResult1 = {
permaban: true,
user: "708544768342229012",
reason: ["bye","bye","Skyler"]
}
Deno.test({
name: "parse Args",
name: "parse command arguments 1 (assertEquals)",
fn: () => {
const result = parseArgs(commandArgs,messageArgs);
assertEquals(result, expectedResult)
const result = parseArgs(commandArgs,messageArgs1);
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,
sanitizeResources: true,