11import { TestContext } from '@salesforce/core/testSetup' ;
22import { expect } from 'chai' ;
33import { stubSfCommandUx } from '@salesforce/sf-plugins-core' ;
4- import Init from '../../../src/commands/data-code-extension/init.js' ;
4+ import ScriptInit from '../../../src/commands/data-code-extension/script/init.js' ;
5+ import FunctionInit from '../../../src/commands/data-code-extension/function/init.js' ;
56
6- describe ( 'data-code-extension init' , ( ) => {
7+ describe ( 'data-code-extension init commands ' , ( ) => {
78 const $$ = new TestContext ( ) ;
89 let sfCommandStubs : ReturnType < typeof stubSfCommandUx > ;
910
@@ -15,12 +16,13 @@ describe('data-code-extension init', () => {
1516 $$ . restore ( ) ;
1617 } ) ;
1718
18- it ( 'runs init command successfully' , async ( ) => {
19+ it ( 'runs script init command successfully' , async ( ) => {
1920 try {
20- const result = await Init . run ( [ '--package-dir' , './test-dir' ] ) ;
21+ const result = await ScriptInit . run ( [ '--package-dir' , './test-dir' ] ) ;
2122
2223 // If Python 3.11+ is installed, check the success result
2324 expect ( result . success ) . to . be . true ;
25+ expect ( result . codeType ) . to . equal ( 'script' ) ;
2426 expect ( result . pythonVersion ) . to . have . property ( 'command' ) ;
2527 expect ( result . pythonVersion ) . to . have . property ( 'version' ) ;
2628 expect ( result . pythonVersion ) . to . have . property ( 'major' ) ;
@@ -76,9 +78,9 @@ describe('data-code-extension init', () => {
7678 }
7779 } ) ;
7880
79- it ( 'returns JSON result when --json flag is used' , async ( ) => {
81+ it ( 'returns JSON result when --json flag is used for script init ' , async ( ) => {
8082 try {
81- const result = await Init . run ( [ '--json' , '--package-dir' , './test-json' ] ) ;
83+ const result = await ScriptInit . run ( [ '--json' , '--package-dir' , './test-json' ] ) ;
8284
8385 // Should return a structured result
8486 expect ( result ) . to . be . an ( 'object' ) ;
@@ -96,11 +98,12 @@ describe('data-code-extension init', () => {
9698 }
9799 } ) ;
98100
99- it ( 'runs init with default code-type (script) and package-dir ' , async ( ) => {
101+ it ( 'runs function init command successfully ' , async ( ) => {
100102 try {
101- const result = await Init . run ( [ '--package-dir' , './test-package' ] ) ;
102- expect ( result . codeType ) . to . equal ( 'script' ) ; // default value
103- expect ( result . packageDir ) . to . equal ( './test-package' ) ;
103+ const result = await FunctionInit . run ( [ '--package-dir' , './test-function' ] ) ;
104+ expect ( result . codeType ) . to . equal ( 'function' ) ;
105+ expect ( result . packageDir ) . to . equal ( './test-function' ) ;
106+ expect ( result . success ) . to . be . true ;
104107 } catch ( error ) {
105108 // Handle case where Python is not installed
106109 if ( error instanceof Error ) {
@@ -109,11 +112,11 @@ describe('data-code-extension init', () => {
109112 }
110113 } ) ;
111114
112- it ( 'runs init with --code-type function ' , async ( ) => {
115+ it ( 'script init returns codeType as script ' , async ( ) => {
113116 try {
114- const result = await Init . run ( [ '--code-type' , 'function' , '-- package-dir', './my-function ' ] ) ;
115- expect ( result . codeType ) . to . equal ( 'function ' ) ;
116- expect ( result . packageDir ) . to . equal ( './my-function ' ) ;
117+ const result = await ScriptInit . run ( [ '--package-dir' , './test-script ' ] ) ;
118+ expect ( result . codeType ) . to . equal ( 'script ' ) ;
119+ expect ( result . packageDir ) . to . equal ( './test-script ' ) ;
117120 } catch ( error ) {
118121 // Handle case where Python is not installed
119122 if ( error instanceof Error ) {
@@ -122,11 +125,11 @@ describe('data-code-extension init', () => {
122125 }
123126 } ) ;
124127
125- it ( 'runs init with -c and -p shorthand flags ' , async ( ) => {
128+ it ( 'function init returns codeType as function ' , async ( ) => {
126129 try {
127- const result = await Init . run ( [ '-c' , 'function' , '-p ', './short- test' ] ) ;
130+ const result = await FunctionInit . run ( [ '--package-dir ' , './test-function-type ' ] ) ;
128131 expect ( result . codeType ) . to . equal ( 'function' ) ;
129- expect ( result . packageDir ) . to . equal ( './short- test' ) ;
132+ expect ( result . packageDir ) . to . equal ( './test-function-type ' ) ;
130133 } catch ( error ) {
131134 // Handle case where Python is not installed
132135 if ( error instanceof Error ) {
@@ -135,9 +138,21 @@ describe('data-code-extension init', () => {
135138 }
136139 } ) ;
137140
138- it ( 'fails when package-dir is not provided' , async ( ) => {
141+ it ( 'fails when package-dir is not provided for script init' , async ( ) => {
142+ try {
143+ await ScriptInit . run ( [ ] ) ;
144+ expect . fail ( 'Should have thrown an error for missing required flag' ) ;
145+ } catch ( error ) {
146+ expect ( error ) . to . exist ;
147+ if ( error instanceof Error ) {
148+ expect ( error . message ) . to . include ( 'package-dir' ) ;
149+ }
150+ }
151+ } ) ;
152+
153+ it ( 'fails when package-dir is not provided for function init' , async ( ) => {
139154 try {
140- await Init . run ( [ '--code-type' , 'script' ] ) ;
155+ await FunctionInit . run ( [ ] ) ;
141156 expect . fail ( 'Should have thrown an error for missing required flag' ) ;
142157 } catch ( error ) {
143158 expect ( error ) . to . exist ;
0 commit comments