@@ -13,7 +13,9 @@ import DandoriCoreCli from "../index";
13
13
import generateDandoriTasks , {
14
14
ChatGPTFunctionCallModel ,
15
15
DandoriTask ,
16
+ OptionalTaskPropsOption ,
16
17
} from "@dandori/core" ;
18
+ import { logger } from "@dandori/libs" ;
17
19
18
20
const tasks : DandoriTask [ ] = [
19
21
{
@@ -31,6 +33,7 @@ vi.mock("@dandori/core", () => ({
31
33
32
34
describe ( "DandoriCoreCli" , ( ) => {
33
35
const mockConsole = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
36
+ const mockLogError = vi . spyOn ( logger , "error" ) . mockImplementation ( ( ) => { } ) ;
34
37
const inputFileName = "DandoriCoreCli.txt" ;
35
38
const inputFileText = "DandoriCoreCli" ;
36
39
const loadProcessArgv = ( options : string [ ] ) => {
@@ -68,18 +71,49 @@ describe("DandoriCoreCli", () => {
68
71
} ) ;
69
72
70
73
describe ( "with -m option" , ( ) => {
71
- const model : ChatGPTFunctionCallModel = "gpt-4-0613" ;
74
+ describe ( "valid argument" , ( ) => {
75
+ const model : ChatGPTFunctionCallModel = "gpt-4-0613" ;
72
76
73
- beforeEach ( async ( ) => {
74
- loadProcessArgv ( [ "-m" , model ] ) ;
75
- await new DandoriCoreCli ( ) . run ( ) ;
77
+ beforeEach ( async ( ) => {
78
+ loadProcessArgv ( [ "-m" , model ] ) ;
79
+ await new DandoriCoreCli ( ) . run ( ) ;
80
+ } ) ;
81
+
82
+ it ( "call generateDandoriTasks with valid model" , ( ) => {
83
+ expect ( generateDandoriTasks ) . toHaveBeenCalledWith ( inputFileText , {
84
+ envFilePath : undefined ,
85
+ chatGPTModel : model ,
86
+ optionalTaskProps : undefined ,
87
+ } ) ;
88
+ } ) ;
76
89
} ) ;
77
90
78
- it ( "call generateDandoriTasks with envFilePath" , ( ) => {
79
- expect ( generateDandoriTasks ) . toHaveBeenCalledWith ( inputFileText , {
80
- envFilePath : undefined ,
81
- chatGPTModel : model ,
82
- optionalTaskProps : undefined ,
91
+ describe ( "invalid argument" , ( ) => {
92
+ const model = "invalid-model" ;
93
+ const supportedChatGPTModels : ChatGPTFunctionCallModel [ ] = [
94
+ "gpt-3.5-turbo-0613" ,
95
+ "gpt-4-0613" ,
96
+ ] ;
97
+ const expectedMessage = `Unsupported model: ${ model } . Supported models are ${ supportedChatGPTModels . join (
98
+ ", " ,
99
+ ) } `;
100
+
101
+ beforeEach ( ( ) => {
102
+ loadProcessArgv ( [ "-m" , model ] ) ;
103
+ } ) ;
104
+
105
+ it ( "throw Error with valid message" , async ( ) => {
106
+ await expect ( new DandoriCoreCli ( ) . run ( ) ) . rejects . toThrow (
107
+ expectedMessage ,
108
+ ) ;
109
+ } ) ;
110
+
111
+ it ( "call logger.error with valid message" , async ( ) => {
112
+ try {
113
+ await new DandoriCoreCli ( ) . run ( ) ;
114
+ } catch {
115
+ expect ( mockLogError ) . toHaveBeenCalledWith ( expectedMessage ) ;
116
+ }
83
117
} ) ;
84
118
} ) ;
85
119
} ) ;
@@ -102,18 +136,51 @@ describe("DandoriCoreCli", () => {
102
136
} ) ;
103
137
104
138
describe ( "with -o option" , ( ) => {
105
- const optionalTaskProps = "deadline,description" ;
139
+ describe ( "valid argument" , ( ) => {
140
+ const optionalTaskProps = "deadline,description" ;
106
141
107
- beforeEach ( async ( ) => {
108
- loadProcessArgv ( [ "-o" , optionalTaskProps ] ) ;
109
- await new DandoriCoreCli ( ) . run ( ) ;
142
+ beforeEach ( async ( ) => {
143
+ loadProcessArgv ( [ "-o" , optionalTaskProps ] ) ;
144
+ await new DandoriCoreCli ( ) . run ( ) ;
145
+ } ) ;
146
+
147
+ it ( "call generateDandoriTasks with valid optionalTaskProps" , ( ) => {
148
+ expect ( generateDandoriTasks ) . toHaveBeenCalledWith ( inputFileText , {
149
+ envFilePath : undefined ,
150
+ chatGPTModel : undefined ,
151
+ optionalTaskProps : optionalTaskProps . split ( "," ) ,
152
+ } ) ;
153
+ } ) ;
110
154
} ) ;
111
155
112
- it ( "call generateDandoriTasks with envFilePath" , ( ) => {
113
- expect ( generateDandoriTasks ) . toHaveBeenCalledWith ( inputFileText , {
114
- envFilePath : undefined ,
115
- chatGPTModel : undefined ,
116
- optionalTaskProps : optionalTaskProps . split ( "," ) ,
156
+ describe ( "invalid argument" , ( ) => {
157
+ const optionalTaskProps = "invalid" ;
158
+ const supportedOptionalTaskProps : OptionalTaskPropsOption = [
159
+ "description" ,
160
+ "deadline" ,
161
+ "assignee" ,
162
+ "all" ,
163
+ ] ;
164
+ const expectedMessage = `Unsupported optional task props: ${ optionalTaskProps } . Supported optional task props are ${ supportedOptionalTaskProps . join (
165
+ ", " ,
166
+ ) } `;
167
+
168
+ beforeEach ( ( ) => {
169
+ loadProcessArgv ( [ "-o" , optionalTaskProps ] ) ;
170
+ } ) ;
171
+
172
+ it ( "throw Error with valid message" , async ( ) => {
173
+ await expect ( new DandoriCoreCli ( ) . run ( ) ) . rejects . toThrow (
174
+ expectedMessage ,
175
+ ) ;
176
+ } ) ;
177
+
178
+ it ( "call logger.error with valid message" , async ( ) => {
179
+ try {
180
+ await new DandoriCoreCli ( ) . run ( ) ;
181
+ } catch {
182
+ expect ( mockLogError ) . toHaveBeenCalledWith ( expectedMessage ) ;
183
+ }
117
184
} ) ;
118
185
} ) ;
119
186
} ) ;
0 commit comments