diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index 8a423f0a407..3f978cfad7c 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -14,7 +14,7 @@ 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 } @@ -22,6 +22,10 @@ func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayV partnerConfigMap, err := db.getActivePartnerConfigurations(versionID) if err == nil && partnerConfigMap[-1] != nil { partnerConfigMap[-1][models.DisplayVersionID] = strconv.Itoa(displayVersionID) + // check for SDK new UI + if platform != "" { + partnerConfigMap[-1][models.PLATFORM_KEY] = platform + } } return partnerConfigMap, err } @@ -76,7 +80,7 @@ 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) @@ -84,10 +88,11 @@ func (db *mySqlDB) getVersionID(profileID, displayVersion, pubID int) (int, int, row = db.conn.QueryRow(db.cfg.Queries.DisplayVersionInnerQuery, profileID, displayVersion, pubID) } + var platform sql.NullString var versionID, displayVersionIDFromDB int - err := row.Scan(&versionID, &displayVersionIDFromDB) + err := row.Scan(&versionID, &displayVersionIDFromDB, &platform) if err != nil { - return versionID, displayVersionIDFromDB, err + return versionID, displayVersionIDFromDB, platform.String, err } - return versionID, displayVersionIDFromDB, nil + return versionID, displayVersionIDFromDB, platform.String, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index ea9f5e57159..6647c9e384b 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -7,6 +7,7 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/prebid/prebid-server/modules/pubmatic/openwrap/config" + "github.com/prebid/prebid-server/modules/pubmatic/openwrap/models" "github.com/stretchr/testify/assert" ) @@ -32,7 +33,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", + LiveVersionInnerQuery: models.TestQuery, }, }, }, @@ -50,8 +51,8 @@ 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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("25_1", "9", models.PLATFORM_DISPLAY) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) return db }, @@ -61,7 +62,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", + LiveVersionInnerQuery: models.TestQuery, }, }, }, @@ -79,8 +80,8 @@ 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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_DISPLAY) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) return db }, @@ -90,8 +91,8 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + LiveVersionInnerQuery: models.TestQuery, + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -131,8 +132,8 @@ 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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_DISPLAY) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). @@ -140,7 +141,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "kgp", "_AU_@_W_x_H_"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "timeout", "200"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "serverSideEnabled", "1") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rowsPartnerConfig) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rowsPartnerConfig) return db }, }, @@ -149,8 +150,8 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - DisplayVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+)", - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + DisplayVersionInnerQuery: models.TestQuery, + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -190,8 +191,8 @@ 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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_DISPLAY) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). @@ -199,7 +200,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "kgp", "_AU_@_W_x_H_"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "timeout", "200"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "serverSideEnabled", "1") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rowsPartnerConfig) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rowsPartnerConfig) return db }, }, @@ -208,8 +209,8 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - DisplayVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+)", - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + DisplayVersionInnerQuery: models.TestQuery, + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -257,8 +258,8 @@ 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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_DISPLAY) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). @@ -279,12 +280,12 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { conn: tt.setup(), cfg: tt.fields.cfg, } - got, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion) + gotPartnerConfigMap, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion) if (err != nil) != tt.wantErr { t.Errorf("mySqlDB.GetActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr) return } - assert.Equal(t, tt.want, got) + assert.Equal(t, tt.want, gotPartnerConfigMap) }) } } @@ -321,7 +322,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -338,7 +339,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { } rows := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("11_11", "openx", "openx", 0, -1, 0, -1, "k1", "v1") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -347,7 +348,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -384,7 +385,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { AddRow(101, "openx", "openx", 0, -1, 0, 152, "k1", "v1"). AddRow(101, "openx", "openx", 0, -1, 0, 152, "k2", "v2"). AddRow(102, "pubmatic", "pubmatic", 0, -1, 0, 76, "k1", "v2") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -393,7 +394,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -436,7 +437,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { AddRow(101, "FirstPartnerName", "FirstBidder", 0, 3, 0, 152, "rev_share", "10"). AddRow(102, "SecondPartnerName", "SecondBidder", 0, -1, 0, 100, "k1", "v1"). AddRow(102, "SecondPartnerName", "SecondBidder", 0, -1, 0, 100, "k2", "v2") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -445,7 +446,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -491,7 +492,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { AddRow(101, "FirstPartnerName", "FirstBidder", 0, 3, 0, 76, "rev_share", "10"). AddRow(102, "SecondPartnerName", "SecondBidder", 0, -1, 0, 100, "k1", "v1"). AddRow(102, "SecondPartnerName", "SecondBidder", 0, -1, 0, 100, "k2", "v2") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -500,7 +501,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -544,7 +545,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { AddRow(101, "FirstPartnerName", "FirstBidder", 0, 3, 0, 76, "rev_share", "10"). AddRow(102, "SecondPartnerName", "SecondBidder", 1, -1, 0, 100, "k1", "v1"). AddRow(102, "SecondPartnerName", "SecondBidder", 1, -1, 0, 100, "k2", "v2") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -553,7 +554,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - GetParterConfig: "^SELECT (.+) FROM wrapper_config_map (.+)", + GetParterConfig: models.TestQuery, }, MaxDbContextTimeout: 1000, }, @@ -597,7 +598,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { AddRow(101, "FirstPartnerName", "FirstBidder", 0, 3, 0, 76, "rev_share", "10"). AddRow(102, "-", "-", 0, -1, 0, 100, "k1", "v1"). AddRow(102, "SecondPartnerName", "SecondBidder", 0, -1, 0, 100, "k2", "v2") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rows) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) return db }, }, @@ -608,12 +609,12 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { conn: tt.setup(), cfg: tt.fields.cfg, } - got, err := db.getActivePartnerConfigurations(tt.args.versionID) + gotPartnerConfigMap, err := db.getActivePartnerConfigurations(tt.args.versionID) if (err != nil) != tt.wantErr { t.Errorf("mySqlDB.getActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr) return } - assert.Equal(t, tt.want, got) + assert.Equal(t, tt.want, gotPartnerConfigMap) }) } } @@ -633,6 +634,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) { args args expectedVersionID int expectedDisplayVersionIDFromDB int + expectedPlatform string wantErr bool setup func() *sql.DB }{ @@ -641,7 +643,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", + LiveVersionInnerQuery: models.TestQuery, }, }, }, @@ -652,6 +654,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) { }, expectedVersionID: 0, expectedDisplayVersionIDFromDB: 0, + expectedPlatform: "", wantErr: true, setup: func() *sql.DB { db, mock, err := sqlmock.New() @@ -659,8 +662,8 @@ func Test_mySqlDB_getVersionID(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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("25_1", "9", models.PLATFORM_APP) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) return db }, @@ -670,7 +673,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", + LiveVersionInnerQuery: models.TestQuery, }, }, }, @@ -682,6 +685,7 @@ 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() @@ -689,8 +693,8 @@ func Test_mySqlDB_getVersionID(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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+) LIVE")).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_APP) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) return db }, @@ -700,7 +704,7 @@ func Test_mySqlDB_getVersionID(t *testing.T) { fields: fields{ cfg: config.Database{ Queries: config.Queries{ - DisplayVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+)", + DisplayVersionInnerQuery: models.TestQuery, }, }, }, @@ -712,6 +716,7 @@ 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() @@ -719,12 +724,96 @@ func Test_mySqlDB_getVersionID(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") - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_version (.+)")).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) + rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_APP) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) return db }, }, + { + name: "Platform is null", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + DisplayVersionInnerQuery: models.TestQuery, + }, + }, + }, + args: args{ + profileID: 19109, + displayVersion: 2, + pubID: 5890, + }, + expectedVersionID: 123, + expectedDisplayVersionIDFromDB: 12, + expectedPlatform: "", + 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{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("123", "12", nil) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 2, 5890).WillReturnRows(rowsWrapperVersion) + return db + }, + }, + { + name: "Platform is empty string", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + LiveVersionInnerQuery: models.TestQuery, + }, + }, + }, + args: args{ + profileID: 19109, + displayVersion: 0, + pubID: 5890, + }, + expectedVersionID: 251, + expectedDisplayVersionIDFromDB: 9, + expectedPlatform: "", + 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{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", "") + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + return db + }, + }, + { + name: "Platform is not null", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + LiveVersionInnerQuery: models.TestQuery, + }, + }, + }, + args: args{ + profileID: 19109, + displayVersion: 0, + pubID: 5890, + }, + 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{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY}).AddRow("251", "9", models.PLATFORM_APP) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -732,17 +821,14 @@ 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) + gotVersionID, gotDisplayVersionID, gotPlatform, err := db.getVersionID(tt.args.profileID, tt.args.displayVersion, tt.args.pubID) if (err != nil) != tt.wantErr { t.Errorf("mySqlDB.getVersionID() error = %v, wantErr %v", err, tt.wantErr) return } - if got != tt.expectedVersionID { - t.Errorf("mySqlDB.getVersionID() got = %v, want %v", got, tt.expectedVersionID) - } - if got1 != tt.expectedDisplayVersionIDFromDB { - t.Errorf("mySqlDB.getVersionID() got1 = %v, want %v", got1, tt.expectedDisplayVersionIDFromDB) - } + assert.Equal(t, tt.expectedVersionID, gotVersionID) + assert.Equal(t, tt.expectedDisplayVersionIDFromDB, gotDisplayVersionID) + assert.Equal(t, tt.expectedPlatform, gotPlatform) }) } } diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index fcadcbf8d6e..26609822d75 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -468,6 +468,7 @@ const ( //DisplayVersionInnerQuery = "DisplayVersionInnerQuery" //LiveVersionInnerQuery = "LiveVersionInnerQuery" //PMSlotToMappings = "GetPMSlotToMappings" + TestQuery = "TestQuery" ) // constants for owlogger Integration Type