Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spenes committed Apr 1, 2024
1 parent 66751a5 commit d1eb35e
Show file tree
Hide file tree
Showing 6 changed files with 795 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ object FailureEntity {
case FailureDetails.SchemaViolation.IgluError(schemaKey, ClientError.ValidationError(ValidatorError.InvalidSchema(e), _)) =>
val errors = e.toList.map { r =>
Json.obj(
"message" := s"Invalid schema: $schemaKey - ${r.message}",
"message" := s"Invalid schema: ${schemaKey.toSchemaUri} - ${r.message}",
"source" := v.source,
"path" := r.path
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ object SpecHelpers extends CatsEffect {
.flatMap(SelfDescribingData.parse[Json])
.leftMap(err => s"Can't parse Json [$rawJson] as as SelfDescribingData, error: [$err]")

def listContextsSchemas(rawContexts: String): List[SchemaKey] =
def listContexts(rawContexts: String): List[SelfDescribingData[Json]] =
jsonStringToSDJ(rawContexts)
.map(_.data.asArray.get.toList)
.flatMap(contexts => contexts.traverse(c => SelfDescribingData.parse[Json](c).map(_.schema))) match {
.flatMap(contexts => contexts.traverse(c => SelfDescribingData.parse[Json](c))) match {
case Left(err) =>
throw new IllegalArgumentException(s"Couldn't list contexts schemas. Error: [$err]")
case Right(schemas) => schemas
case Right(sdjs) => sdjs
}

def listContextsSchemas(rawContexts: String): List[SchemaKey] = listContexts(rawContexts).map(_.schema)

def getUnstructSchema(rawUnstruct: String): SchemaKey =
jsonStringToSDJ(rawUnstruct)
.map(_.data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-present Snowplow Analytics Ltd.
* All rights reserved.
*
* This software is made available by Snowplow Analytics, Ltd.,
* under the terms of the Snowplow Limited Use License Agreement, Version 1.0
* located at https://docs.snowplow.io/limited-use-license-1.0
* BY INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY PORTION
* OF THE SOFTWARE, YOU AGREE TO THE TERMS OF SUCH LICENSE AGREEMENT.
*/
package com.snowplowanalytics.snowplow.enrich.common.enrichments

import cats.data.NonEmptyList
import cats.syntax.option._

import io.circe.Json
import io.circe.syntax._

import com.snowplowanalytics.iglu.client.ClientError.ValidationError
import com.snowplowanalytics.iglu.client.validator.{ValidatorError, ValidatorReport}
import com.snowplowanalytics.snowplow.badrows.FailureDetails

import org.specs2.mutable.Specification

class AtomicFieldsSpec extends Specification {

"errorsToSchemaViolation" should {
"convert ValidatorReports to SchemaViolation correctly" >> {
val vrList = NonEmptyList(
ValidatorReport(message = "testMessage", path = "testPath1".some, targets = List("t1, t2"), keyword = "testKeyword1".some),
List(
ValidatorReport(message = "testMessage", path = None, targets = List.empty, keyword = "testKeyword2".some),
ValidatorReport(message = "testMessage", path = "testPath3".some, targets = List("t1", "t2"), keyword = None),
ValidatorReport(message = "testMessage", path = "testPath4".some, targets = List.empty, keyword = "testKeyword4".some)
)
)
val expected = FailureEntity.SchemaViolation(
schemaViolation = FailureDetails.SchemaViolation.IgluError(
schemaKey = AtomicFields.atomicSchema,
error = ValidationError(ValidatorError.InvalidData(vrList), None)
),
source = "atomic_field",
data = Json.obj(
"testPath1" := "testKeyword1",
"testPath3" := Json.Null,
"testPath4" := "testKeyword4"
)
)
val result = AtomicFields.errorsToSchemaViolation(vrList)
result must beEqualTo(expected)
}
}
}
Loading

0 comments on commit d1eb35e

Please sign in to comment.