Skip to content

Commit

Permalink
Minor update to the e2e test
Browse files Browse the repository at this point in the history
* We are always returning an object now

* Update error messages.
  • Loading branch information
goetzrrGit committed Nov 20, 2023
1 parent 89eb955 commit 15ee80b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.json.Json;
import javax.json.JsonValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -137,7 +138,10 @@ void constraintsSucceedNoViolations() throws IOException {
hasura.deleteActivity(planId, activityId);
hasura.awaitSimulation(planId);
final var constraintsResults = hasura.checkConstraints(planId);
assertEquals(0, constraintsResults.size());

assertEquals(1, constraintsResults.size());
assertEquals(true, constraintsResults.get(0).success());
assertEquals(0, constraintsResults.get(0).result().violations().size());
}

@Test
Expand Down Expand Up @@ -183,7 +187,7 @@ void constraintCachedNoViolations() throws IOException {
assertEquals(constraintDefinition, cachedRun.constraintDefinition());

// Check results
assertTrue(cachedRun.results().isEmpty());
assertTrue(!cachedRun.results().isEmpty());
}

@Test
Expand Down Expand Up @@ -258,7 +262,7 @@ void runConstraintsOnOldSimulation() throws IOException {

// Expect no violations on the new simulation
final var newConstraintResults = hasura.checkConstraints(planId, newSimDatasetId);
assertEquals(0, newConstraintResults.size());
assertEquals(1, newConstraintResults.size());

// Expect one violation on the old simulation
final var oldConstraintsResponses = hasura.checkConstraints(planId, oldSimDatasetId);
Expand Down Expand Up @@ -460,7 +464,8 @@ void compilationFailsOutdatedSimulationSimDatasetId() throws IOException {
assertEquals(false,constraintRepsonse.success());
assertEquals(1,constraintRepsonse.errors().size());
final ConstraintError error = constraintRepsonse.errors().get(0);
assertEquals("Constraint 'fruit_equal_peel': TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message());
assertEquals("Constraint 'fruit_equal_peel' compilation failed:\n"
+ " TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message());
}

@Test
Expand All @@ -478,7 +483,39 @@ void compilationFailsOutdatedSimulationNoSimDataset() throws IOException {
assertEquals(false,constraintRepsonse.success());
assertEquals(1,constraintRepsonse.errors().size());
final ConstraintError error = constraintRepsonse.errors().get(0);
assertEquals("Constraint 'fruit_equal_peel': TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message());
assertEquals("Constraint 'fruit_equal_peel' compilation failed:\n"
+ " TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message());

}

@Test
@DisplayName("A modified and recompiled constraint that originally compiled successfully.")
void constraintInvalidModification() throws IOException {

hasura.awaitSimulation(planId);
var constraintsResponses = hasura.checkConstraints(planId);

assertEquals(1, constraintsResponses.size());
assertEquals(true, constraintsResponses.get(0).success());

hasura.updateConstraint(
constraintId,
constraintDefinition+"compilation error");

var constraintsErrorResponses = hasura.checkConstraints(planId);

assertEquals(1, constraintsErrorResponses.size());
assertEquals(false, constraintsErrorResponses.get(0).success());
assertEquals(3 , constraintsErrorResponses.get(0).errors().size());

hasura.updateConstraint(
constraintId,
constraintDefinition);
constraintsResponses = hasura.checkConstraints(planId);

assertEquals(1, constraintsResponses.size());
assertEquals(true, constraintsResponses.get(0).success());


}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonString;
import java.util.ArrayList;
import java.util.List;

public record ConstraintRecord(
Expand All @@ -14,7 +15,7 @@ public record ConstraintRecord(
public static ConstraintRecord fromJSON(JsonObject json){
return new ConstraintRecord(
json.getBoolean("success"),
json.getJsonObject("results").isEmpty() ? null : ConstraintResult.fromJSON(json.getJsonObject("results")),
json.getJsonObject("results").isEmpty() ? new ConstraintResult(-1,"","",new ArrayList<>(), new ArrayList<>(),new ArrayList<>()) : ConstraintResult.fromJSON(json.getJsonObject("results")),
json.getJsonArray("errors").getValuesAs(ConstraintError::fromJSON));
}
}

0 comments on commit 15ee80b

Please sign in to comment.