From d2a3d3f475f89b31d13c0469e8e7624b6618689d Mon Sep 17 00:00:00 2001 From: Pubmatic-Supriya-Patil <131644110+Pubmatic-Supriya-Patil@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:23:13 +0530 Subject: [PATCH] OTT-1982: honor IFA over session_id if when ifa_type is absent (#895) --- modules/pubmatic/openwrap/device.go | 2 +- modules/pubmatic/openwrap/device_test.go | 45 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) 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 {