1- import type { CredentialSchemaInput } from '@/core/types '
1+ import { getDefaultValueForType } from './inputDefaults '
22
3- import { getDefaultValueForType } from './credentialDefaults'
4-
5- const makeInput = ( overrides : Partial < CredentialSchemaInput > = { } ) : CredentialSchemaInput => ( {
6- label : 'Test' ,
7- name : 'test' ,
8- type : 'string' ,
3+ const makeInput = ( overrides : Record < string , unknown > = { } ) => ( {
4+ type : 'string' as string ,
95 ...overrides
106} )
117
@@ -32,15 +28,26 @@ describe('getDefaultValueForType', () => {
3228 expect ( getDefaultValueForType ( makeInput ( { type : 'json' } ) ) ) . toBe ( '{}' )
3329 } )
3430
35- it ( 'returns first option name for options with options present' , ( ) => {
36- const input = makeInput ( {
37- type : 'options' ,
38- options : [
39- { label : 'First' , name : 'first' } ,
40- { label : 'Second' , name : 'second' }
41- ]
42- } )
43- expect ( getDefaultValueForType ( input ) ) . toBe ( 'first' )
31+ it ( 'returns [] for array' , ( ) => {
32+ expect ( getDefaultValueForType ( makeInput ( { type : 'array' } ) ) ) . toEqual ( [ ] )
33+ } )
34+
35+ it ( 'returns first option name for object options' , ( ) => {
36+ expect (
37+ getDefaultValueForType (
38+ makeInput ( {
39+ type : 'options' ,
40+ options : [
41+ { label : 'First' , name : 'first' } ,
42+ { label : 'Second' , name : 'second' }
43+ ]
44+ } )
45+ )
46+ ) . toBe ( 'first' )
47+ } )
48+
49+ it ( 'returns first option value for string options' , ( ) => {
50+ expect ( getDefaultValueForType ( makeInput ( { type : 'options' , options : [ 'alpha' , 'beta' ] } ) ) ) . toBe ( 'alpha' )
4451 } )
4552
4653 it ( "returns '' for options with no options" , ( ) => {
@@ -57,6 +64,17 @@ describe('getDefaultValueForType', () => {
5764 } )
5865
5966 it ( "returns '' for unknown type" , ( ) => {
60- expect ( getDefaultValueForType ( makeInput ( { type : 'unknown' as CredentialSchemaInput [ 'type' ] } ) ) ) . toBe ( '' )
67+ expect ( getDefaultValueForType ( makeInput ( { type : 'somethingElse' } ) ) ) . toBe ( '' )
68+ } )
69+
70+ it ( 'works with InputParam-shaped objects' , ( ) => {
71+ // InputParam has id, name, label, type, etc.
72+ const inputParam = { id : 'p1' , name : 'field' , label : 'Field' , type : 'boolean' }
73+ expect ( getDefaultValueForType ( inputParam ) ) . toBe ( false )
74+ } )
75+
76+ it ( 'works with CredentialSchemaInput-shaped objects' , ( ) => {
77+ const credInput = { label : 'API Key' , name : 'apiKey' , type : 'password' }
78+ expect ( getDefaultValueForType ( credInput ) ) . toBe ( '' )
6179 } )
6280} )
0 commit comments