Skip to content

Commit

Permalink
Add test to check that a required field that is allowed to be null pa…
Browse files Browse the repository at this point in the history
…sses validation (close #621)
  • Loading branch information
dilyand authored and istreeter committed Jun 10, 2022
1 parent 03007f8 commit c925598
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class IgluUtilsSpec extends Specification with ValidatedMatchers {
"jsonschema",
SchemaVer.Full(1, 0, 0)
)
val clientSessionSchema =
SchemaKey(
"com.snowplowanalytics.snowplow",
"client_session",
"jsonschema",
SchemaVer.Full(1, 0, 1)
)
val emailSent1 = s"""{
"schema": "${emailSentSchema.toSchemaUri}",
"data": {
Expand All @@ -85,6 +92,17 @@ class IgluUtilsSpec extends Specification with ValidatedMatchers {
"emailAddress": "[email protected]"
}
}"""
val clientSession = s"""{
"schema": "${clientSessionSchema.toSchemaUri}",
"data": {
"sessionIndex": 1,
"storageMechanism": "LOCAL_STORAGE",
"firstEventId": "5c33fccf-6be5-4ce6-afb1-e34026a3ca75",
"sessionId": "21c2a0dd-892d-42d1-b156-3a9d4e147eef",
"previousSessionId": null,
"userId": "20d631b8-7837-49df-a73e-6da73154e6fd"
}
}"""
val noSchema =
"""{"schema":"iglu:com.snowplowanalytics.snowplow/foo/jsonschema/1-0-0", "data": {}}"""

Expand Down Expand Up @@ -314,6 +332,18 @@ class IgluUtilsSpec extends Specification with ValidatedMatchers {
ko(s"[$res] are not 2 SDJs with expected schema [${emailSentSchema.toSchemaUri}]")
}
}

"return the extracted SDJ for an input that has a required property set to null if the schema explicitly allows it" >> {
val input = new EnrichedEvent
input.setContexts(buildInputContexts(List(clientSession)))

IgluUtils.extractAndValidateInputContexts(input, SpecHelpers.client) must beValid.like {
case sdj: List[SelfDescribingData[Json]] if sdj.size == 1 && sdj.forall(_.schema == clientSessionSchema) =>
ok
case _ =>
ko("$.previousSessionId: is missing but it is required")
}
}
}

"validateEnrichmentsContexts" should {
Expand Down

0 comments on commit c925598

Please sign in to comment.