1+ import { describe , it } from 'mocha' ;
2+ import {
3+ assertApplicationConfig ,
4+ InvalidPackageIdentifierError ,
5+ InvalidInstallPropertyError ,
6+ InvalidInstallCommandError ,
7+ InvalidInstallTimeoutError ,
8+ } from '@/components/Application' ;
9+ import assert from 'node:assert/strict' ;
10+
11+ describe ( 'Application' , ( ) => {
12+ describe ( 'assertApplicationConfig' , ( ) => {
13+ const applicationName = 'test-application' ;
14+
15+ it ( 'should pass for valid minimal config' , ( ) => {
16+ assert . doesNotThrow ( ( ) => {
17+ assertApplicationConfig ( applicationName , { package : 'my-package' } ) ;
18+ } ) ;
19+ } ) ;
20+
21+ it ( 'should pass for valid config with install options' , ( ) => {
22+ assert . doesNotThrow ( ( ) => {
23+ assertApplicationConfig ( applicationName , {
24+ package : 'my-package' ,
25+ install : {
26+ command : 'npm ci' ,
27+ timeout : 60000 ,
28+ } ,
29+ } ) ;
30+ } ) ;
31+ } ) ;
32+
33+ it ( 'should pass for valid config with partial install options' , ( ) => {
34+ assert . doesNotThrow ( ( ) => {
35+ assertApplicationConfig ( applicationName , {
36+ package : 'my-package' ,
37+ install : { command : 'npm ci' } ,
38+ } ) ;
39+ } ) ;
40+
41+ assert . doesNotThrow ( ( ) => {
42+ assertApplicationConfig ( applicationName , {
43+ package : 'my-package' ,
44+ install : { timeout : 60000 } ,
45+ } ) ;
46+ } ) ;
47+
48+ assert . doesNotThrow ( ( ) => {
49+ assertApplicationConfig ( applicationName , {
50+ package : 'my-package' ,
51+ install : { } ,
52+ } ) ;
53+ } ) ;
54+ } ) ;
55+
56+ it ( 'should pass for config with additional, arbitrary options' , ( ) => {
57+ assert . doesNotThrow ( ( ) => {
58+ assertApplicationConfig ( applicationName , {
59+ package : 'my-package' ,
60+ foo : 'bar' ,
61+ baz : 42 ,
62+ fuzz : { buzz : true }
63+ } ) ;
64+ } ) ;
65+ } ) ;
66+
67+ it ( 'should fail for invalid package identifiers' , ( ) => {
68+ const invalidValues = [ null , undefined , 42 , { } , [ ] , true , false ] ;
69+
70+ for ( const invalidValue of invalidValues ) {
71+ assert . throws (
72+ ( ) => {
73+ assertApplicationConfig ( applicationName , {
74+ package : invalidValue ,
75+ } ) ;
76+ } ,
77+ ( error : Error ) => {
78+ return (
79+ error instanceof InvalidPackageIdentifierError &&
80+ error . message === `Invalid 'package' property for application ${ applicationName } : expected string, got ${ typeof invalidValue } `
81+ ) ;
82+ }
83+ ) ;
84+ }
85+ } ) ;
86+
87+ it ( 'should fail for invalid install property' , ( ) => {
88+ const invalidValues = [ null , 42 , 'string' , [ ] , true , false ] ;
89+
90+ for ( const invalidValue of invalidValues ) {
91+ assert . throws (
92+ ( ) => {
93+ assertApplicationConfig ( applicationName , {
94+ package : 'my-package' ,
95+ install : invalidValue ,
96+ } ) ;
97+ } ,
98+ ( error : Error ) => {
99+ return (
100+ error instanceof InvalidInstallPropertyError &&
101+ error . message === `Invalid 'install' property for application ${ applicationName } : expected object, got ${ typeof invalidValue } `
102+ ) ;
103+ }
104+ ) ;
105+ }
106+ } ) ;
107+
108+ it ( 'should fail for invalid install.command' , ( ) => {
109+ const invalidValues = [ null , undefined , 42 , { } , [ ] , true , false ] ;
110+
111+ for ( const invalidValue of invalidValues ) {
112+ assert . throws (
113+ ( ) => {
114+ assertApplicationConfig ( applicationName , {
115+ package : 'my-package' ,
116+ install : { command : invalidValue } ,
117+ } ) ;
118+ } ,
119+ ( error : Error ) => {
120+ return (
121+ error instanceof InvalidInstallCommandError &&
122+ error . message === `Invalid 'install.command' property for application ${ applicationName } : expected string, got ${ typeof invalidValue } `
123+ ) ;
124+ }
125+ ) ;
126+ }
127+ } ) ;
128+
129+ it ( 'should fail for invalid install.timeout' , ( ) => {
130+ const invalidValues = [ null , undefined , 'string' , { } , [ ] , true , false , - 1 , - 100 ] ;
131+
132+ for ( const invalidValue of invalidValues ) {
133+ assert . throws (
134+ ( ) => {
135+ assertApplicationConfig ( applicationName , {
136+ package : 'my-package' ,
137+ install : { timeout : invalidValue } ,
138+ } ) ;
139+ } ,
140+ ( error : Error ) => {
141+ return (
142+ error instanceof InvalidInstallTimeoutError &&
143+ error . message === `Invalid 'install.timeout' property for application ${ applicationName } : expected non-negative number, got ${ typeof invalidValue } `
144+ ) ;
145+ }
146+ ) ;
147+ }
148+ } ) ;
149+
150+ it ( 'should pass for valid timeout of 0' , ( ) => {
151+ assert . doesNotThrow ( ( ) => {
152+ assertApplicationConfig ( applicationName , {
153+ package : 'my-package' ,
154+ install : { timeout : 0 } ,
155+ } ) ;
156+ } ) ;
157+ } ) ;
158+ } ) ;
159+ } ) ;
0 commit comments