|
14 | 14 | import org.prebid.server.auction.privacy.enforcement.mask.UserFpdActivityMask; |
15 | 15 | import org.prebid.server.execution.timeout.Timeout; |
16 | 16 | import org.prebid.server.hooks.execution.v1.auction.AuctionRequestPayloadImpl; |
| 17 | +import org.prebid.server.hooks.modules.optable.targeting.model.ModuleContext; |
| 18 | +import org.prebid.server.hooks.modules.optable.targeting.model.Status; |
17 | 19 | import org.prebid.server.hooks.modules.optable.targeting.v1.core.ConfigResolver; |
18 | 20 | import org.prebid.server.hooks.modules.optable.targeting.v1.core.OptableTargeting; |
19 | 21 | import org.prebid.server.hooks.v1.InvocationAction; |
@@ -61,7 +63,8 @@ public void setUp() { |
61 | 63 | target = new OptableTargetingProcessedAuctionRequestHook( |
62 | 64 | configResolver, |
63 | 65 | optableTargeting, |
64 | | - userFpdActivityMask); |
| 66 | + userFpdActivityMask, |
| 67 | + 0.01); |
65 | 68 |
|
66 | 69 | when(invocationContext.accountConfig()).thenReturn(givenAccountConfig(true)); |
67 | 70 | when(invocationContext.auctionContext()).thenReturn(givenAuctionContext(activityInfrastructure, timeout)); |
@@ -128,6 +131,70 @@ public void shouldReturnResultWithUpdateActionWhenOptableTargetingReturnTargetin |
128 | 131 | assertThat(bidRequest.getUser().getData().getFirst().getSegment().getFirst().getId()).isEqualTo("id"); |
129 | 132 | } |
130 | 133 |
|
| 134 | + @Test |
| 135 | + public void shouldReturnFailWhenOriginIsAbsentInAccountConfiguration() { |
| 136 | + // given |
| 137 | + configResolver = new ConfigResolver( |
| 138 | + mapper, |
| 139 | + jsonMerger, |
| 140 | + givenOptableTargetingProperties("key", "tenant", null, false)); |
| 141 | + target = new OptableTargetingProcessedAuctionRequestHook( |
| 142 | + configResolver, |
| 143 | + optableTargeting, |
| 144 | + userFpdActivityMask, |
| 145 | + 0.01); |
| 146 | + when(invocationContext.accountConfig()) |
| 147 | + .thenReturn(givenAccountConfig("key", "tenant", null, true)); |
| 148 | + |
| 149 | + // when |
| 150 | + final Future<InvocationResult<AuctionRequestPayload>> future = target.call(auctionRequestPayload, |
| 151 | + invocationContext); |
| 152 | + |
| 153 | + // then |
| 154 | + assertThat(future).isNotNull(); |
| 155 | + assertThat(future.succeeded()).isTrue(); |
| 156 | + |
| 157 | + final InvocationResult<AuctionRequestPayload> result = future.result(); |
| 158 | + assertThat(result).isNotNull(); |
| 159 | + assertThat(result.status()).isEqualTo(InvocationStatus.success); |
| 160 | + assertThat(result.action()).isEqualTo(InvocationAction.update); |
| 161 | + assertThat((ModuleContext) result.moduleContext()) |
| 162 | + .extracting(it -> it.getEnrichRequestStatus().getStatus()) |
| 163 | + .isEqualTo(Status.FAIL); |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void shouldReturnFailWhenTenantIsAbsentInAccountConfiguration() { |
| 168 | + // given |
| 169 | + configResolver = new ConfigResolver( |
| 170 | + mapper, |
| 171 | + jsonMerger, |
| 172 | + givenOptableTargetingProperties("key", null, "origin", false)); |
| 173 | + target = new OptableTargetingProcessedAuctionRequestHook( |
| 174 | + configResolver, |
| 175 | + optableTargeting, |
| 176 | + userFpdActivityMask, |
| 177 | + 0.01); |
| 178 | + when(invocationContext.accountConfig()) |
| 179 | + .thenReturn(givenAccountConfig("key", null, null, true)); |
| 180 | + |
| 181 | + // when |
| 182 | + final Future<InvocationResult<AuctionRequestPayload>> future = target.call(auctionRequestPayload, |
| 183 | + invocationContext); |
| 184 | + |
| 185 | + // then |
| 186 | + assertThat(future).isNotNull(); |
| 187 | + assertThat(future.succeeded()).isTrue(); |
| 188 | + |
| 189 | + final InvocationResult<AuctionRequestPayload> result = future.result(); |
| 190 | + assertThat(result).isNotNull(); |
| 191 | + assertThat(result.status()).isEqualTo(InvocationStatus.success); |
| 192 | + assertThat(result.action()).isEqualTo(InvocationAction.update); |
| 193 | + assertThat((ModuleContext) result.moduleContext()) |
| 194 | + .extracting(it -> it.getEnrichRequestStatus().getStatus()) |
| 195 | + .isEqualTo(Status.FAIL); |
| 196 | + } |
| 197 | + |
131 | 198 | @Test |
132 | 199 | public void shouldReturnResultWithCleanedUpUserExtOptableTag() { |
133 | 200 | // given |
@@ -180,6 +247,10 @@ public void shouldReturnResultWithUpdateWhenOptableTargetingDoesntReturnResult() |
180 | 247 | } |
181 | 248 |
|
182 | 249 | private ObjectNode givenAccountConfig(boolean cacheEnabled) { |
183 | | - return mapper.valueToTree(givenOptableTargetingProperties(cacheEnabled)); |
| 250 | + return givenAccountConfig("key", "tenant", "origin", cacheEnabled); |
| 251 | + } |
| 252 | + |
| 253 | + private ObjectNode givenAccountConfig(String key, String tenant, String origin, boolean cacheEnabled) { |
| 254 | + return mapper.valueToTree(givenOptableTargetingProperties(key, tenant, origin, cacheEnabled)); |
184 | 255 | } |
185 | 256 | } |
0 commit comments