<commit_before>package uk.ac.wellcome.platform.api.models

import org.scalatest.{FunSpec, Matchers}
import uk.ac.wellcome.models._
import uk.ac.wellcome.platform.api.utils.ApiJsonUtil

class DisplayItemTest extends FunSpec with Matchers {

  val location: Location = {
    val thumbnailUrl = Some("https://iiif.example.org/V0000001/default.jpg")
    val locationType = "thumbnail-image"

    Location(
      locationType = locationType,
      url = thumbnailUrl,
      license = License_CCBY
    )
  }

  val identifier: SourceIdentifier = SourceIdentifier(
    identifierScheme = IdentifierSchemes.miroImageNumber,
    value = "value"
  )

  it("should read an Item as a DisplayItem correctly") {
    val item = Item(
      canonicalId = Some("foo"),
      sourceIdentifier = identifier,
      identifiers = List(identifier),
      locations = List(location)
    )

    val displayItem = DisplayItem(
      item = item,
      includesIdentifiers = true
    )

    displayItem.id shouldBe item.id
    displayItem.locations shouldBe List(DisplayLocation(location))
    displayItem.identifiers shouldBe Some(List(DisplayIdentifier(identifier)))
    displayItem.ontologyType shouldBe "Item"
  }

  it("correctly parses an Item without any identifiers") {
    val item =
      ApiJsonUtil.fromJson[Item]("""
        {
          "canonicalId": "b71876a",
          "sourceIdentifier": {
            "identifierScheme": "miro-image-number",
            "value": "B718760"
          },
          "locations": [],
          "type": "item"
        }
      """).get

    val displayItem = DisplayItem(
      item = item,
      includesIdentifiers = true
    )

    displayItem.identifiers shouldBe Some(List())
  }

  it("correctly parses an Item without any locations") {
    val item =
      ApiJsonUtil.fromJson[Item]("""
        {
          "canonicalId": "mr953zsh",
          "sourceIdentifier": {
            "identifierScheme": "miro-image-number",
            "value": "M9530000"
          },
          "identifiers": [],<commit_msg>Expunge one other use of ApiJsonUtil<commit_after>package uk.ac.wellcome.platform.api.models

import org.scalatest.{FunSpec, Matchers}
import uk.ac.wellcome.models._
import uk.ac.wellcome.utils.JsonUtil._

class DisplayItemTest extends FunSpec with Matchers {

  val location: Location = {
    val thumbnailUrl = Some("https://iiif.example.org/V0000001/default.jpg")
    val locationType = "thumbnail-image"

    Location(
      locationType = locationType,
      url = thumbnailUrl,
      license = License_CCBY
    )
  }

  val identifier: SourceIdentifier = SourceIdentifier(
    identifierScheme = IdentifierSchemes.miroImageNumber,
    value = "value"
  )

  it("should read an Item as a DisplayItem correctly") {
    val item = Item(
      canonicalId = Some("foo"),
      sourceIdentifier = identifier,
      identifiers = List(identifier),
      locations = List(location)
    )

    val displayItem = DisplayItem(
      item = item,
      includesIdentifiers = true
    )

    displayItem.id shouldBe item.id
    displayItem.locations shouldBe List(DisplayLocation(location))
    displayItem.identifiers shouldBe Some(List(DisplayIdentifier(identifier)))
    displayItem.ontologyType shouldBe "Item"
  }

  it("correctly parses an Item without any identifiers") {
    val item = fromJson[Item]("""
        {
          "canonicalId": "b71876a",
          "sourceIdentifier": {
            "identifierScheme": "miro-image-number",
            "value": "B718760"
          },
          "locations": [],
          "type": "item"
        }
      """).get

    val displayItem = DisplayItem(
      item = item,
      includesIdentifiers = true
    )

    displayItem.identifiers shouldBe Some(List())
  }

  it("correctly parses an Item without any locations") {
    val item = fromJson[Item]("""
        {
          "canonicalId": "mr953zsh",
          "sourceIdentifier": {
            "identifierScheme": "miro-image-number",
            "value": "M9530000"
          },
          "identifiers": [],
{'fraction_non_alphanumeric': 0.10923953430765419, 'fraction_numerical': 0.013871686896210057, 'mean_word_length': 2.6345634563456346, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4337157', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1135, 'n_words': 257}