Skip to content

Commit 6ba1166

Browse files
committed
Increase test coverage
1 parent c88a5a2 commit 6ba1166

File tree

2 files changed

+109
-56
lines changed

2 files changed

+109
-56
lines changed

src/test/groovy/org/prebid/server/functional/tests/GeneralGetInterfaceImpSpec.groovy

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.prebid.server.functional.tests
22

33
import org.prebid.server.functional.model.db.StoredRequest
4+
import org.prebid.server.functional.model.request.amp.Targeting
45
import org.prebid.server.functional.model.request.auction.BidRequest
56
import org.prebid.server.functional.model.request.auction.Format
67
import org.prebid.server.functional.model.request.auction.Imp
@@ -13,6 +14,8 @@ import org.prebid.server.functional.service.PrebidServerException
1314
import org.prebid.server.functional.util.PBSUtils
1415
import spock.lang.PendingFeature
1516

17+
import java.nio.charset.StandardCharsets
18+
1619
import static org.prebid.server.functional.model.response.auction.ErrorType.PREBID
1720

1821
class GeneralGetInterfaceImpSpec extends BaseSpec {
@@ -1675,4 +1678,60 @@ class GeneralGetInterfaceImpSpec extends BaseSpec {
16751678
it.nvol == audioImp.audio.nvol
16761679
}
16771680
}
1681+
1682+
def "PBS get request should move targeting key to imp.ext.data"() {
1683+
given: "Create targeting"
1684+
def targeting = new Targeting().tap {
1685+
any = PBSUtils.randomString
1686+
}
1687+
1688+
and: "Encode Targeting to String"
1689+
def encodeTargeting = URLEncoder.encode(encode(targeting), StandardCharsets.UTF_8)
1690+
1691+
and: "Amp request with targeting"
1692+
def generalGetRequest = GeneralGetRequest.default.tap {
1693+
it.targeting = encodeTargeting
1694+
}
1695+
1696+
and: "Default BidRequest"
1697+
def bidRequest = BidRequest.defaultBidRequest
1698+
1699+
and: "Create and save stored request into DB"
1700+
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, bidRequest)
1701+
storedRequestDao.save(storedRequest)
1702+
1703+
when: "PBS processes amp request"
1704+
defaultPbsService.sendGeneralGetRequest(generalGetRequest)
1705+
1706+
then: "Amp response should contain value from targeting in imp.ext.data"
1707+
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
1708+
assert bidderRequest.imp[0].ext.data.any == targeting.any
1709+
}
1710+
1711+
def "PBS should throw exception when general get request linked to stored request with several imps"() {
1712+
given: "Stored request with several imps"
1713+
def request = BidRequest.getDefaultBidRequest().tap {
1714+
addImp(Imp.defaultImpression)
1715+
setAccountId(accountId)
1716+
}
1717+
1718+
and: "Save storedRequest into DB"
1719+
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
1720+
storedRequestDao.save(storedRequest)
1721+
1722+
when: "PBS processes general get request"
1723+
defaultPbsService.sendGeneralGetRequest(generalGetRequest)
1724+
1725+
then: "PBs should throw error due to invalid request"
1726+
def exception = thrown(PrebidServerException)
1727+
assert exception.statusCode == 400
1728+
assert exception.responseBody == "data for tag_id '${generalGetRequest.resolveStoredRequestId()}' includes '${request.imp.size()}'" +
1729+
" imp elements. Only one is allowed"
1730+
1731+
where:
1732+
generalGetRequest << [
1733+
new GeneralGetRequest(storedRequestId: PBSUtils.randomNumber),
1734+
new GeneralGetRequest(storedRequestIdLegacy: PBSUtils.randomNumber)
1735+
]
1736+
}
16781737
}

src/test/groovy/org/prebid/server/functional/tests/ProfileSpec.groovy

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,32 +1519,61 @@ class ProfileSpec extends BaseSpec {
15191519
]
15201520
}
15211521

