Skip to content

Commit

Permalink
add missing challenge tests, fix typo in save state
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Jul 14, 2024
1 parent fe002c9 commit 7a778a2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum CHALLENGE {
POST_RESTORE_EXISTING_CHALLENGER,
POST_TODOS_TOO_LONG_PAYLOAD_SIZE,
POST_TODOS_INVALID_EXTRA_FIELD,
POST_MAX_OUT_TITILE_DESCRIPTION_LENGTH,
POST_MAX_OUT_TITLE_DESCRIPTION_LENGTH,
PUT_TODOS_400,
POST_TODOS_404,
PUT_TODOS_FULL_200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public HttpApiResponse run(final HttpApiRequest request,
if(aTodo.getFieldValue("title").asString().length() == 50 &&
aTodo.getFieldValue("description").asString().length() == 200
){
challengers.pass(challenger, CHALLENGE.POST_MAX_OUT_TITILE_DESCRIPTION_LENGTH);
challengers.pass(challenger, CHALLENGE.POST_MAX_OUT_TITLE_DESCRIPTION_LENGTH);
}
}
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ChallengeDefinitions(ChallengerConfig config){
storeChallengeAs(CHALLENGE.POST_TODOS_BAD_DONE_STATUS, PostChallenges.postTodosBadDoneStatus400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_TODOS_TOO_LONG_TITLE_LENGTH, PostChallenges.postTodosTitleTooLong400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_TODOS_TOO_LONG_DESCRIPTION_LENGTH, PostChallenges.postTodosDescriptionTooLong400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_MAX_OUT_TITILE_DESCRIPTION_LENGTH, PostChallenges.postTodosMaxTitleDescriptionTooLong400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_MAX_OUT_TITLE_DESCRIPTION_LENGTH, PostChallenges.postTodosMaxTitleDescriptionTooLong400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_TODOS_TOO_LONG_PAYLOAD_SIZE, PostChallenges.postTodosPayloadTooLong400(challengeOrder++), postCreateChallenges);
storeChallengeAs(CHALLENGE.POST_TODOS_INVALID_EXTRA_FIELD, PostChallenges.postTodosInvalidExtraField400(challengeOrder++), postCreateChallenges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void canPostTodosWithMaxTitleAndDescriptionLengths() {
"{\"title\":\"" + stringOfLength(50) + "\",\"description\":\"" + stringOfLength(200) + "\"}");

Assertions.assertEquals(201, response.statusCode);
Assertions.assertTrue(challenger.statusOfChallenge(CHALLENGE.POST_MAX_OUT_TITILE_DESCRIPTION_LENGTH));
Assertions.assertTrue(challenger.statusOfChallenge(CHALLENGE.POST_MAX_OUT_TITLE_DESCRIPTION_LENGTH));
}
@Test
public void canPostTodosFailPayloadLenValidationPass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ChallengeStatus {
public Boolean OVERRIDE_DELETE_HEARTBEAT_405;
public Boolean POST_SECRET_NOTE_BEARER_200;
public Boolean GET_RESTORE_EXISTING_CHALLENGER;
public Boolean GET_RESTORABLE_TODOS;
public Boolean GET_ACCEPT_XML;
public Boolean POST_RESTORE_EXISTING_CHALLENGER;
public Boolean POST_TODOS_TOO_LONG_PAYLOAD_SIZE;
Expand Down Expand Up @@ -58,6 +59,6 @@ public class ChallengeStatus {
public Boolean POST_SECRET_NOTE_403;
public Boolean CREATE_SECRET_TOKEN_401;
public Boolean GET_SECRET_NOTE_401;
public Boolean POST_MAX_OUT_TITILE_DESCRIPTION_LENGTH;
public Boolean POST_MAX_OUT_TITLE_DESCRIPTION_LENGTH;
public Boolean PUT_TODOS_FULL_200;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.co.compendiumdev.challenger.restassured._13_restore_session_challenges;

import com.google.gson.Gson;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import uk.co.compendiumdev.challenger.payloads.Challenger;
import uk.co.compendiumdev.challenger.restassured.api.ChallengesStatus;
import uk.co.compendiumdev.challenger.restassured.api.RestAssuredBaseTest;

public class C034GetChallengerSessionForRestoringTest extends RestAssuredBaseTest {

@Test
public void canGetChallengerSession(){

Assertions.assertNotNull(xChallenger);
Assertions.assertTrue(xChallenger.length()>5);

Response cResponse = RestAssured.
given().
header("X-CHALLENGER", xChallenger).
accept("application/json").
get(apiPath("/challenger/" + xChallenger)).
then().
statusCode(200).
contentType(ContentType.JSON).and().extract().response();

Challenger challengerResponse = new Gson().fromJson(cResponse.body().asString(), Challenger.class);

Assertions.assertTrue(challengerResponse.challengeStatus.GET_RESTORABLE_CHALLENGER_PROGRESS_STATUS);

ChallengesStatus statuses = new ChallengesStatus();
statuses.get();
Assertions.assertTrue(statuses.getChallengeNamed("GET /challenger/guid (existing X-CHALLENGER)").status,
"challenge not passed");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package uk.co.compendiumdev.challenger.restassured._13_restore_session_challenges;

import com.google.gson.Gson;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import uk.co.compendiumdev.challenger.payloads.Challenger;
import uk.co.compendiumdev.challenger.payloads.Todos;
import uk.co.compendiumdev.challenger.restassured.api.ChallengesStatus;
import uk.co.compendiumdev.challenger.restassured.api.RestAssuredBaseTest;

public class C037GetTodosDatabaseForRestoringTest extends RestAssuredBaseTest {

@Test
public void canGetTodosForChallengerSession(){

Assertions.assertNotNull(xChallenger);
Assertions.assertTrue(xChallenger.length()>5);

Response todoResponse = RestAssured.
given().
header("X-CHALLENGER", xChallenger).
accept("application/json").
get(apiPath("/challenger/database/" + xChallenger)).
then().
statusCode(200).
contentType(ContentType.JSON).and().extract().response();

Todos todosResponse = new Gson().fromJson(todoResponse.body().asString(), Todos.class);
Assertions.assertFalse(todosResponse.todos.isEmpty());


Response cResponse = RestAssured.
given().
header("X-CHALLENGER", xChallenger).
accept("application/json").
get(apiPath("/challenger/" + xChallenger)).
then().
statusCode(200).
contentType(ContentType.JSON).and().extract().response();

Challenger challengerResponse = new Gson().fromJson(cResponse.body().asString(), Challenger.class);
Assertions.assertTrue(challengerResponse.challengeStatus.GET_RESTORABLE_TODOS);

ChallengesStatus statuses = new ChallengesStatus();
statuses.get();
Assertions.assertTrue(statuses.getChallengeNamed("GET /challenger/database/guid (200)").status,
"challenge not passed");

}
}

0 comments on commit 7a778a2

Please sign in to comment.