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

import com.twitter.finagle.http.Status
import uk.ac.wellcome.models.Work

class PublishersTest extends ApiWorksTestBase {

  it("includes an empty publishers field if the work has no publishers") { }

  it("includes the publishers field for agent publishers") { }

  it("includes the publishers field with a mixture of agents/organisations") { }
}<commit_msg>Add some tests around the publisher in API results<commit_after>package uk.ac.wellcome.platform.api.works

import com.twitter.finagle.http.Status
import uk.ac.wellcome.models.{Agent, Organisation, Work}

class PublishersTest extends ApiWorksTestBase {

  it("includes an empty publishers field if the work has no publishers") {
    val work = Work(
      canonicalId = Some("zm9q6c6h"),
      sourceIdentifier = sourceIdentifier,
      title = Some("A zoo of zebras doing zumba"),
      publishers = List()
    )

    insertIntoElasticSearch(work)

    eventually {
      server.httpGet(
        path = s"/$apiPrefix/works",
        andExpect = Status.Ok,
        withJsonBody = s"""
          |{
          |  ${resultList(totalResults = 1)},
          |  "results": [
          |    {
          |      "type": "Work",
          |      "id": "${work.id}",
          |      "title": "${work.title.get}",
          |      "creators": [ ],
          |      "subjects": [ ],
          |      "genres": [ ],
          |      "publishers": [ ]
          |    }
          |  ]
          |}
          """.stripMargin
      )
    }
  }

  it("includes the publishers field for agent publishers") {
    val work = Work(
      canonicalId = Some("patkj4ds"),
      sourceIdentifier = sourceIdentifier,
      title = Some("A party of purple panthers in Paris"),
      publishers = List(
        Agent("<NAME>"),
        Agent("<NAME>")
      )
    )

    insertIntoElasticSearch(work)

    eventually {
      server.httpGet(
        path = s"/$apiPrefix/works",
        andExpect = Status.Ok,
        withJsonBody = s"""
          |{
          |  ${resultList(totalResults = 1)},
          |  "results": [
          |    {
          |      "type": "Work",
          |      "id": "${work.id}",
          |      "title": "${work.title.get}",
          |      "creators": [ ],
          |      "subjects": [ ],
          |      "genres": [ ],
          |      "publishers": [
          |        {
          |          "label": "${work.publishers(0).label}",
          |          "type": "Agent"
          |        },
          |        {
          |          "label": "${work.publishers(1).label}",
          |          "type": "Agent"
          |        }
          |      ]
          |    }
          |  ]
          |}
          """.stripMargin
      )
    }
  }

  it("includes the publishers field with a mixture of agents/organisations") {
    val work = Work(
      canonicalId = Some("v9w6cz66"),
      sourceIdentifier = sourceIdentifier,
      title = Some("Vultures vying for victory"),
      publishers = List(
        Agent("<NAME>"),
        Organisation("Verily Volumes")
      )
    )

    insertIntoElasticSearch(work)

    eventually {
      server.httpGet(
        path = s"/$apiPrefix/works",
        andExpect = Status.Ok,
        withJsonBody = s"""
          |{
          |  ${resultList(totalResults = 1)},
          |  "results": [
          |    {
          |      "type": "Work",
          |      "id": "${work.id}",
          |      "title": "${work.title.get}",
          |      "creators": [ ],
          |      "subjects": [ ],
          |      "genres": [ ],
          |      "publishers": [
          |        {
          |          "label": "${work.publishers(0).label}",
          |          "type": "Agent"
          |        },
          |        {
          |          "label": "${work.publishers(1).label}",
          |          "type": "Organisation"
          |        }
          |      ]
          |    }
          |  ]
          |}
          """.stripMargin
      )
    }
  }
}
{'fraction_non_alphanumeric': 0.14346096469418199, 'fraction_numerical': 0.0037294878170064643, 'mean_word_length': 1.4249547920433996, 'pattern_counts': {'":': 32, '<': 6, '<?xml version=': 0, '>': 6, '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': '5329689', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1145, 'n_words': 221}