<commit_before>package uk.ac.wellcome.platform.merger.rules.singlepagemiro

import org.scalatest.{Assertion, FunSpec, Matchers}
import uk.ac.wellcome.models.work.generators.WorksGenerators
import uk.ac.wellcome.models.work.internal._

class SierraMiroMergeRuleTest
    extends FunSpec
    with Matchers
    with WorksGenerators {

  describe("merges a single-page Miro work into a Sierra work") {
    val sierraPhysicalItem =
      createIdentifiableItemWith(locations = List(createPhysicalLocation))

    val sierraPhysicalWork = createUnidentifiedSierraWorkWith(
      items = List(sierraPhysicalItem)
    )

    val sierraDigitalItem = createIdentifiableItemWith(
      locations = List(createDigitalLocation)
    )
    val sierraDigitalWork = createUnidentifiedSierraWorkWith(
      items = List(sierraDigitalItem)
    )

    val miroWork = createMiroWork

    describe("order: miroWork, sierraWork") {
      val redirectedWork = getRedirectedWork(sierraPhysicalWork, miroWork)
      val mergedWork = getMergedWork(sierraPhysicalWork, miroWork)

      it("creates a redirect from the Miro work to the Sierra work") {
        redirectedWork shouldBe UnidentifiedRedirectedWork(
          source = miroWork,
          target = sierraPhysicalWork
        )
      }

      it("copies identifiers from the Miro work to the Sierra work") {
        mergedWork.sourceIdentifier shouldBe sierraPhysicalWork.sourceIdentifier
        mergedWork.otherIdentifiers shouldBe sierraPhysicalWork.otherIdentifiers ++ miroWork.identifiers
      }

      it("doesn't copy Sierra identifiers from the Miro work") {
        val miroLibraryReferenceSourceIdentifier = createSourceIdentifierWith(
          identifierType = IdentifierType("miro-library-reference")
        )
        val miroWorkWithExtraIdentifiers = createMiroWorkWith(
          otherIdentifiers = List(
            miroLibraryReferenceSourceIdentifier,
            sierraPhysicalWork.sourceIdentifier,
            createSierraIdentifierSourceIdentifier,
            createSierraSystemSourceIdentifier))

        val mergedWork =
          getMergedWork(sierraPhysicalWork, miroWorkWithExtraIdentifiers)

        mergedWork.otherIdentifiers shouldBe sierraPhysicalWork.otherIdentifiers :+
          miroWorkWithExtraIdentifiers.sourceIdentifier :+
          miroLibraryReferenceSourceIdentifier
      }

      it("copies item locations from the Miro work to a physical Sierra work") {
        mergedWork.items shouldBe List(
          sierraPhysicalItem.copy(
            agent = sierraPhysicalItem.agent.copy(
              locations =
                sierraPhysicalItem.agent.locations ++ miroWork.items.head.agent.locations
            )
          ))
      }

      it("doesn't copy across the Miro location if the Sierra work already has a DigitalLocation") {
        val mergedWork = getMergedWork(sierraDigitalWork, miroWork)

        mergedWork.items shouldBe sierraDigitalWork.items
      }
    }

    describe("order: sierraWork, miroWork (order doesn't matter)") {
      val redirectedWork = getRedirectedWork(miroWork, sierraPhysicalWork)<commit_msg>Add a failing test that we keep the Miro location<commit_after>package uk.ac.wellcome.platform.merger.rules.singlepagemiro

import org.scalatest.{Assertion, FunSpec, Matchers}
import uk.ac.wellcome.models.work.generators.WorksGenerators
import uk.ac.wellcome.models.work.internal._

class SierraMiroMergeRuleTest
    extends FunSpec
    with Matchers
    with WorksGenerators {

  describe("merges a single-page Miro work into a Sierra work") {
    val sierraPhysicalItem =
      createIdentifiableItemWith(locations = List(createPhysicalLocation))

    val sierraPhysicalWork = createUnidentifiedSierraWorkWith(
      items = List(sierraPhysicalItem)
    )

    val sierraDigitalItem = createIdentifiableItemWith(
      locations = List(createDigitalLocation)
    )
    val sierraDigitalWork = createUnidentifiedSierraWorkWith(
      items = List(sierraDigitalItem)
    )

    val miroWork = createMiroWork

    describe("order: miroWork, sierraWork") {
      val redirectedWork = getRedirectedWork(sierraPhysicalWork, miroWork)
      val mergedWork = getMergedWork(sierraPhysicalWork, miroWork)

      it("creates a redirect from the Miro work to the Sierra work") {
        redirectedWork shouldBe UnidentifiedRedirectedWork(
          source = miroWork,
          target = sierraPhysicalWork
        )
      }

      it("copies identifiers from the Miro work to the Sierra work") {
        mergedWork.sourceIdentifier shouldBe sierraPhysicalWork.sourceIdentifier
        mergedWork.otherIdentifiers shouldBe sierraPhysicalWork.otherIdentifiers ++ miroWork.identifiers
      }

      it("doesn't copy Sierra identifiers from the Miro work") {
        val miroLibraryReferenceSourceIdentifier = createSourceIdentifierWith(
          identifierType = IdentifierType("miro-library-reference")
        )
        val miroWorkWithExtraIdentifiers = createMiroWorkWith(
          otherIdentifiers = List(
            miroLibraryReferenceSourceIdentifier,
            sierraPhysicalWork.sourceIdentifier,
            createSierraIdentifierSourceIdentifier,
            createSierraSystemSourceIdentifier))

        val mergedWork =
          getMergedWork(sierraPhysicalWork, miroWorkWithExtraIdentifiers)

        mergedWork.otherIdentifiers shouldBe sierraPhysicalWork.otherIdentifiers :+
          miroWorkWithExtraIdentifiers.sourceIdentifier :+
          miroLibraryReferenceSourceIdentifier
      }

      it("copies item locations from the Miro work to a physical Sierra work") {
        mergedWork.items shouldBe List(
          sierraPhysicalItem.copy(
            agent = sierraPhysicalItem.agent.copy(
              locations =
                sierraPhysicalItem.agent.locations ++ miroWork.items.head.agent.locations
            )
          ))
      }

      it("copies across the Miro location if the Sierra work already has a DigitalLocation") {
        val mergedWork = getMergedWork(sierraDigitalWork, miroWork)

        mergedWork.items shouldBe List(sierraDigitalItem.copy(
          agent = sierraDigitalItem.agent.copy(
            locations =
              sierraDigitalItem.agent.locations ++ miroWork.items.head.agent.locations
          )
        ))
      }
    }

    describe("order: sierraWork, miroWork (order doesn't matter)") {
      val redirectedWork = getRedirectedWork(miroWork, sierraPhysicalWork)
{'fraction_non_alphanumeric': 0.06167469318005282, 'fraction_numerical': 0.0, 'mean_word_length': 3.1616031027795732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6726711', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1652, 'n_words': 368}