Skip to content

Commit

Permalink
Initial testing for crop spec metadata; CropSpec and Crop fields seem…
Browse files Browse the repository at this point in the history
… to handle None inputs to metadata differently!

Not sure if this is intentional.
  • Loading branch information
tonytw1 committed Nov 29, 2024
1 parent 32e4b11 commit 14fa02b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cropper/test/lib/CropSpecMetadataTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package lib

import com.gu.mediaservice.model._
import org.joda.time.DateTime
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

class CropSpecMetadataTest extends AnyFunSpec with Matchers with CropSpecMetadata {

private val cropSpec = CropSpec(
uri = "/test",
bounds = Bounds(1, 2, 3, 4), aspectRatio = Some("16:9"), `type` = ExportType.default
)
private val crop = Crop(
id = Some("123"),
specification = cropSpec,
author = Some("Tony McCrae"),
date = Some(DateTime.now),
master = None,
assets = List.empty,
)
private val dimensions = Dimensions(640, 480)

describe("metadata for crop spec") {
it("should serialize crop spec to key value pairs") {
val metadata = metadataForCrop(crop, dimensions)

metadata("width") shouldBe "640"
metadata("height") shouldBe "480"
metadata.get("aspect-ratio") shouldBe Some("16:9")
metadata.get("author") shouldBe Some("Tony McCrae")
}

it("should handle empty optional fields") {
val withEmptyField = cropSpec.copy(aspectRatio = None)

val metadata = metadataForCrop(crop.copy(specification = withEmptyField, author = None), dimensions)

metadata.get("aspect-ratio") shouldBe None
metadata.get("author") shouldBe Some("None") // TODO this does not look intentional!
}

it("should round trip metadata back to crop spec") {
val metadata = metadataForCrop(crop, dimensions)

val roundTripped = cropSpecFromMetadata(metadata)

roundTripped shouldBe Some(cropSpec)
}
}

}

0 comments on commit 14fa02b

Please sign in to comment.