diff --git a/modules/pubmatic/openwrap/device.go b/modules/pubmatic/openwrap/device.go index 899a0c00d78..82dbd9acf2b 100644 --- a/modules/pubmatic/openwrap/device.go +++ b/modules/pubmatic/openwrap/device.go @@ -54,7 +54,7 @@ func updateDeviceIFADetails(dvc *models.DeviceCtx) { } else { deviceExt.DeleteIFAType() } - } else if extSessionID != "" { + } else if extSessionID != "" && dvc.DeviceIFA == "" { dvc.DeviceIFA = extSessionID dvc.IFATypeID = ptrutil.ToPtr(models.DeviceIfaTypeIdSessionId) deviceExt.SetIFAType(models.DeviceIFATypeSESSIONID) diff --git a/modules/pubmatic/openwrap/device_test.go b/modules/pubmatic/openwrap/device_test.go index 6fd88da9b6d..c9b48999951 100644 --- a/modules/pubmatic/openwrap/device_test.go +++ b/modules/pubmatic/openwrap/device_test.go @@ -390,6 +390,27 @@ func TestUpdateDeviceIFADetails(t *testing.T) { }(), }, }, + want: &models.DeviceCtx{ + DeviceIFA: `existing_ifa_id`, + Ext: func() *models.ExtDevice { + deviceExt := &models.ExtDevice{} + deviceExt.SetSessionID(`sample_session_id`) + return deviceExt + }(), + }, + }, + { + name: `ifa_type_missing_ifa_empty_session_id_present`, + args: args{ + dvc: &models.DeviceCtx{ + DeviceIFA: "", + Ext: func() *models.ExtDevice { + deviceExt := &models.ExtDevice{} + deviceExt.SetSessionID(`sample_session_id`) + return deviceExt + }(), + }, + }, want: &models.DeviceCtx{ IFATypeID: ptrutil.ToPtr(9), DeviceIFA: `sample_session_id`, @@ -397,11 +418,33 @@ func TestUpdateDeviceIFADetails(t *testing.T) { deviceExt := &models.ExtDevice{} deviceExt.SetIFAType(models.DeviceIFATypeSESSIONID) deviceExt.SetSessionID(`sample_session_id`) - return deviceExt }(), }, }, + { + name: `ifa_type_missing_ifa_not_present_session_id_present`, + args: args{ + dvc: &models.DeviceCtx{ + Ext: func() *models.ExtDevice { + deviceExt := &models.ExtDevice{} + deviceExt.SetSessionID(`sample_session_id`) + return deviceExt + }(), + }, + }, + want: &models.DeviceCtx{ + IFATypeID: ptrutil.ToPtr(9), + DeviceIFA: `sample_session_id`, + Ext: func() *models.ExtDevice { + deviceExt := &models.ExtDevice{} + deviceExt.SetIFAType(models.DeviceIFATypeSESSIONID) + deviceExt.SetSessionID(`sample_session_id`) + return deviceExt + }(), + }, + }, + // TODO: Add test cases. } for _, tt := range tests {