Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Dec 30, 2024
1 parent 61a66a3 commit dff3cb2
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ create function merlin.external_source_pdg_ack_update()
returns trigger
language plpgsql as $$
begin
update merlin.plan_derivation_group set plan_derivation_group.acknowledged = false
update merlin.plan_derivation_group set acknowledged = false
where plan_derivation_group.derivation_group_name = NEW.derivation_group_name;
return new;
end;
Expand Down
113 changes: 103 additions & 10 deletions e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ void uploadExternalSourceEventTypes() throws IOException {
},
"code": {
"type": "string"
},
"optional": {
"type": "string"
}
}
}
Expand All @@ -66,6 +69,9 @@ void uploadExternalSourceEventTypes() throws IOException {
},
"operator": {
"type": "string"
},
"optional": {
"type": "string"
}
},
"required": ["version", "operator"]
Expand Down Expand Up @@ -139,7 +145,7 @@ void correctSourceAndEventAttributes() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

try (final var gateway = new GatewayRequests(playwright)) {
Expand Down Expand Up @@ -182,7 +188,7 @@ void sourceMissingAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
Expand Down Expand Up @@ -225,7 +231,7 @@ void sourceExtraAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
Expand Down Expand Up @@ -268,14 +274,57 @@ void sourceWrongTypeAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource));
assertTrue(ex.getMessage().contains("should be number"));
}

// test that optional attributes (listed in schema, but not marked as required) are okay
@Test
void sourceOptionalAttribute() throws IOException {
final String events = """
[
{
"attributes": {
"projectUser": "UserA",
"code": "A"
},
"duration": "01:00:00",
"event_type_name": "TestEventType",
"key": "Event_01",
"start_time": "2024-01-21T01:00:00+00:00"
}
]
""";

// includes optional type
final String source = """
{
"attributes": { "version": 1, "operator": "alpha", "optional": "bear" },
"derivation_group_name": "TestDerivationGroup",
"period": {
"start_time": "2024-01-21T00:00:00+00:00",
"end_time": "2024-01-28T00:00:00+00:00"
},
"key": "TestExternalSourceKey",
"source_type_name": "TestSourceType",
"valid_at": "2024-01-19T00:00:00+00:00"
}
""";

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("events", events)
.build();

try (final var gateway = new GatewayRequests(playwright)) {
gateway.uploadExternalSource(externalSource);
}
}

// test that an event fails missing an attribute
@Test
void eventMissingAttribute() throws IOException {
Expand All @@ -296,7 +345,7 @@ void eventMissingAttribute() throws IOException {

final String source = """
{
"attributes": { "version": "string", "operator": "alpha" },
"attributes": { "version": 1, "operator": "alpha" },
"derivation_group_name": "TestDerivationGroup",
"period": {
"start_time": "2024-01-21T00:00:00+00:00",
Expand All @@ -310,7 +359,7 @@ void eventMissingAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
Expand Down Expand Up @@ -340,7 +389,7 @@ void eventExtraAttribute() throws IOException {

final String source = """
{
"attributes": { "version": "string", "operator": "alpha" },
"attributes": { "version": 1, "operator": "alpha" },
"derivation_group_name": "TestDerivationGroup",
"period": {
"start_time": "2024-01-21T00:00:00+00:00",
Expand All @@ -354,7 +403,7 @@ void eventExtraAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
Expand Down Expand Up @@ -383,7 +432,7 @@ void eventWrongTypeAttribute() throws IOException {

final String source = """
{
"attributes": { "version": "string", "operator": "alpha" },
"attributes": { "version": 1, "operator": "alpha" },
"derivation_group_name": "TestDerivationGroup",
"period": {
"start_time": "2024-01-21T00:00:00+00:00",
Expand All @@ -397,11 +446,55 @@ void eventWrongTypeAttribute() throws IOException {

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("external_events", events)
.add("events", events)
.build();

final var gateway = new GatewayRequests(playwright);
final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource));
assertTrue(ex.getMessage().contains("should be string"));
}

// test that optional attributes (listed in schema, but not marked as required) are okay
@Test
void eventOptionalAttribute() throws IOException {
final String events = """
[
{
"attributes": {
"projectUser": "UserA",
"code": "A",
"optional": "optionalArg"
},
"duration": "01:00:00",
"event_type_name": "TestEventType",
"key": "Event_01",
"start_time": "2024-01-21T01:00:00+00:00"
}
]
""";

// includes optional type
final String source = """
{
"attributes": { "version": 1, "operator": "alpha", "optional": "optionalArg" },
"derivation_group_name": "TestDerivationGroup",
"period": {
"start_time": "2024-01-21T00:00:00+00:00",
"end_time": "2024-01-28T00:00:00+00:00"
},
"key": "TestExternalSourceKey",
"source_type_name": "TestSourceType",
"valid_at": "2024-01-19T00:00:00+00:00"
}
""";

final JsonObject externalSource = Json.createObjectBuilder()
.add("source", source)
.add("events", events)
.build();

try (final var gateway = new GatewayRequests(playwright)) {
gateway.uploadExternalSource(externalSource);
}
}
}

0 comments on commit dff3cb2

Please sign in to comment.