Skip to content

Commit

Permalink
Adapter alias - syncer changes (#3082)
Browse files Browse the repository at this point in the history
co-authored by @onkarvhanumante
  • Loading branch information
onkarvhanumante authored Sep 29, 2023
1 parent 9e14c09 commit 061aa84
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
9 changes: 7 additions & 2 deletions config/bidderinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,13 @@ func processBidderAliases(aliasNillableFieldsByBidder map[string]aliasNillableFi
if aliasBidderInfo.PlatformID == "" {
aliasBidderInfo.PlatformID = parentBidderInfo.PlatformID
}
if aliasBidderInfo.Syncer == nil {
aliasBidderInfo.Syncer = parentBidderInfo.Syncer
if aliasBidderInfo.Syncer == nil && parentBidderInfo.Syncer != nil {
syncerKey := aliasBidderInfo.AliasOf
if parentBidderInfo.Syncer.Key != "" {
syncerKey = parentBidderInfo.Syncer.Key
}
syncer := Syncer{Key: syncerKey}
aliasBidderInfo.Syncer = &syncer
}
if aliasBidderInfo.UserSyncURL == "" {
aliasBidderInfo.UserSyncURL = parentBidderInfo.UserSyncURL
Expand Down
63 changes: 49 additions & 14 deletions config/bidderinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,6 @@ func TestProcessBidderInfo(t *testing.T) {
PlatformID: "123",
Syncer: &Syncer{
Key: "foo",
IFrame: &SyncerEndpoint{
URL: "https://foo.com/sync?mode=iframe&r={{.RedirectURL}}",
RedirectURL: "https://redirect/setuid/iframe",
ExternalURL: "https://iframe.host",
UserMacro: "UID",
},
},
UserSyncURL: "user-url",
XAPI: AdapterXAPI{
Expand All @@ -293,7 +287,7 @@ func TestProcessBidderInfo(t *testing.T) {
}

func TestProcessAliasBidderInfo(t *testing.T) {
parentBidderInfo := BidderInfo{
parentWithSyncerKey := BidderInfo{
AppSecret: "app-secret",
Capabilities: &CapabilitiesInfo{
App: &PlatformInfo{
Expand Down Expand Up @@ -389,8 +383,29 @@ func TestProcessAliasBidderInfo(t *testing.T) {
Tracker: "alias-tracker",
},
}
bidderB := parentBidderInfo
bidderB := parentWithSyncerKey
bidderB.AliasOf = "bidderA"
bidderB.Syncer = &Syncer{
Key: bidderB.Syncer.Key,
}

parentWithoutSyncerKey := BidderInfo{
Syncer: &Syncer{
IFrame: &SyncerEndpoint{
URL: "https://foo.com/sync?mode=iframe&r={{.RedirectURL}}",
RedirectURL: "https://redirect/setuid/iframe",
ExternalURL: "https://iframe.host",
UserMacro: "UID",
},
},
}

bidderC := parentWithoutSyncerKey
bidderC.AliasOf = "bidderA"
bidderC.Syncer = &Syncer{
Key: "bidderA",
}

testCases := []struct {
description string
aliasInfos map[string]aliasNillableFields
Expand All @@ -399,7 +414,7 @@ func TestProcessAliasBidderInfo(t *testing.T) {
expectedErr error
}{
{
description: "inherit all parent info in alias bidder",
description: "inherit all parent info in alias bidder, use parent syncer key as syncer alias key",
aliasInfos: map[string]aliasNillableFields{
"bidderB": {
Disabled: nil,
Expand All @@ -409,14 +424,34 @@ func TestProcessAliasBidderInfo(t *testing.T) {
},
},
bidderInfos: BidderInfos{
"bidderA": parentBidderInfo,
"bidderA": parentWithSyncerKey,
"bidderB": BidderInfo{
AliasOf: "bidderA",
// all other fields should be inherited from parent bidder
},
},
expectedErr: nil,
expectedBidderInfos: BidderInfos{"bidderA": parentBidderInfo, "bidderB": bidderB},
expectedBidderInfos: BidderInfos{"bidderA": parentWithSyncerKey, "bidderB": bidderB},
},
{
description: "inherit all parent info in alias bidder, use parent name as syncer alias key",
aliasInfos: map[string]aliasNillableFields{
"bidderC": {
Disabled: nil,
ModifyingVastXmlAllowed: nil,
Experiment: nil,
XAPI: nil,
},
},
bidderInfos: BidderInfos{
"bidderA": parentWithoutSyncerKey,
"bidderC": BidderInfo{
AliasOf: "bidderA",
// all other fields should be inherited from parent bidder
},
},
expectedErr: nil,
expectedBidderInfos: BidderInfos{"bidderA": parentWithoutSyncerKey, "bidderC": bidderC},
},
{
description: "all bidder info specified for alias, do not inherit from parent bidder",
Expand All @@ -429,11 +464,11 @@ func TestProcessAliasBidderInfo(t *testing.T) {
},
},
bidderInfos: BidderInfos{
"bidderA": parentBidderInfo,
"bidderA": parentWithSyncerKey,
"bidderB": aliasBidderInfo,
},
expectedErr: nil,
expectedBidderInfos: BidderInfos{"bidderA": parentBidderInfo, "bidderB": aliasBidderInfo},
expectedBidderInfos: BidderInfos{"bidderA": parentWithSyncerKey, "bidderB": aliasBidderInfo},
},
{
description: "invalid alias",
Expand Down Expand Up @@ -461,7 +496,7 @@ func TestProcessAliasBidderInfo(t *testing.T) {
if test.expectedErr != nil {
assert.Equal(t, test.expectedErr, err)
} else {
assert.Equal(t, test.expectedBidderInfos, bidderInfos)
assert.Equal(t, test.expectedBidderInfos, bidderInfos, test.description)
}
}
}
Expand Down

0 comments on commit 061aa84

Please sign in to comment.