Skip to content

Commit

Permalink
adjusts tests
Browse files Browse the repository at this point in the history
check if appversion is invalid
  • Loading branch information
ubamrein committed Jun 24, 2020
1 parent 88e6f4c commit 8fde064
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DPPPTConfigController() {
ConfigResponse config = new ConfigResponse();
//update message for various old builds
var appVersion = new Version(appversion);
if(appVersion.isSmallerVersionThan(initialReleaseVersion)) {
if(!appVersion.isValid() || appVersion.isSmallerVersionThan(initialReleaseVersion)) {
config = generalUpdateRelease1(buildnr.toLowerCase().startsWith("ios"));
}
//if we have testflight builds suggest to switch to store version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@

package org.dpppt.switzerland.backend.sdk.config.ws;

import org.dpppt.switzerland.backend.sdk.config.ws.model.ConfigResponse;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;

import io.jsonwebtoken.Jwts;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;


public class DPPPTConfigControllerTest extends BaseControllerTest {
@Autowired
ObjectMapper objectMapper;
@Test
public void testHello() throws Exception {
MockHttpServletResponse response = mockMvc.perform(get("/v1"))
Expand Down Expand Up @@ -54,4 +63,77 @@ public void testSecurityHeaders() throws Exception {
}

}

@Test
public void testForUpdateNote() throws Exception {
MockHttpServletResponse result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.0").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.1").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.2").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.3").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.4").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.5").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNoUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.6").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNoUpdate(result);
}
@Test
public void testForTestflight() throws Exception {
List<String> testflightVersions = List.of("ios-200619.2333.175",
"ios-200612.2347.141",
"ios-200528.2230.100",
"ios-200524.1316.87",
"ios-200521.2320.79");
for(var buildnr : testflightVersions) {
MockHttpServletResponse result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.0").param("buildnr", buildnr))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestTestflightUpdate(result);
}
MockHttpServletResponse result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.5").param("buildnr", "ios-200521.2320.80"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNoUpdate(result);
}

private void assertTestNoUpdate(MockHttpServletResponse result) throws Exception {
ConfigResponse resp = objectMapper.readValue(result.getContentAsString(Charset.forName("utf-8")), ConfigResponse.class);
assertNull(resp.getInfoBox());
}
private void assertTestNormalUpdate(MockHttpServletResponse result) throws Exception{
ConfigResponse resp = objectMapper.readValue(result.getContentAsString(Charset.forName("utf-8")), ConfigResponse.class);
assertNotNull(resp);
assertNotNull(resp.getInfoBox());
assertNotNull(resp.getInfoBox().getDeInfoBox());
assertEquals("App-Update verfügbar", resp.getInfoBox().getDeInfoBox().getTitle());
}
private void assertTestTestflightUpdate(MockHttpServletResponse result) throws Exception{
ConfigResponse resp = objectMapper.readValue(result.getContentAsString(Charset.forName("utf-8")), ConfigResponse.class);
assertNotNull(resp);
assertNotNull(resp.getInfoBox());
assertNotNull(resp.getInfoBox().getDeInfoBox());
assertEquals("App-Update im App Store", resp.getInfoBox().getDeInfoBox().getTitle());
}
}

0 comments on commit 8fde064

Please sign in to comment.