Skip to content

Commit

Permalink
Increase tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
marki1an committed Dec 3, 2024
1 parent ec35946 commit d9d83bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy)
class UserExt {

String consent
Expand All @@ -12,8 +15,9 @@ class UserExt {
UserTime time
UserExtData data
UserExtPrebid prebid
@JsonProperty("consented_providers_settings")
ConsentedProvidersSettings consentedProvidersSettings
@JsonProperty("ConsentedProvidersSettings")
ConsentedProvidersSettings consentedProvidersSettingsKebabCase

static UserExt getFPDUserExt() {
new UserExt(data: UserExtData.FPDUserExtData)
Expand Down
68 changes: 65 additions & 3 deletions src/test/groovy/org/prebid/server/functional/tests/AmpSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import org.prebid.server.functional.model.db.StoredRequest
import org.prebid.server.functional.model.db.StoredResponse
import org.prebid.server.functional.model.request.amp.AmpRequest
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.ConsentedProvidersSettings
import org.prebid.server.functional.model.request.auction.DistributionChannel
import org.prebid.server.functional.model.request.auction.Site
import org.prebid.server.functional.model.request.auction.StoredAuctionResponse
import org.prebid.server.functional.model.request.auction.User
import org.prebid.server.functional.model.request.auction.UserExt
import org.prebid.server.functional.model.response.auction.SeatBid
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.util.PBSUtils
Expand Down Expand Up @@ -56,7 +59,7 @@ class AmpSpec extends BaseSpec {
assert exception.responseBody == "Invalid request format: request.${channel.value.toLowerCase()} must not exist in AMP stored requests."

where:
channel << [DistributionChannel.APP, DistributionChannel.DOOH]
channel << [DistributionChannel.APP, DistributionChannel.DOOH]
}

def "PBS should return info from the stored response when it's defined in the stored request"() {
Expand Down Expand Up @@ -189,7 +192,36 @@ class AmpSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def ampStoredRequest = BidRequest.defaultBidRequest
def ampStoredRequest = BidRequest.defaultBidRequest.tap {
user = new User(ext: new UserExt(
consentedProvidersSettingsKebabCase: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString),
consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString)))
}
def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
defaultPbsService.sendAmpRequest(ampRequest)

then: "Bidder request should contain addtl consent"
def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id)
assert bidderRequest.user.ext.consentedProvidersSettingsKebabCase.consentedProviders == randomAddtlConsent
assert bidderRequest.user.ext.consentedProvidersSettings.consentedProviders == randomAddtlConsent
}

def "PBS should pass addtl_consent to user.ext.ConsentedProvidersSettings.consented_providers"() {
given: "Default amp request with addtlConsent"
def randomAddtlConsent = PBSUtils.randomString
def ampRequest = AmpRequest.defaultAmpRequest.tap {
addtlConsent = randomAddtlConsent
}

and: "Save storedRequest into DB"
def ampStoredRequest = BidRequest.defaultBidRequest.tap {
user = new User(ext: new UserExt(
consentedProvidersSettingsKebabCase: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString),
consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString)))
}
def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

Expand All @@ -198,6 +230,7 @@ class AmpSpec extends BaseSpec {

then: "Bidder request should contain addtl consent"
def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id)
assert bidderRequest.user.ext.consentedProvidersSettingsKebabCase.consentedProviders == randomAddtlConsent
assert bidderRequest.user.ext.consentedProvidersSettings.consentedProviders == randomAddtlConsent
}

Expand All @@ -208,7 +241,35 @@ class AmpSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def ampStoredRequest = BidRequest.defaultBidRequest
def ampStoredRequest = BidRequest.defaultBidRequest.tap {
user = new User(ext: new UserExt(
consentedProvidersSettingsKebabCase: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString),
consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString)))
}
def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
defaultPbsService.sendAmpRequest(ampRequest)

then: "Bidder request shouldn't contain addtl consent"
def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id)
assert !bidderRequest.user.ext.consentedProvidersSettings.consentedProviders
assert !bidderRequest.user.ext.consentedProvidersSettingsKebabCase.consentedProviders
}

def "PBS shouldn't pass addtl_consent to user.ext.ConsentedProvidersSettings.consented_providers when addtl_consent not specified"() {
given: "Default amp request without addtl_consent"
def ampRequest = AmpRequest.defaultAmpRequest.tap {
addtlConsent = null
}

and: "Save storedRequest into DB"
def ampStoredRequest = BidRequest.defaultBidRequest.tap {
user = new User(ext: new UserExt(
consentedProvidersSettingsKebabCase: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString),
consentedProvidersSettings: new ConsentedProvidersSettings(consentedProviders: PBSUtils.randomString)))
}
def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

Expand All @@ -218,5 +279,6 @@ class AmpSpec extends BaseSpec {
then: "Bidder request shouldn't contain addtl consent"
def bidderRequest = bidder.getBidderRequest(ampStoredRequest.id)
assert !bidderRequest.user.ext.consentedProvidersSettings.consentedProviders
assert !bidderRequest.user.ext.consentedProvidersSettingsKebabCase.consentedProviders
}
}

0 comments on commit d9d83bc

Please sign in to comment.