Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCOPS-1343: Handle legacy invalid profiles #582

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func (db *mySqlDB) GetAdunitConfig(profileID, displayVersion int) (*adunitconfig
adunitConfig.ConfigPattern = models.MACRO_AD_UNIT_ID
}

// safe check for old legacy profiles
// new profiles cannot be created as UI-API has config object validation
if adunitConfig.Config == nil {
adunitConfig.Config = make(map[string]*adunitconfig.AdConfig)
}

if _, ok := adunitConfig.Config["default"]; !ok {
adunitConfig.Config["default"] = &adunitconfig.AdConfig{}
}
Expand Down
30 changes: 30 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) {
return db
},
},
{
name: "config key not present",
fields: fields{
cfg: config.Database{
Queries: config.Queries{
GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)",
},
},
},
args: args{
profileID: 5890,
displayVersion: 1,
},
want: &adunitconfig.AdUnitConfig{
ConfigPattern: "_DIV_",
Config: map[string]*adunitconfig.AdConfig{
"default": {},
},
},
wantErr: false,
setup: func() *sql.DB {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
rows := sqlmock.NewRows([]string{"adunitConfig"}).AddRow(`{"configPattern": "_DIV_"}`)
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_media_config (.+)")).WillReturnRows(rows)
return db
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down