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

PB-UOE-10137 : Fetch platform details from wrapper_profile table and move to profile level #727

Merged
merged 9 commits into from
Apr 8, 2024
5 changes: 5 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type mySqlDB struct {
cfg config.Database
}

type PlatformStruct struct {
// other fields
Platform sql.NullString `json:"platform" db:"platform"`
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}

var db *mySqlDB
var dbOnce sync.Once

Expand Down
14 changes: 9 additions & 5 deletions modules/pubmatic/openwrap/database/mysql/partner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import (
// return the list of active server side header bidding partners
// with their configurations at publisher-profile-version level
func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayVersion int) (map[int]map[string]string, error) {
versionID, displayVersionID, err := db.getVersionID(profileID, displayVersion, pubID)
versionID, displayVersionID, platform, err := db.getVersionID(profileID, displayVersion, pubID)
if err != nil {
return nil, err
}

partnerConfigMap, err := db.getActivePartnerConfigurations(versionID)
if err == nil && partnerConfigMap[-1] != nil {
partnerConfigMap[-1][models.DisplayVersionID] = strconv.Itoa(displayVersionID)
if platform != "" {
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
partnerConfigMap[-1][models.PLATFORM_KEY] = platform
}
}
return partnerConfigMap, err
}
Expand Down Expand Up @@ -78,18 +81,19 @@ func (db *mySqlDB) getActivePartnerConfigurations(versionID int) (map[int]map[st
return partnerConfigMap, nil
}

func (db *mySqlDB) getVersionID(profileID, displayVersion, pubID int) (int, int, error) {
func (db *mySqlDB) getVersionID(profileID, displayVersion, pubID int) (int, int, string, error) {
var row *sql.Row
if displayVersion == 0 {
row = db.conn.QueryRow(db.cfg.Queries.LiveVersionInnerQuery, profileID, pubID)
} else {
row = db.conn.QueryRow(db.cfg.Queries.DisplayVersionInnerQuery, profileID, displayVersion, pubID)
}

var platformStruct PlatformStruct
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
var versionID, displayVersionIDFromDB int
err := row.Scan(&versionID, &displayVersionIDFromDB)
err := row.Scan(&versionID, &displayVersionIDFromDB, &platformStruct.Platform)
if err != nil {
return versionID, displayVersionIDFromDB, err
return versionID, displayVersionIDFromDB, platformStruct.Platform.String, err
}
return versionID, displayVersionIDFromDB, nil
return versionID, displayVersionIDFromDB, platformStruct.Platform.String, nil
}
25 changes: 16 additions & 9 deletions modules/pubmatic/openwrap/database/mysql/partner_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("25_1", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("25_1", "9", "display")
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

return db
Expand Down Expand Up @@ -79,7 +79,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("251", "9", "display")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

return db
Expand Down Expand Up @@ -131,7 +131,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("251", "9", "display")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
Expand Down Expand Up @@ -190,7 +190,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("251", "9", "display")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
Expand Down Expand Up @@ -257,7 +257,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("251", "9", "display")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
Expand Down Expand Up @@ -633,6 +633,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) {
args args
expectedVersionID int
expectedDisplayVersionIDFromDB int
expectedPlatform string
wantErr bool
setup func() *sql.DB
}{
Expand All @@ -652,14 +653,15 @@ func Test_mySqlDB_getVersionID(t *testing.T) {
},
expectedVersionID: 0,
expectedDisplayVersionIDFromDB: 0,
expectedPlatform: "",
wantErr: true,
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("25_1", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("25_1", "9", "in-app")
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

return db
Expand All @@ -682,14 +684,15 @@ func Test_mySqlDB_getVersionID(t *testing.T) {

expectedVersionID: 251,
expectedDisplayVersionIDFromDB: 9,
expectedPlatform: "in-app",
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform"}).AddRow("251", "9", "in-app")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

return db
Expand All @@ -712,14 +715,15 @@ func Test_mySqlDB_getVersionID(t *testing.T) {

expectedVersionID: 251,
expectedDisplayVersionIDFromDB: 9,
expectedPlatform: "in-app",
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId"}).AddRow("251", "9")
rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "in-app"}).AddRow("251", "9", "in-app")
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion)

return db
Expand All @@ -732,7 +736,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) {
conn: tt.setup(),
cfg: tt.fields.cfg,
}
got, got1, err := db.getVersionID(tt.args.profileID, tt.args.displayVersion, tt.args.pubID)
got, got1, got2, err := db.getVersionID(tt.args.profileID, tt.args.displayVersion, tt.args.pubID)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
if (err != nil) != tt.wantErr {
t.Errorf("mySqlDB.getVersionID() error = %v, wantErr %v", err, tt.wantErr)
return
Expand All @@ -743,6 +747,9 @@ func Test_mySqlDB_getVersionID(t *testing.T) {
if got1 != tt.expectedDisplayVersionIDFromDB {
t.Errorf("mySqlDB.getVersionID() got1 = %v, want %v", got1, tt.expectedDisplayVersionIDFromDB)
}
if got2 != tt.expectedPlatform {
t.Errorf("mySqlDB.getVersionID() got1 = %v, want %v", got2, tt.expectedPlatform)
}
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Loading