/[sudobot]/trunk/tests/framework/arguments/IntegerArgument.test.ts
ViewVC logotype

Annotation of /trunk/tests/framework/arguments/IntegerArgument.test.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (hide annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1548 byte(s)
chore: add trunk
1 rakinar2 575 import IntegerArgument from "@framework/arguments/IntegerArgument";
2     import { describe, expect, it } from "vitest";
3     import { createApplication } from "../../mocks/application.mock";
4     import { initialize } from "./ArgumentTestUtils";
5    
6     describe("IntegerArgument", () => {
7     createApplication();
8    
9     let data: ReturnType<typeof initialize>;
10    
11     it("should parse a integer argument", async () => {
12     data = initialize({
13     content: "test 123 test",
14     userId: "1",
15     guildId: "1",
16     prefix: "!"
17     });
18    
19     const result = await IntegerArgument.performCast(
20     data.context,
21     data.content,
22     data.argv,
23     data.argv[1],
24     1,
25     "testarg",
26     undefined,
27     true
28     );
29    
30     expect(result.value?.getRawValue()).toBe("123");
31     expect(result.value?.getValue()).toBe(123);
32     expect(result.error).toBeUndefined();
33     });
34    
35     it("should throw an error when the argument is not a number", async () => {
36     data = initialize({
37     content: "test nan test",
38     userId: "1",
39     guildId: "1",
40     prefix: "!"
41     });
42    
43     const result = await IntegerArgument.performCast(
44     data.context,
45     data.content,
46     data.argv,
47     data.argv[1],
48     1,
49     "testarg",
50     undefined,
51     true
52     );
53    
54     expect(result.value).toBeUndefined();
55     expect(result.error).toBeDefined();
56     });
57     });

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26