11import { getEnvOptions } from '../src/merge' ;
2+ import { getGraphQLEnvVars } from '../src/env' ;
23import * as fs from 'fs' ;
34import * as os from 'os' ;
45import * as path from 'path' ;
@@ -37,6 +38,15 @@ describe('getEnvOptions', () => {
3738 enableServicesApi : false ,
3839 isPublic : false ,
3940 metaSchemas : [ 'config_meta' ]
41+ } ,
42+ sms : {
43+ provider : 'devsms' ,
44+ senderId : 'ConfigSender' ,
45+ requestTimeoutMs : 3000 ,
46+ dryRun : false ,
47+ devsms : {
48+ baseUrl : 'http://config-devsms:4000'
49+ }
4050 }
4151 } ) ;
4252
@@ -52,7 +62,12 @@ describe('getEnvOptions', () => {
5262 API_META_SCHEMAS : 'env_meta1,env_meta2' ,
5363 API_ANON_ROLE : 'env_anon' ,
5464 API_ROLE_NAME : 'env_role' ,
55- API_DEFAULT_DATABASE_ID : 'env_db'
65+ API_DEFAULT_DATABASE_ID : 'env_db' ,
66+ SMS_PROVIDER : 'devsms' ,
67+ SMS_SENDER_ID : 'EnvSender' ,
68+ SMS_REQUEST_TIMEOUT_MS : '4000' ,
69+ SEND_SMS_DRY_RUN : 'true' ,
70+ DEVSMS_BASE_URL : 'http://env-devsms:4000'
5671 } ;
5772
5873 const result = getEnvOptions (
@@ -75,6 +90,10 @@ describe('getEnvOptions', () => {
7590 api : {
7691 enableServicesApi : false ,
7792 defaultDatabaseId : 'override_db'
93+ } ,
94+ sms : {
95+ senderId : 'OverrideSender' ,
96+ requestTimeoutMs : 9000
7897 }
7998 } ,
8099 tempDir ,
@@ -121,4 +140,97 @@ describe('getEnvOptions', () => {
121140 expect ( result . api ?. exposedSchemas ) . toEqual ( [ 'public' , 'override_schema' ] ) ;
122141 expect ( result . api ?. metaSchemas ) . toEqual ( [ 'env_meta' , 'override_meta' ] ) ;
123142 } ) ;
143+
144+ it ( 'parses SMS environment variables into typed options' , ( ) => {
145+ const result = getGraphQLEnvVars ( {
146+ SMS_PROVIDER : 'devsms' ,
147+ SMS_SENDER_ID : 'LocalSender' ,
148+ SMS_REQUEST_TIMEOUT_MS : '2500' ,
149+ SEND_SMS_DRY_RUN : 'true' ,
150+ DEVSMS_BASE_URL : 'http://localhost:4000'
151+ } ) ;
152+
153+ expect ( result . sms ) . toEqual ( {
154+ provider : 'devsms' ,
155+ senderId : 'LocalSender' ,
156+ requestTimeoutMs : 2500 ,
157+ dryRun : true ,
158+ devsms : {
159+ baseUrl : 'http://localhost:4000'
160+ }
161+ } ) ;
162+ } ) ;
163+
164+ it ( 'honors defaults, config, env, and runtime override priority for SMS' , ( ) => {
165+ tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'graphql-env-sms-' ) ) ;
166+ writeConfig ( tempDir , {
167+ sms : {
168+ provider : 'devsms' ,
169+ senderId : 'ConfigSender' ,
170+ requestTimeoutMs : 3000 ,
171+ dryRun : false ,
172+ devsms : {
173+ baseUrl : 'http://config-devsms:4000'
174+ }
175+ }
176+ } ) ;
177+
178+ const result = getEnvOptions (
179+ {
180+ sms : {
181+ requestTimeoutMs : 9000
182+ }
183+ } ,
184+ tempDir ,
185+ {
186+ SMS_SENDER_ID : 'EnvSender' ,
187+ SEND_SMS_DRY_RUN : 'true' ,
188+ DEVSMS_BASE_URL : 'http://env-devsms:4000'
189+ }
190+ ) ;
191+
192+ expect ( result . sms ) . toEqual ( {
193+ provider : 'devsms' ,
194+ senderId : 'EnvSender' ,
195+ requestTimeoutMs : 9000 ,
196+ dryRun : true ,
197+ devsms : {
198+ baseUrl : 'http://env-devsms:4000'
199+ }
200+ } ) ;
201+ } ) ;
202+
203+ it ( 'uses the injected env object instead of global process.env for SMS' , ( ) => {
204+ const previousSmsProvider = process . env . SMS_PROVIDER ;
205+ process . env . SMS_PROVIDER = 'twilio' ;
206+
207+ try {
208+ const result = getEnvOptions ( { } , process . cwd ( ) , {
209+ SMS_PROVIDER : 'devsms'
210+ } ) ;
211+
212+ expect ( result . sms ?. provider ) . toBe ( 'devsms' ) ;
213+ } finally {
214+ if ( previousSmsProvider === undefined ) {
215+ delete process . env . SMS_PROVIDER ;
216+ } else {
217+ process . env . SMS_PROVIDER = previousSmsProvider ;
218+ }
219+ }
220+ } ) ;
221+
222+ it ( 'keeps SMS provider and DevSms base URL optional while applying defaults' , ( ) => {
223+ const result = getEnvOptions ( { } , process . cwd ( ) , { } ) ;
224+
225+ expect ( result . sms ) . toEqual ( {
226+ requestTimeoutMs : 5000 ,
227+ dryRun : false
228+ } ) ;
229+ } ) ;
230+
231+ it ( 'throws on invalid SMS_REQUEST_TIMEOUT_MS values' , ( ) => {
232+ expect ( ( ) => getGraphQLEnvVars ( {
233+ SMS_REQUEST_TIMEOUT_MS : '5s'
234+ } ) ) . toThrow ( 'SMS_REQUEST_TIMEOUT_MS must be an integer' ) ;
235+ } ) ;
124236} ) ;
0 commit comments