File tree Expand file tree Collapse file tree 2 files changed +47
-5
lines changed
src/infrastructure/discord/commands
test/infrastructure/discord/commands Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export async function execute(interaction: CommandInteraction) {
4444
4545 const dueDateInput = new TextInputBuilder ( )
4646 . setCustomId ( "dueDate" )
47- . setLabel ( "Due Date (e.g. yyyy-mm-dd)" )
47+ . setLabel ( "Due Date (yyyy-mm-dd, defaults in 1 week )" )
4848 . setStyle ( TextInputStyle . Short )
4949 . setRequired ( false ) ;
5050
@@ -68,16 +68,24 @@ export async function handleModalSubmit(
6868) : Promise < void > {
6969 const title = interaction . fields . getTextInputValue ( "title" ) ;
7070 const description = interaction . fields . getTextInputValue ( "description" ) ;
71- const dueDate = interaction . fields . getTextInputValue ( "dueDate" ) ;
71+ const dueDateInput = interaction . fields . getTextInputValue ( "dueDate" ) ;
7272
73- if ( dueDate && ! / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / . test ( dueDate ) ) {
74- throw new Error ( "Invalid due date format. Please use yyyy-mm-dd." ) ;
73+ let dueDate : Date ;
74+
75+ if ( dueDateInput ) {
76+ if ( ! / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / . test ( dueDateInput ) ) {
77+ throw new Error ( "Invalid due date format. Please use yyyy-mm-dd." ) ;
78+ }
79+ dueDate = new Date ( dueDateInput ) ;
80+ } else {
81+ dueDate = new Date ( ) ;
82+ dueDate . setDate ( dueDate . getDate ( ) + 7 ) ; // one week from today
7583 }
7684
7785 const result = await ItemService . create ( {
7886 title,
7987 description,
80- dueDate : new Date ( dueDate ) ,
88+ dueDate,
8189 } ) ;
8290
8391 if ( result . err ) {
Original file line number Diff line number Diff line change @@ -121,5 +121,39 @@ describe("create-issue slash command", () => {
121121 "abc-123" ,
122122 ) ;
123123 } ) ;
124+
125+ it ( "will default due date to one week from today if left blank" , async ( ) => {
126+ const today = new Date ( ) ;
127+ const expectedDate = new Date ( today ) ;
128+ expectedDate . setDate ( today . getDate ( ) + 7 ) ;
129+
130+ interaction . fields . getTextInputValue = jest . fn ( ( key ) => {
131+ if ( key === "dueDate" ) return "" ;
132+ return "test value" ;
133+ } ) ;
134+
135+ ( ItemService . create as jest . Mock ) . mockResolvedValue (
136+ Ok ( { githubIssueId : "abc-123" } ) ,
137+ ) ;
138+
139+ await handleModalSubmit ( interaction ) ;
140+
141+ expect ( ItemService . create ) . toHaveBeenCalledWith ( {
142+ title : "test value" ,
143+ description : "test value" ,
144+ dueDate : expect . any ( Date ) ,
145+ } ) ;
146+
147+ const actualDueDate = ( ItemService . create as jest . Mock ) . mock . calls [ 0 ] [ 0 ] . dueDate ;
148+
149+ expect ( actualDueDate . toISOString ( ) . slice ( 0 , 10 ) ) . toEqual (
150+ expectedDate . toISOString ( ) . slice ( 0 , 10 ) ,
151+ ) ;
152+
153+ expect ( promptAssigneeSelection ) . toHaveBeenCalledWith (
154+ interaction ,
155+ "abc-123" ,
156+ ) ;
157+ } ) ;
124158 } ) ;
125159} ) ;
You can’t perform that action at this time.
0 commit comments