Skip to content

Commit

Permalink
Fix iOS LMT bug to support 15+ and PATCH version (#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanchyk authored Feb 25, 2021
1 parent 719dcf4 commit c748093
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private static Integer resolveLmt(Device device, App app) {

// osv format expected: "[major].[minor]". Example: 14.0
final String[] versionParts = StringUtils.split(osv, '.');
if (versionParts.length != 2) {
if (versionParts.length < 2) {
return null;
}

Expand All @@ -435,11 +435,7 @@ private static Integer resolveLmt(Device device, App app) {
return null;
}

if (versionMajor < 14) {
return null;
}

return resolveLmtForIos14AndHigher(device, versionMinor);
return resolveLmtForIos(device, versionMajor, versionMinor);
}

private static Integer tryParseAsNumber(String number) {
Expand All @@ -450,12 +446,16 @@ private static Integer tryParseAsNumber(String number) {
}
}

private static Integer resolveLmtForIos14AndHigher(Device device, Integer versionMinor) {
if (versionMinor == 0 || versionMinor == 1) {
private static Integer resolveLmtForIos(Device device, Integer versionMajor, Integer versionMinor) {
if (versionMajor < 14) {
return null;
}

if (versionMajor == 14 && (versionMinor == 0 || versionMinor == 1)) {
return resolveLmtForIos14Minor0And1(device);
}

if (versionMinor >= 2) {
if (versionMajor > 14 || versionMinor >= 2) {
return resolveLmtForIos14Minor2AndHigher(device);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,24 @@ public void shouldNotSetDeviceLmtForIosInvalidVersionMinor() {
assertThat(request.getDevice().getLmt()).isNull();
}

@Test
public void shouldNotSetDeviceLmtForIosMissingVersionMinor() {
// given
givenBidRequest(BidRequest.builder()
.app(App.builder().build())
.device(Device.builder()
.os("iOS")
.osv("14")
.build())
.build());

// when
final BidRequest request = factory.fromRequest(routingContext, 0L).result().getBidRequest();

// then
assertThat(request.getDevice().getLmt()).isNull();
}

@Test
public void shouldNotSetDeviceLmtForIosLowerThan14() {
// given
Expand All @@ -648,6 +666,24 @@ public void shouldNotSetDeviceLmtForIosLowerThan14() {
assertThat(request.getDevice().getLmt()).isNull();
}

@Test
public void shouldSetDeviceLmtOneForIos14WithPatchVersion() {
// given
givenBidRequest(BidRequest.builder()
.app(App.builder().build())
.device(Device.builder()
.os("iOS")
.osv("14.0.patch-version")
.build())
.build());

// when
final BidRequest request = factory.fromRequest(routingContext, 0L).result().getBidRequest();

// then
assertThat(request.getDevice().getLmt()).isOne();
}

@Test
public void shouldSetDeviceLmtOneForIos14Minor0() {
// given
Expand Down Expand Up @@ -945,7 +981,7 @@ public void shouldNotOverrideDeviceLmtForIos14Minor2AndAtts1() {
.lmt(0)
.os("iOS")
.osv("14.2")
.ext(ExtDevice.of(2, null))
.ext(ExtDevice.of(1, null))
.build())
.build());

Expand All @@ -957,13 +993,32 @@ public void shouldNotOverrideDeviceLmtForIos14Minor2AndAtts1() {
}

@Test
public void shouldSetDeviceLmtOneForIos14Minor3AndAtts2() {
public void shouldSetDeviceLmtOneForIos15Minor0AndAtts1() {
// given
givenBidRequest(BidRequest.builder()
.app(App.builder().build())
.device(Device.builder()
.os("iOS")
.osv("14.3")
.osv("15.0")
.ext(ExtDevice.of(1, null))
.build())
.build());

// when
final BidRequest request = factory.fromRequest(routingContext, 0L).result().getBidRequest();

// then
assertThat(request.getDevice().getLmt()).isOne();
}

@Test
public void shouldSetDeviceLmtOneForIos15Minor0AndAtts2() {
// given
givenBidRequest(BidRequest.builder()
.app(App.builder().build())
.device(Device.builder()
.os("iOS")
.osv("15.0")
.ext(ExtDevice.of(2, null))
.build())
.build());
Expand Down

0 comments on commit c748093

Please sign in to comment.