-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check that a required field that is allowed to be null pa…
…sses validation (close #621)
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": { | ||
|
@@ -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": {}}""" | ||
|
||
|
@@ -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 { | ||
|