2021-04-29 10:43:21 +00:00
|
|
|
import { Args, parseArgs } from '../src/utils/command.ts'
|
2021-04-28 18:28:19 +00:00
|
|
|
import {
|
|
|
|
assertEquals,
|
|
|
|
assertNotEquals
|
|
|
|
} from 'https://deno.land/std@0.95.0/testing/asserts.ts'
|
2021-04-28 13:57:59 +00:00
|
|
|
|
2021-04-28 18:22:54 +00:00
|
|
|
const commandArgs: Args[] = [
|
2021-04-28 19:28:09 +00:00
|
|
|
{
|
|
|
|
name: 'originalMessage',
|
|
|
|
match: 'content'
|
|
|
|
},
|
2021-04-28 18:22:54 +00:00
|
|
|
{
|
2021-04-28 18:28:19 +00:00
|
|
|
name: 'permaban',
|
|
|
|
match: 'flag',
|
|
|
|
flag: '--permanent',
|
|
|
|
defaultValue: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'user',
|
2021-04-29 10:43:21 +00:00
|
|
|
match: 'mentionUser'
|
2021-04-28 18:28:19 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'reason',
|
|
|
|
match: 'rest',
|
|
|
|
defaultValue: 'ree'
|
2021-04-28 18:22:54 +00:00
|
|
|
}
|
2021-04-28 18:28:19 +00:00
|
|
|
]
|
2021-04-28 18:22:54 +00:00
|
|
|
|
2021-04-28 18:28:19 +00:00
|
|
|
const messageArgs1: string[] = [
|
|
|
|
'<@!708544768342229012>',
|
|
|
|
'--permanent',
|
|
|
|
'bye',
|
|
|
|
'bye',
|
|
|
|
'Skyler'
|
|
|
|
]
|
2021-04-28 18:22:54 +00:00
|
|
|
const expectedResult1 = {
|
2021-04-28 19:28:09 +00:00
|
|
|
originalMessage: [
|
|
|
|
'<@!708544768342229012>',
|
|
|
|
'--permanent',
|
|
|
|
'bye',
|
|
|
|
'bye',
|
|
|
|
'Skyler'
|
|
|
|
],
|
2021-04-28 18:22:54 +00:00
|
|
|
permaban: true,
|
2021-04-28 18:28:19 +00:00
|
|
|
user: '708544768342229012',
|
2021-04-30 06:15:13 +00:00
|
|
|
reason: 'bye bye Skyler'
|
2021-04-28 18:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Deno.test({
|
2021-04-28 19:28:09 +00:00
|
|
|
only: false,
|
2021-04-28 18:28:19 +00:00
|
|
|
name: 'parse command arguments 1 (assertEquals)',
|
2021-04-28 18:22:54 +00:00
|
|
|
fn: () => {
|
2021-04-28 18:28:19 +00:00
|
|
|
const result = parseArgs(commandArgs, messageArgs1)
|
2021-04-28 18:22:54 +00:00
|
|
|
assertEquals(result, expectedResult1)
|
|
|
|
},
|
|
|
|
sanitizeOps: true,
|
|
|
|
sanitizeResources: true,
|
2021-04-28 18:28:19 +00:00
|
|
|
sanitizeExit: true
|
2021-04-28 18:22:54 +00:00
|
|
|
})
|
|
|
|
|
2021-04-28 18:28:19 +00:00
|
|
|
const messageArgs2: string[] = [
|
|
|
|
'<@!708544768342229012>',
|
|
|
|
'bye',
|
|
|
|
'bye',
|
|
|
|
'Skyler'
|
|
|
|
]
|
2021-04-28 18:22:54 +00:00
|
|
|
const expectedResult2 = {
|
2021-04-28 19:28:09 +00:00
|
|
|
originalMessage: ['<@!708544768342229012>', 'bye', 'bye', 'Skyler'],
|
2021-04-28 13:57:59 +00:00
|
|
|
permaban: true,
|
2021-04-28 18:28:19 +00:00
|
|
|
user: '708544768342229012',
|
2021-04-30 06:15:13 +00:00
|
|
|
reason: 'bye bye Skyler'
|
2021-04-28 13:57:59 +00:00
|
|
|
}
|
2021-04-28 18:22:54 +00:00
|
|
|
|
|
|
|
Deno.test({
|
2021-04-28 18:28:19 +00:00
|
|
|
name: 'parse command arguments 2 (assertEquals)',
|
2021-04-28 18:22:54 +00:00
|
|
|
fn: () => {
|
2021-04-28 18:28:19 +00:00
|
|
|
const result = parseArgs(commandArgs, messageArgs2)
|
2021-04-28 18:22:54 +00:00
|
|
|
assertEquals(result, expectedResult2)
|
|
|
|
},
|
|
|
|
sanitizeOps: true,
|
|
|
|
sanitizeResources: true,
|
2021-04-28 18:28:19 +00:00
|
|
|
sanitizeExit: true
|
2021-04-28 18:22:54 +00:00
|
|
|
})
|
|
|
|
|
2021-04-28 18:28:19 +00:00
|
|
|
const messageArgs3: string[] = [
|
|
|
|
'<@!708544768342229012>',
|
|
|
|
'bye',
|
|
|
|
'bye',
|
|
|
|
'Skyler'
|
|
|
|
]
|
2021-04-28 18:22:54 +00:00
|
|
|
const expectedResult3 = {
|
|
|
|
permaban: false,
|
2021-04-28 18:28:19 +00:00
|
|
|
user: '708544768342229012',
|
2021-04-30 06:15:13 +00:00
|
|
|
reason: 'bye bye Skyler'
|
2021-04-28 18:22:54 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 13:57:59 +00:00
|
|
|
Deno.test({
|
2021-04-29 17:34:16 +00:00
|
|
|
name: 'parse command arguments default value (assertNotEquals)',
|
2021-04-28 13:57:59 +00:00
|
|
|
fn: () => {
|
2021-04-28 18:28:19 +00:00
|
|
|
const result = parseArgs(commandArgs, messageArgs3)
|
2021-04-28 18:22:54 +00:00
|
|
|
assertNotEquals(result, expectedResult3)
|
2021-04-28 13:57:59 +00:00
|
|
|
},
|
|
|
|
sanitizeOps: true,
|
|
|
|
sanitizeResources: true,
|
2021-04-28 18:28:19 +00:00
|
|
|
sanitizeExit: true
|
|
|
|
})
|
2021-04-29 17:34:16 +00:00
|
|
|
|
|
|
|
const commandArgs2: Args[] = [
|
2021-04-30 06:15:13 +00:00
|
|
|
{
|
2021-04-29 17:34:16 +00:00
|
|
|
name: 'user',
|
|
|
|
match: 'mentionUser'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'channel',
|
|
|
|
match: 'mentionChannel'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'role',
|
2021-04-30 06:15:13 +00:00
|
|
|
match: 'mentionRole'
|
2021-04-29 17:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'reason',
|
|
|
|
match: 'rest',
|
|
|
|
defaultValue: 'ree'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const messageArgs4: string[] = [
|
|
|
|
'<@!708544768342229012>',
|
|
|
|
'bye',
|
|
|
|
'<#783319033730564098>',
|
|
|
|
'<@&836715188690092032>'
|
|
|
|
]
|
|
|
|
const expectedResult4 = {
|
2021-04-30 06:15:13 +00:00
|
|
|
channel: '783319033730564098',
|
|
|
|
role: '836715188690092032',
|
|
|
|
user: '708544768342229012',
|
|
|
|
reason: 'bye'
|
2021-04-29 17:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: 'parse command arguments mentions (assertEquals)',
|
|
|
|
fn: () => {
|
|
|
|
const result = parseArgs(commandArgs2, messageArgs4)
|
|
|
|
assertEquals(result, expectedResult4)
|
|
|
|
},
|
|
|
|
sanitizeOps: true,
|
|
|
|
sanitizeResources: true,
|
|
|
|
sanitizeExit: true
|
|
|
|
})
|
2021-05-03 09:24:09 +00:00
|
|
|
|
|
|
|
const messageArgs5: string[] = ['<@!708544768342229012>']
|
|
|
|
const expectedResult5 = {
|
|
|
|
user: '708544768342229012',
|
|
|
|
reason: 'No reason provided'
|
|
|
|
}
|
|
|
|
const commandArgs5: Args[] = [
|
|
|
|
{
|
|
|
|
name: 'user',
|
|
|
|
match: 'mentionUser'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'reason',
|
|
|
|
match: 'rest',
|
|
|
|
defaultValue: 'No reason provided'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
Deno.test({
|
|
|
|
name: 'parse command arguments, rest match default',
|
|
|
|
fn: () => {
|
|
|
|
const result = parseArgs(commandArgs5, messageArgs5)
|
|
|
|
assertEquals(result, expectedResult5)
|
|
|
|
}
|
|
|
|
})
|