1522-
def "PBS should throw exception when profiles are not configured for filesystem and request contain profileId"() {
1522+
def "PBS should process request when profiles are not configured for filesystem and request contain profileId"() {
15231523
given: "PBS with profiles.fail-on-unknown config"
15241524
def config = FILESYSTEM_CONFIG + PROFILES_CONFIG + ['settings.filesystem.profiles-dir': null]
15251525
pbsContainer = new PrebidServerContainer(config)
15261526
pbsContainer.withFolder(REQUESTS_PATH)
15271527
pbsContainer.withFolder(IMPS_PATH)
15281528
pbsContainer.withFolder(RESPONSES_PATH)
15291529
pbsContainer.withFolder(CATEGORIES_PATH)
1530+
pbsContainer.withCopyToContainer(Transferable.of(encode(fileRequestProfileWithEmptyMerge)), "$PROFILES_PATH/${fileRequestProfileWithEmptyMerge.fileName}")
15301531
def accountsConfig = new FileSystemAccountsConfig(accounts: [new AccountConfig(id: ACCOUNT_ID_FILE_STORAGE, status: ACTIVE)])
15311532
pbsContainer.withCopyToContainer(Transferable.of(encodeYaml(accountsConfig)),
15321533
SETTINGS_FILENAME)
15331534
pbsContainer.start()
15341535
def pbsWithStoredProfiles = new PrebidServerService(pbsContainer)
15351536

15361537
and: "BidRequest with profile"
1537-
def requestWithProfile = BidRequest.getDefaultBidRequest().tap {
1538-
it.ext.prebid.profileNames = [PBSUtils.randomString]
1539-
}
1538+
def requestWithProfile = getRequestWithProfiles(ACCOUNT_ID_FILE_STORAGE.toString(), [fileRequestProfileWithEmptyMerge]).tap {
1539+
it.device = Device.default
1540+
} as BidRequest
15401541

15411542
when: "PBS processes auction request"
1542-
pbsWithStoredProfiles.sendAuctionRequest(requestWithProfile)
1543+
def response = pbsWithStoredProfiles.sendAuctionRequest(requestWithProfile)
15431544

1544-
then: "PBs should throw error due to invalid profile config"
1545-
def exception = thrown(PrebidServerException)
1546-
assert exception.statusCode == 400
1547-
assert exception.responseBody == INVALID_REQUEST_PREFIX + CONFIG_ERROR_MESSAGE
1545+
then: "PBS should emit proper warning"
1546+
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
1547+
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_REQUEST_PROFILE_MESSAGE.formatted(fileRequestProfileWithEmptyMerge.id)]
1548+
1549+
and: "Response should contain error"
1550+
assert !response.ext?.errors
1551+
1552+
and: "Missing metric should increments"
1553+
def metrics = pbsWithStoredProfiles.sendCollectedMetricsRequest()
1554+
assert metrics[MISSING_ACCOUNT_PROFILE_METRIC.formatted(ACCOUNT_ID_FILE_STORAGE)] == 1
1555+
1556+
and: "Bidder request should contain data from profile"
1557+
verifyAll(bidder.getBidderRequest(requestWithProfile.id)) {
1558+
it.site.id == requestWithProfile.site.id
1559+
it.site.name == requestWithProfile.site.name
1560+
it.site.domain == requestWithProfile.site.domain
1561+
it.site.cat == requestWithProfile.site.cat
1562+
it.site.sectionCat == requestWithProfile.site.sectionCat
1563+
it.site.pageCat == requestWithProfile.site.pageCat
1564+
it.site.page == requestWithProfile.site.page
1565+
it.site.ref == requestWithProfile.site.ref
1566+
it.site.search == requestWithProfile.site.search
1567+
it.site.keywords == requestWithProfile.site.keywords
1568+
1569+
it.device.didsha1 == requestWithProfile.device.didsha1
1570+
it.device.didmd5 == requestWithProfile.device.didmd5
1571+
it.device.dpidsha1 == requestWithProfile.device.dpidsha1
1572+
it.device.ifa == requestWithProfile.device.ifa
1573+
it.device.macsha1 == requestWithProfile.device.macsha1
1574+
it.device.macmd5 == requestWithProfile.device.macmd5
1575+
it.device.dpidmd5 == requestWithProfile.device.dpidmd5
1576+
}
15481577

15491578
cleanup: "Stop and remove pbs container"
15501579
pbsContainer.stop()
@@ -1563,15 +1592,16 @@ class ProfileSpec extends BaseSpec {
15631592

15641593
and: "Default stored request"
15651594
def request = BidRequest.getDefaultBidRequest().tap {
1595+
it.device = Device.default
15661596
setAccountId(accountId)
15671597
}
15681598

15691599
and: "Save storedRequest into DB"
1570-
def storedRequest = StoredRequest.getStoredRequest(getRequest.resolveStoredRequestId(), request)
1600+
def storedRequest = StoredRequest.getStoredRequest(getRequest.storedRequestId, request)
15711601
storedRequestDao.save(storedRequest)
15721602

15731603
when: "PBS processes general get request"
1574-
def response = pbsWithStoredProfiles.(getRequest)
1604+
def response = pbsWithStoredProfiles.sendGeneralGetRequest(getRequest)
15751605

15761606
then: "Response should not contain errors and warnings"
15771607
assert !response.ext?.errors
@@ -1589,7 +1619,6 @@ class ProfileSpec extends BaseSpec {
15891619
it.site.ref == requestProfile.body.site.ref
15901620
it.site.search == requestProfile.body.site.search
15911621
it.site.keywords == requestProfile.body.site.keywords
1592-
it.site.ext.data == requestProfile.body.site.ext.data
15931622

15941623
it.device.didsha1 == requestProfile.body.device.didsha1
15951624
it.device.didmd5 == requestProfile.body.device.didmd5
@@ -1723,6 +1752,7 @@ class ProfileSpec extends BaseSpec {
17231752

17241753
and: "Default stored request"
17251754
def request = BidRequest.getDefaultBidRequest().tap {
1755+
it.device = Device.default
17261756
setAccountId(accountId)
17271757
}
17281758

@@ -1756,7 +1786,6 @@ class ProfileSpec extends BaseSpec {
17561786
it.site.ref == request.site.ref
17571787
it.site.search == request.site.search
17581788
it.site.keywords == request.site.keywords
1759-
it.site.ext.data == request.site.ext.data
17601789

17611790
it.device.didsha1 == request.device.didsha1
17621791
it.device.didmd5 == request.device.didmd5
@@ -1816,19 +1845,20 @@ class ProfileSpec extends BaseSpec {
18161845
and: "Default stored request"
18171846
def accountId = PBSUtils.randomNumber as String
18181847
def request = BidRequest.getDefaultBidRequest().tap {
1848+
it.device = Device.default
18191849
setAccountId(accountId)
18201850
}
18211851

18221852
and: "Save storedRequest into DB"
1823-
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
1853+
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, request)
18241854
storedRequestDao.save(storedRequest)
18251855

18261856
when: "PBS processes general get request"
18271857
def response = pbsWithStoredProfiles.sendGeneralGetRequest(generalGetRequest)
18281858

18291859
then: "PBS should emit proper warning"
18301860
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
1831-
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_PROFILE_MESSAGE.formatted(requestProfile)]
1861+
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_REQUEST_PROFILE_MESSAGE.formatted(requestProfile)]
18321862

18331863
and: "Response should contain error"
18341864
assert !response.ext?.errors
@@ -1849,7 +1879,6 @@ class ProfileSpec extends BaseSpec {
18491879
it.site.ref == request.site.ref
18501880
it.site.search == request.site.search
18511881
it.site.keywords == request.site.keywords
1852-
it.site.ext.data == request.site.ext.data
18531882

18541883
it.device.didsha1 == request.device.didsha1
18551884
it.device.didmd5 == request.device.didmd5
@@ -1871,14 +1900,15 @@ class ProfileSpec extends BaseSpec {
18711900

18721901
def "PBS should emit error and metrics when imp profile missing for profile general get parameter"() {
18731902
given: "Default GeneralGetRequest"
1874-
def impProfile = PBSUtils.randomString
1903+
def impProfileId = PBSUtils.randomString
18751904
def generalGetRequest = GeneralGetRequest.default.tap {
1876-
it.impProfiles = [impProfile]
1905+
it.impProfiles = [impProfileId]
18771906
}
18781907

18791908
and: "Default stored request"
18801909
def accountId = PBSUtils.randomNumber as String
18811910
def request = BidRequest.getDefaultBidRequest().tap {
1911+
it.device = Device.default
18821912
setAccountId(accountId)
18831913
}
18841914

@@ -1891,7 +1921,7 @@ class ProfileSpec extends BaseSpec {
18911921

18921922
then: "PBS should emit proper warning"
18931923
assert response.ext?.warnings[ErrorType.PREBID]*.code == [999]
1894-
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_PROFILE_MESSAGE.formatted(impProfile.id)]
1924+
assert response.ext?.warnings[ErrorType.PREBID]*.message == [NO_IMP_PROFILE_MESSAGE.formatted(impProfileId)]
18951925

18961926
and: "Response should contain error"
18971927
assert !response.ext?.errors
@@ -1912,7 +1942,6 @@ class ProfileSpec extends BaseSpec {
19121942
it.site.ref == request.site.ref
19131943
it.site.search == request.site.search
19141944
it.site.keywords == request.site.keywords
1915-
it.site.ext.data == request.site.ext.data
19161945

19171946
it.device.didsha1 == request.device.didsha1
19181947
it.device.didmd5 == request.device.didmd5
@@ -2022,7 +2051,7 @@ class ProfileSpec extends BaseSpec {
20222051
}
20232052

20242053
and: "Save storedRequest into DB"
2025-
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.getStoredAuctionResponseId(), request)
2054+
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.storedRequestId, request)
20262055
storedRequestDao.save(storedRequest)
20272056

20282057
when: "PBS processes general get request"
@@ -2091,41 +2120,6 @@ class ProfileSpec extends BaseSpec {
20912120
}
20922121
}
20932122

2094-
def "PBS should apply imp profile for all imps when profile included as parameter for with multi-imps general get request"() {
2095-
given: "Default profile in database"
2096-
def accountId = PBSUtils.randomNumber as String
2097-
def impProfile = ImpProfile.getProfile(accountId)
2098-
profileImpDao.save(StoredProfileImp.getProfile(impProfile))
2099-
2100-
and: "Default GeneralGetRequest"
2101-
def generalGetRequest = GeneralGetRequest.default.tap {
2102-
it.impProfiles = [impProfile.id]
2103-
}
2104-
2105-
and: "Default stored request"
2106-
def request = BidRequest.getDefaultBidRequest().tap {
2107-
addImp(Imp.defaultImpression)
2108-
setAccountId(accountId)
2109-
}
2110-
2111-
and: "Save storedRequest into DB"
2112-
def storedRequest = StoredRequest.getStoredRequest(generalGetRequest.resolveStoredRequestId(), request)
2113-
storedRequestDao.save(storedRequest)
2114-
2115-
when: "PBS processes general get request"
2116-
def response = pbsWithStoredProfiles.sendGeneralGetRequest(generalGetRequest)
2117-
2118-
then: "Response should not contain errors and warnings"
2119-
assert !response.ext?.errors
2120-
assert !response.ext?.warnings
2121-
2122-
and: "Bidder request imp should contain data from profile"
2123-
verifyAll(bidder.getBidderRequest(request.id).imp) {
2124-
it.id == [impProfile.body.id] * 2
2125-
it.banner == [impProfile.body.banner] * 2
2126-
}
2127-
}
2128-
21292123
private static BidRequest getRequestWithProfiles(String accountId, List<Profile> profiles) {
21302124
BidRequest.getDefaultBidRequest().tap {
21312125
it.imp.first.ext.prebid.profileNames = profiles.findAll { it.type == ProfileType.IMP }*.id

0 commit comments

Comments
 (0)