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,7 +38,16 @@ describe('getEnvOptions', () => {
3738 enableServicesApi : false ,
3839 isPublic : false ,
3940 metaSchemas : [ 'config_meta' ]
40- }
41+ } ,
42+ sms : {
43+ provider : 'devsms' ,
44+ senderId : 'ConfigSender' ,
45+ requestTimeoutMs : 3000 ,
46+ dryRun : false ,
47+ devsms : {
48+ baseUrl : 'http://config-devsms:4000' ,
49+ } ,
50+ } ,
4151 } ) ;
4252
4353 const testEnv : NodeJS . ProcessEnv = {
@@ -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,7 +90,11 @@ describe('getEnvOptions', () => {
7590 api : {
7691 enableServicesApi : false ,
7792 defaultDatabaseId : 'override_db'
78- }
93+ } ,
94+ sms : {
95+ senderId : 'OverrideSender' ,
96+ requestTimeoutMs : 9000 ,
97+ } ,
7998 } ,
8099 tempDir ,
81100 testEnv
@@ -121,4 +140,125 @@ 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 ( 'accepts custom SMS provider names' , ( ) => {
165+ const result = getGraphQLEnvVars ( {
166+ SMS_PROVIDER : 'custom-sms-gateway' ,
167+ } ) ;
168+
169+ expect ( result . sms ?. provider ) . toBe ( 'custom-sms-gateway' ) ;
170+ } ) ;
171+
172+ it ( 'honors config, env, and runtime override priority for SMS' , ( ) => {
173+ tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'graphql-env-sms-' ) ) ;
174+ writeConfig ( tempDir , {
175+ sms : {
176+ provider : 'devsms' ,
177+ senderId : 'ConfigSender' ,
178+ requestTimeoutMs : 3000 ,
179+ dryRun : false ,
180+ devsms : {
181+ baseUrl : 'http://config-devsms:4000' ,
182+ } ,
183+ } ,
184+ } ) ;
185+
186+ const result = getEnvOptions (
187+ {
188+ sms : {
189+ requestTimeoutMs : 9000 ,
190+ } ,
191+ } ,
192+ tempDir ,
193+ {
194+ SMS_SENDER_ID : 'EnvSender' ,
195+ SEND_SMS_DRY_RUN : 'true' ,
196+ DEVSMS_BASE_URL : 'http://env-devsms:4000' ,
197+ }
198+ ) ;
199+
200+ expect ( result . sms ) . toEqual ( {
201+ provider : 'devsms' ,
202+ senderId : 'EnvSender' ,
203+ requestTimeoutMs : 9000 ,
204+ dryRun : true ,
205+ devsms : {
206+ baseUrl : 'http://env-devsms:4000' ,
207+ } ,
208+ } ) ;
209+ } ) ;
210+
211+ it ( 'uses the injected env object instead of global process.env for SMS' , ( ) => {
212+ const previousSmsProvider = process . env . SMS_PROVIDER ;
213+ process . env . SMS_PROVIDER = 'twilio' ;
214+
215+ try {
216+ const result = getEnvOptions ( { } , process . cwd ( ) , {
217+ SMS_PROVIDER : 'devsms' ,
218+ } ) ;
219+
220+ expect ( result . sms ?. provider ) . toBe ( 'devsms' ) ;
221+ } finally {
222+ if ( previousSmsProvider === undefined ) {
223+ delete process . env . SMS_PROVIDER ;
224+ } else {
225+ process . env . SMS_PROVIDER = previousSmsProvider ;
226+ }
227+ }
228+ } ) ;
229+
230+ it ( 'keeps SMS absent when it is not configured' , ( ) => {
231+ const result = getEnvOptions ( { } , process . cwd ( ) , { } ) ;
232+
233+ expect ( result . sms ) . toBeUndefined ( ) ;
234+ } ) ;
235+
236+ it ( 'omits an invalid SMS timeout from partial env overrides' , ( ) => {
237+ const result = getGraphQLEnvVars ( {
238+ SMS_REQUEST_TIMEOUT_MS : '5s' ,
239+ } ) ;
240+
241+ expect ( result . sms ) . toBeUndefined ( ) ;
242+ } ) ;
243+
244+ it ( 'does not let absent or invalid SMS env values override config' , ( ) => {
245+ tempDir = fs . mkdtempSync (
246+ path . join ( os . tmpdir ( ) , 'graphql-env-sms-defaults-' )
247+ ) ;
248+ writeConfig ( tempDir , {
249+ sms : {
250+ requestTimeoutMs : 3000 ,
251+ dryRun : true ,
252+ } ,
253+ } ) ;
254+
255+ const result = getEnvOptions ( { } , tempDir , {
256+ SMS_REQUEST_TIMEOUT_MS : '5s' ,
257+ } ) ;
258+
259+ expect ( result . sms ) . toEqual ( {
260+ requestTimeoutMs : 3000 ,
261+ dryRun : true ,
262+ } ) ;
263+ } ) ;
124264} ) ;
0 commit comments