@@ -215,6 +215,41 @@ func TestNewFromEnv_AutoRegistrationYearGroups(t *testing.T) {
215215 assert .Equal (t , []int32 {6 , 7 , 8 }, cfg .AutoRegistrationYearGroups )
216216}
217217
218+ func TestNewFromEnv_ForceERPSyncOnStart (t * testing.T ) {
219+ tests := []struct {
220+ name string
221+ envValue string
222+ expected bool
223+ }{
224+ {
225+ name : "true value" ,
226+ envValue : "true" ,
227+ expected : true ,
228+ },
229+ {
230+ name : "false value" ,
231+ envValue : "false" ,
232+ expected : false ,
233+ },
234+ {
235+ name : "empty uses default false" ,
236+ envValue : "" ,
237+ expected : false ,
238+ },
239+ }
240+ for _ , tc := range tests {
241+ t .Run (tc .name , func (t * testing.T ) {
242+ loadTestEnvVariables (t , map [string ]string {
243+ "FORCE_ERP_SYNC_ON_START" : tc .envValue ,
244+ })
245+
246+ cfg , err := NewFromEnv ()
247+ assert .NoError (t , err )
248+ assert .Equal (t , tc .expected , cfg .ForceERPSyncOnStart )
249+ })
250+ }
251+ }
252+
218253func TestNewFromEnv_ParseError (t * testing.T ) {
219254 oldParse := parseEnv
220255 parseEnv = func (_ interface {}, _ ... env.Options ) error {
@@ -254,6 +289,57 @@ func TestGetDatabaseURLForMysqlFromEnv_ParseError(t *testing.T) {
254289 assert .False (t , ok )
255290}
256291
292+ func TestIsERPIntegrated (t * testing.T ) {
293+ var tests = []struct {
294+ name string
295+ newEnv map [string ]string
296+ expectedResult bool
297+ }{
298+ {
299+ name : "all required variables are set" ,
300+ newEnv : map [string ]string {
301+ "ISAMS_BASE_URL" : "https://example.com" ,
302+ "ISAMS_API_CLIENT_ID" : "client-id" ,
303+ "ISAMS_API_CLIENT_SECRET" : "client-secret" ,
304+ },
305+ expectedResult : true ,
306+ },
307+ {
308+ name : "missing ISAMS_BASE_URL" ,
309+ newEnv : map [string ]string {
310+ "ISAMS_API_CLIENT_ID" : "client-id" ,
311+ "ISAMS_API_CLIENT_SECRET" : "client-secret" ,
312+ },
313+ expectedResult : false ,
314+ },
315+ {
316+ name : "missing ISAMS_API_CLIENT_ID" ,
317+ newEnv : map [string ]string {
318+ "ISAMS_BASE_URL" : "https://example.com" ,
319+ "ISAMS_API_CLIENT_SECRET" : "client-secret" ,
320+ },
321+ expectedResult : false ,
322+ },
323+ {
324+ name : "missing ISAMS_API_CLIENT_SECRET" ,
325+ newEnv : map [string ]string {
326+ "ISAMS_BASE_URL" : "https://example.com" ,
327+ "ISAMS_API_CLIENT_ID" : "client-id" ,
328+ },
329+ expectedResult : false ,
330+ },
331+ }
332+ for _ , tc := range tests {
333+ t .Run (tc .name , func (t * testing.T ) {
334+ loadTestEnvVariables (t , tc .newEnv )
335+
336+ cfg , err := NewFromEnv ()
337+ assert .NoError (t , err )
338+ assert .Equal (t , tc .expectedResult , cfg .IsERPIntegrated ())
339+ })
340+ }
341+ }
342+
257343func loadTestEnvVariables (t * testing.T , env map [string ]string ) {
258344 t .Helper ()
259345 resetConfigEnv (t )
@@ -281,6 +367,7 @@ func resetConfigEnv(t *testing.T) {
281367 "STUDENTS_IMAGE_PHOTO_DIR" ,
282368 "STUDENTS_IMAGE_PHOTO_URL_PREFIX" ,
283369 "AUTO_REGISTRATION_YEAR_GROUPS" ,
370+ "FORCE_ERP_SYNC_ON_START" ,
284371 "DATABASE_HOST" ,
285372 "DATABASE_PORT" ,
286373 "DATABASE_USERNAME" ,
0 commit comments