1 |
rakinar2 |
575 |
import { faker } from "@faker-js/faker"; |
2 |
|
|
import StringArgument from "@framework/arguments/StringArgument"; |
3 |
|
|
import { beforeEach, describe, expect, it } from "vitest"; |
4 |
|
|
import { createApplication } from "../../mocks/application.mock"; |
5 |
|
|
import { initialize } from "./ArgumentTestUtils"; |
6 |
|
|
|
7 |
|
|
describe("StringArgument", () => { |
8 |
|
|
createApplication(); |
9 |
|
|
let data: ReturnType<typeof initialize>; |
10 |
|
|
|
11 |
|
|
beforeEach(() => { |
12 |
|
|
data = initialize({ |
13 |
|
|
content: faker.lorem.words(5), |
14 |
|
|
userId: "1", |
15 |
|
|
guildId: "1", |
16 |
|
|
prefix: "!" |
17 |
|
|
}); |
18 |
|
|
}); |
19 |
|
|
|
20 |
|
|
it("should parse a string argument", async () => { |
21 |
|
|
const arg1 = await StringArgument.performCast( |
22 |
|
|
data.context, |
23 |
|
|
data.content, |
24 |
|
|
data.argv, |
25 |
|
|
data.argv[1], |
26 |
|
|
0, |
27 |
|
|
"testarg", |
28 |
|
|
undefined, |
29 |
|
|
true |
30 |
|
|
); |
31 |
|
|
const arg3 = await StringArgument.performCast( |
32 |
|
|
data.context, |
33 |
|
|
data.content, |
34 |
|
|
data.argv, |
35 |
|
|
data.argv[3], |
36 |
|
|
2, |
37 |
|
|
"testarg3", |
38 |
|
|
undefined, |
39 |
|
|
true |
40 |
|
|
); |
41 |
|
|
|
42 |
|
|
expect(arg1.value?.getRawValue()).toBe(data.argv[1]); |
43 |
|
|
expect(arg1.value?.getValue()).toBe(data.argv[1]); |
44 |
|
|
expect(arg1.error).toBeUndefined(); |
45 |
|
|
|
46 |
|
|
expect(arg3.value?.getRawValue()).toBe(data.argv[3]); |
47 |
|
|
expect(arg3.value?.getValue()).toBe(data.argv[3]); |
48 |
|
|
expect(arg3.error).toBeUndefined(); |
49 |
|
|
}); |
50 |
|
|
}); |