From 4fbbbb0ef781f339cc2ea92acf9d18b361409877 Mon Sep 17 00:00:00 2001 From: Paul Butcher Date: Tue, 11 Jul 2023 14:56:35 +0100 Subject: [PATCH] Remove AnyFunSpec from base trait (#673) * remove AnyFunSpec from base class * remove AnyFunSpec from base class * commit missed file --- .../scala/weco/api/search/ApiErrorsTest.scala | 3 +- .../api/search/ApiSearchTemplatesTest.scala | 3 +- .../scala/weco/api/search/ApiTestBase.scala | 12 +- .../weco/api/search/fixtures/ApiFixture.scala | 7 +- .../api/search/images/ApiImagesTestBase.scala | 3 +- .../images/ImagesAggregationsTest.scala | 4 +- .../api/search/images/ImagesErrorsTest.scala | 4 +- .../ImagesFilteredAggregationsTest.scala | 3 +- .../api/search/images/ImagesFiltersTest.scala | 3 +- .../search/images/ImagesIncludesTest.scala | 4 +- .../search/images/ImagesSimilarityTest.scala | 3 +- .../weco/api/search/images/ImagesTest.scala | 15 +- .../api/search/works/ApiWorksTestBase.scala | 46 ++- .../search/works/WorksAggregationsTest.scala | 4 +- .../api/search/works/WorksErrorsTest.scala | 3 +- .../works/WorksFilteredAggregationsTest.scala | 3 +- .../api/search/works/WorksFiltersTest.scala | 365 +----------------- .../api/search/works/WorksIncludesTest.scala | 4 +- .../api/search/works/WorksRedirectsTest.scala | 4 +- .../weco/api/search/works/WorksTest.scala | 3 +- .../api/search/works/WorksTestDeleted.scala | 4 +- .../api/search/works/WorksTestInvisible.scala | 4 +- 22 files changed, 111 insertions(+), 393 deletions(-) diff --git a/search/src/test/scala/weco/api/search/ApiErrorsTest.scala b/search/src/test/scala/weco/api/search/ApiErrorsTest.scala index 8f94c4e12a..97e82eae5c 100644 --- a/search/src/test/scala/weco/api/search/ApiErrorsTest.scala +++ b/search/src/test/scala/weco/api/search/ApiErrorsTest.scala @@ -1,8 +1,9 @@ package weco.api.search +import org.scalatest.funspec.AnyFunSpec import weco.api.search.works.ApiWorksTestBase -class ApiErrorsTest extends ApiWorksTestBase { +class ApiErrorsTest extends AnyFunSpec with ApiWorksTestBase { it("returns a Not Found error if you try to get an unrecognised path") { withApi { route => assertNotFound(route)( diff --git a/search/src/test/scala/weco/api/search/ApiSearchTemplatesTest.scala b/search/src/test/scala/weco/api/search/ApiSearchTemplatesTest.scala index d6e60c10da..4e32bdd6b4 100644 --- a/search/src/test/scala/weco/api/search/ApiSearchTemplatesTest.scala +++ b/search/src/test/scala/weco/api/search/ApiSearchTemplatesTest.scala @@ -2,10 +2,11 @@ package weco.api.search import akka.http.scaladsl.model.ContentTypes import io.circe.Json +import org.scalatest.funspec.AnyFunSpec import org.scalatest.matchers.should.Matchers import weco.api.search.works.ApiWorksTestBase -class ApiSearchTemplatesTest extends ApiWorksTestBase with Matchers { +class ApiSearchTemplatesTest extends AnyFunSpec with ApiWorksTestBase with Matchers { it("renders a list of available search templates") { checkJson { json => json.isObject shouldBe true diff --git a/search/src/test/scala/weco/api/search/ApiTestBase.scala b/search/src/test/scala/weco/api/search/ApiTestBase.scala index 3f8c288a65..ba9ef8b5e3 100644 --- a/search/src/test/scala/weco/api/search/ApiTestBase.scala +++ b/search/src/test/scala/weco/api/search/ApiTestBase.scala @@ -1,10 +1,13 @@ package weco.api.search import akka.http.scaladsl.server.Route -import org.scalatest.Assertion +import org.scalatest.{Assertion, Suite} import weco.api.search.fixtures.ApiFixture +import scala.math + trait ApiTestBase extends ApiFixture { + this: Suite => val publicRootUri = "https://api-testing.local/catalogue/v2" // This is the path relative to which requests are made on the host, @@ -41,6 +44,13 @@ trait ApiTestBase extends ApiFixture { "description": "$description" }""" + def resultListWithCalculatedPageCount(totalResults: Int, pageSize: Int = 10): String = + resultList( + pageSize, + totalPages = math.ceil(totalResults.toDouble / pageSize).toInt, + totalResults = totalResults + ) + def resultList( pageSize: Int = 10, totalPages: Int = 1, diff --git a/search/src/test/scala/weco/api/search/fixtures/ApiFixture.scala b/search/src/test/scala/weco/api/search/fixtures/ApiFixture.scala index 12962062a9..e4cd954f74 100644 --- a/search/src/test/scala/weco/api/search/fixtures/ApiFixture.scala +++ b/search/src/test/scala/weco/api/search/fixtures/ApiFixture.scala @@ -7,14 +7,13 @@ import akka.http.scaladsl.server.Route import com.sksamuel.elastic4s.Index import io.circe.parser.parse import io.circe.Json -import org.scalatest.Assertion -import org.scalatest.funspec.AnyFunSpec +import org.scalatest.{Assertion, Suite} import weco.api.search.SearchApi import weco.fixtures.TestWith import weco.api.search.models.{ApiConfig, ElasticConfig, QueryConfig} -trait ApiFixture extends AnyFunSpec with ScalatestRouteTest with IndexFixtures { - +trait ApiFixture extends ScalatestRouteTest with IndexFixtures { + this: Suite => val Status = akka.http.scaladsl.model.StatusCodes val publicRootUri: String diff --git a/search/src/test/scala/weco/api/search/images/ApiImagesTestBase.scala b/search/src/test/scala/weco/api/search/images/ApiImagesTestBase.scala index 41333ea4ba..0cb274fce5 100644 --- a/search/src/test/scala/weco/api/search/images/ApiImagesTestBase.scala +++ b/search/src/test/scala/weco/api/search/images/ApiImagesTestBase.scala @@ -1,5 +1,6 @@ package weco.api.search.images +import org.scalatest.Suite import weco.api.search.ApiTestBase import weco.api.search.fixtures.TestDocumentFixtures import weco.api.search.json.CatalogueJsonUtil @@ -9,7 +10,7 @@ trait ApiImagesTestBase extends ApiTestBase with CatalogueJsonUtil with TestDocumentFixtures { - + this: Suite => def imagesListResponse( ids: Seq[String], strictOrdering: Boolean = false diff --git a/search/src/test/scala/weco/api/search/images/ImagesAggregationsTest.scala b/search/src/test/scala/weco/api/search/images/ImagesAggregationsTest.scala index b62cd9717c..087c0d04a1 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesAggregationsTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesAggregationsTest.scala @@ -1,8 +1,10 @@ package weco.api.search.images +import org.scalatest.funspec.AnyFunSpec import weco.api.search.models.request.SingleImageIncludes -class ImagesAggregationsTest extends ApiImagesTestBase { +class ImagesAggregationsTest extends AnyFunSpec +with ApiImagesTestBase { it("aggregates by license") { val images = (0 to 6).map(i => s"images.different-licenses.$i") val displayImages = images diff --git a/search/src/test/scala/weco/api/search/images/ImagesErrorsTest.scala b/search/src/test/scala/weco/api/search/images/ImagesErrorsTest.scala index 4950b73ba5..3f3560bfb8 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesErrorsTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesErrorsTest.scala @@ -1,10 +1,12 @@ package weco.api.search.images +import org.scalatest.funspec.AnyFunSpec import org.scalatest.prop.TableDrivenPropertyChecks import weco.api.search.models.ElasticConfig class ImagesErrorsTest - extends ApiImagesTestBase + extends AnyFunSpec + with ApiImagesTestBase with TableDrivenPropertyChecks { describe("returns a 404 for missing resources") { it("looking up an image that doesn't exist") { diff --git a/search/src/test/scala/weco/api/search/images/ImagesFilteredAggregationsTest.scala b/search/src/test/scala/weco/api/search/images/ImagesFilteredAggregationsTest.scala index b209802222..ed65208778 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesFilteredAggregationsTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesFilteredAggregationsTest.scala @@ -1,8 +1,9 @@ package weco.api.search.images +import org.scalatest.funspec.AnyFunSpec import weco.api.search.models.request.SingleImageIncludes -class ImagesFilteredAggregationsTest extends ApiImagesTestBase { +class ImagesFilteredAggregationsTest extends AnyFunSpec with ApiImagesTestBase { it("filters and aggregates by license") { withImagesApi { case (imagesIndex, routes) => diff --git a/search/src/test/scala/weco/api/search/images/ImagesFiltersTest.scala b/search/src/test/scala/weco/api/search/images/ImagesFiltersTest.scala index 2112bfdae0..39f7335c41 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesFiltersTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesFiltersTest.scala @@ -2,9 +2,10 @@ package weco.api.search.images import akka.http.scaladsl.server.Route import org.scalatest.Assertion +import org.scalatest.funspec.AnyFunSpec import weco.fixtures.TestWith -class ImagesFiltersTest extends ApiImagesTestBase { +class ImagesFiltersTest extends AnyFunSpec with ApiImagesTestBase { describe("filtering images by license") { it("filters by license") { withImagesApi { diff --git a/search/src/test/scala/weco/api/search/images/ImagesIncludesTest.scala b/search/src/test/scala/weco/api/search/images/ImagesIncludesTest.scala index 5254a1f367..3c2cd29f6a 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesIncludesTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesIncludesTest.scala @@ -1,6 +1,8 @@ package weco.api.search.images -class ImagesIncludesTest extends ApiImagesTestBase { +import org.scalatest.funspec.AnyFunSpec + +class ImagesIncludesTest extends AnyFunSpec with ApiImagesTestBase { describe("images includes") { it( "includes the source contributors on results from the list endpoint if we pass ?include=source.contributors" diff --git a/search/src/test/scala/weco/api/search/images/ImagesSimilarityTest.scala b/search/src/test/scala/weco/api/search/images/ImagesSimilarityTest.scala index 96a1e8c364..af8e3cc87a 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesSimilarityTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesSimilarityTest.scala @@ -1,8 +1,9 @@ package weco.api.search.images import io.circe.Json +import org.scalatest.funspec.AnyFunSpec -class ImagesSimilarityTest extends ApiImagesTestBase { +class ImagesSimilarityTest extends AnyFunSpec with ApiImagesTestBase { /** * These tests treat the simple presence of the requested property as a proxy diff --git a/search/src/test/scala/weco/api/search/images/ImagesTest.scala b/search/src/test/scala/weco/api/search/images/ImagesTest.scala index f73c064d21..09a517dd83 100644 --- a/search/src/test/scala/weco/api/search/images/ImagesTest.scala +++ b/search/src/test/scala/weco/api/search/images/ImagesTest.scala @@ -1,8 +1,9 @@ package weco.api.search.images +import org.scalatest.funspec.AnyFunSpec import weco.api.search.models.request.SingleImageIncludes -class ImagesTest extends ApiImagesTestBase { +class ImagesTest extends AnyFunSpec with ApiImagesTestBase { it("returns a list of images") { withImagesApi { case (imagesIndex, routes) => @@ -112,11 +113,11 @@ class ImagesTest extends ApiImagesTestBase { assertJsonResponse( routes, - path = - s"$rootPath/images?sort=source.production.dates" + path = s"$rootPath/images?sort=source.production.dates" ) { Status.OK -> imagesListResponse( - ids = productionImages, strictOrdering = true + ids = productionImages, + strictOrdering = true ) } } @@ -133,7 +134,8 @@ class ImagesTest extends ApiImagesTestBase { s"$rootPath/images?sort=source.production.dates&sortOrder=asc" ) { Status.OK -> imagesListResponse( - ids = productionImages, strictOrdering = true + ids = productionImages, + strictOrdering = true ) } } @@ -150,7 +152,8 @@ class ImagesTest extends ApiImagesTestBase { s"$rootPath/images?sort=source.production.dates&sortOrder=desc" ) { Status.OK -> imagesListResponse( - ids = productionImages.reverse, strictOrdering = true + ids = productionImages.reverse, + strictOrdering = true ) } } diff --git a/search/src/test/scala/weco/api/search/works/ApiWorksTestBase.scala b/search/src/test/scala/weco/api/search/works/ApiWorksTestBase.scala index 248b94b120..1f7a7aed43 100644 --- a/search/src/test/scala/weco/api/search/works/ApiWorksTestBase.scala +++ b/search/src/test/scala/weco/api/search/works/ApiWorksTestBase.scala @@ -1,6 +1,7 @@ package weco.api.search.works import io.circe.Json +import org.scalatest.Suite import weco.api.search.ApiTestBase import weco.api.search.fixtures.TestDocumentFixtures import weco.api.search.json.CatalogueJsonUtil @@ -10,6 +11,7 @@ trait ApiWorksTestBase extends ApiTestBase with CatalogueJsonUtil with TestDocumentFixtures { + this: Suite => def getMinimalDisplayWorks(ids: Seq[String]): Seq[Json] = ids @@ -21,10 +23,19 @@ trait ApiWorksTestBase ids: Seq[String], includes: WorksIncludes = WorksIncludes.none, strictOrdering: Boolean = false + ): String = + s"{${worksList(ids, includes, strictOrdering)}}" + + private def worksList( + ids: Seq[String], + includes: WorksIncludes = WorksIncludes.none, + strictOrdering: Boolean = false ): String = { val works = ids - .map { getVisibleWork } + .map { + getVisibleWork + } .map(_.display.withIncludes(includes)) val sortedWorks = if (strictOrdering) { @@ -32,14 +43,39 @@ trait ApiWorksTestBase } else { works.sortBy(w => getKey(w, "id").get.asString) } - s""" - |{ - | ${resultList(totalResults = ids.size)}, + | ${resultListWithCalculatedPageCount( + totalResults = ids.size + )}, | "results": [ | ${sortedWorks.mkString(",")} | ] - |} """.stripMargin } + + def worksListResponseWithAggs( + ids: Seq[String], + aggs: Map[String, Seq[(Int, String)]] + ) = + s"{${worksList(ids)}, ${aggregations(aggs)}}" + + private def aggregations(aggs: Map[String, Seq[(Int, String)]]): String = { + val aggregationEntries = aggs map { + case (key, buckets) => + val aggregationBuckets = buckets map { + case (count, bucketData) => + s""" + |{ + | "count" : $count, + | "data" : $bucketData, + | "type" : "AggregationBucket" + | } + |""".stripMargin + + } + s""""$key": {"buckets": [${aggregationBuckets.mkString(",")}], "type" : "Aggregation"}""" + } + s""" "aggregations":{${aggregationEntries.mkString(",")}, "type" : "Aggregations"}""" + + } } diff --git a/search/src/test/scala/weco/api/search/works/WorksAggregationsTest.scala b/search/src/test/scala/weco/api/search/works/WorksAggregationsTest.scala index c6d8e99d5b..e26c113a06 100644 --- a/search/src/test/scala/weco/api/search/works/WorksAggregationsTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksAggregationsTest.scala @@ -1,6 +1,8 @@ package weco.api.search.works -class WorksAggregationsTest extends ApiWorksTestBase { +import org.scalatest.funspec.AnyFunSpec + +class WorksAggregationsTest extends AnyFunSpec with ApiWorksTestBase { it("aggregates by format") { withWorksApi { case (worksIndex, routes) => diff --git a/search/src/test/scala/weco/api/search/works/WorksErrorsTest.scala b/search/src/test/scala/weco/api/search/works/WorksErrorsTest.scala index 406c373e76..e8cc480f28 100644 --- a/search/src/test/scala/weco/api/search/works/WorksErrorsTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksErrorsTest.scala @@ -1,11 +1,12 @@ package weco.api.search.works import com.sksamuel.elastic4s.Index +import org.scalatest.funspec.AnyFunSpec import org.scalatest.prop.TableDrivenPropertyChecks import weco.api.search.models.ElasticConfig import weco.elasticsearch.IndexConfig -class WorksErrorsTest extends ApiWorksTestBase with TableDrivenPropertyChecks { +class WorksErrorsTest extends AnyFunSpec with ApiWorksTestBase with TableDrivenPropertyChecks { val includesString = "['identifiers', 'items', 'holdings', 'subjects', 'genres', 'contributors', 'production', 'languages', 'notes', 'formerFrequency', 'designation', 'images', 'parts', 'partOf', 'precededBy', 'succeededBy']" diff --git a/search/src/test/scala/weco/api/search/works/WorksFilteredAggregationsTest.scala b/search/src/test/scala/weco/api/search/works/WorksFilteredAggregationsTest.scala index 357236071b..2c2d48d333 100644 --- a/search/src/test/scala/weco/api/search/works/WorksFilteredAggregationsTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksFilteredAggregationsTest.scala @@ -1,8 +1,9 @@ package weco.api.search.works +import org.scalatest.funspec.AnyFunSpec import weco.api.search.models.request.WorksIncludes -class WorksFilteredAggregationsTest extends ApiWorksTestBase { +class WorksFilteredAggregationsTest extends AnyFunSpec with ApiWorksTestBase { val aggregatedWorks = (0 to 9).map(i => s"works.examples.filtered-aggregations-tests.$i") diff --git a/search/src/test/scala/weco/api/search/works/WorksFiltersTest.scala b/search/src/test/scala/weco/api/search/works/WorksFiltersTest.scala index 4a68d0efdc..264e928054 100644 --- a/search/src/test/scala/weco/api/search/works/WorksFiltersTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksFiltersTest.scala @@ -2,12 +2,14 @@ package weco.api.search.works import akka.http.scaladsl.server.Route import org.scalatest.Assertion +import org.scalatest.funspec.AnyFunSpec import org.scalatest.prop.TableDrivenPropertyChecks import weco.fixtures.TestWith -import java.net.URLEncoder - -class WorksFiltersTest extends ApiWorksTestBase with TableDrivenPropertyChecks { +class WorksFiltersTest + extends AnyFunSpec + with ApiWorksTestBase + with TableDrivenPropertyChecks { it("combines multiple filters") { withWorksApi { @@ -51,104 +53,6 @@ class WorksFiltersTest extends ApiWorksTestBase with TableDrivenPropertyChecks { } } - describe("filtering works by Format") { - it("when listing works") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, worksFormat: _*) - - assertJsonResponse( - routes, - path = s"$rootPath/works?workType=k" - ) { - Status.OK -> worksListResponse( - ids = Seq("works.formats.9.Pictures") - ) - } - } - } - - it("filters by multiple formats") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, worksFormat: _*) - - assertJsonResponse( - routes, - path = s"$rootPath/works?workType=k,d" - ) { - Status.OK -> worksListResponse( - ids = Seq( - "works.formats.4.Journals", - "works.formats.5.Journals", - "works.formats.6.Journals", - "works.formats.9.Pictures" - ) - ) - } - } - } - } - - describe("filtering works by type") { - val works = Seq( - "works.examples.different-work-types.Collection", - "works.examples.different-work-types.Series", - "works.examples.different-work-types.Section" - ) - - it("when listing works") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - assertJsonResponse(routes, path = s"$rootPath/works?type=Collection") { - Status.OK -> worksListResponse( - ids = Seq("works.examples.different-work-types.Collection") - ) - } - } - } - - it("filters by multiple types") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - assertJsonResponse( - routes, - path = s"$rootPath/works?type=Collection,Series" - ) { - Status.OK -> worksListResponse( - ids = Seq( - "works.examples.different-work-types.Collection", - "works.examples.different-work-types.Series" - ) - ) - } - } - } - - it("when searching works") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - assertJsonResponse( - routes, - path = s"$rootPath/works?query=rats&type=Series,Section" - ) { - Status.OK -> worksListResponse( - ids = Seq( - "works.examples.different-work-types.Series", - "works.examples.different-work-types.Section" - ) - ) - } - } - } - } - describe("filtering works by date range") { val productionWorks = Seq( "work-production.1098", @@ -231,58 +135,6 @@ class WorksFiltersTest extends ApiWorksTestBase with TableDrivenPropertyChecks { } } - describe("filtering works by language") { - val languageWorks = Seq( - "works.languages.0.eng", - "works.languages.1.eng", - "works.languages.2.eng", - "works.languages.3.eng+swe", - "works.languages.4.eng+swe+tur", - "works.languages.5.swe", - "works.languages.6.tur" - ) - - it("filters by language") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, languageWorks: _*) - - assertJsonResponse(routes, path = s"$rootPath/works?languages=eng") { - Status.OK -> worksListResponse( - ids = Seq( - "works.languages.0.eng", - "works.languages.1.eng", - "works.languages.2.eng", - "works.languages.3.eng+swe", - "works.languages.4.eng+swe+tur" - ) - ) - } - } - } - - it("filters by multiple comma separated languages") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, languageWorks: _*) - - assertJsonResponse( - routes, - path = s"$rootPath/works?languages=swe,tur" - ) { - Status.OK -> worksListResponse( - ids = Seq( - "works.languages.3.eng+swe", - "works.languages.4.eng+swe+tur", - "works.languages.5.swe", - "works.languages.6.tur" - ) - ) - } - } - } - } - describe("filtering by genre concept ids") { // This work has a single compound Genre. @@ -345,7 +197,6 @@ class WorksFiltersTest extends ApiWorksTestBase with TableDrivenPropertyChecks { ) ) } - } } @@ -366,212 +217,6 @@ class WorksFiltersTest extends ApiWorksTestBase with TableDrivenPropertyChecks { ) ) } - - } - } - } - - describe("filtering works by genre") { - val annualReportsWork = s"works.examples.genre-filters-tests.0" - val pamphletsWork = "works.examples.genre-filters-tests.1" - val psychologyWork = "works.examples.genre-filters-tests.2" - val darwinWork = "works.examples.genre-filters-tests.3" - val mostThingsWork = "works.examples.genre-filters-tests.4" - val nothingWork = "works.examples.genre-filters-tests.5" - - val works = - List( - annualReportsWork, - pamphletsWork, - psychologyWork, - darwinWork, - mostThingsWork, - nothingWork - ) - - val testCases = Table( - ("query", "expectedIds", "clue"), - ("Annual reports.", Seq(annualReportsWork), "single match single genre"), - ( - "Pamphlets.", - Seq(pamphletsWork, mostThingsWork), - "multi match single genre" - ), - ( - "Annual reports.,Pamphlets.", - Seq(annualReportsWork, pamphletsWork, mostThingsWork), - "comma separated" - ), - ( - """Annual reports.,"Psychology, Pathological"""", - Seq(annualReportsWork, psychologyWork, mostThingsWork), - "commas in quotes" - ), - ( - """"Darwin \"Jones\", Charles","Psychology, Pathological",Pamphlets.""", - Seq(darwinWork, psychologyWork, mostThingsWork, pamphletsWork), - "escaped quotes in quotes" - ) - ) - - it("filters by genres as a comma separated list") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - forAll(testCases) { - (query: String, expectedIds: Seq[String], clue: String) => - withClue(clue) { - assertJsonResponse( - routes, - path = - s"$rootPath/works?genres.label=${URLEncoder.encode(query, "UTF-8")}" - ) { - Status.OK -> worksListResponse(expectedIds) - } - } - } - } - } - } - - describe("filtering works") { - val sanitationWork = "works.examples.subject-filters-tests.0" - val londonWork = "works.examples.subject-filters-tests.1" - val psychologyWork = "works.examples.subject-filters-tests.2" - val darwinWork = "works.examples.subject-filters-tests.3" - val mostThingsWork = "works.examples.subject-filters-tests.4" - val nothingWork = "works.examples.subject-filters-tests.5" - - val works = - List( - sanitationWork, - londonWork, - psychologyWork, - darwinWork, - mostThingsWork, - nothingWork - ) - - val testCases = Table( - ("filterName", "query", "expectedIds", "clue"), - ( - "subjects.label", - "Sanitation.", - Seq(sanitationWork), - "single match single subject" - ), - ( - "subjects.label", - "London (England)", - Seq(londonWork, mostThingsWork), - "multi match single subject" - ), - ( - "subjects.label", - "Sanitation.,London (England)", - Seq(sanitationWork, londonWork, mostThingsWork), - "comma separated" - ), - ( - "subjects.label", - """Sanitation.,"Psychology, Pathological"""", - Seq(sanitationWork, psychologyWork, mostThingsWork), - "commas in quotes" - ), - ( - "subjects.label", - """"Darwin \"Jones\", Charles","Psychology, Pathological",London (England)""", - Seq(darwinWork, psychologyWork, londonWork, mostThingsWork), - "escaped quotes in quotes" - ) - ) - - it("filters by subjects") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - forAll(testCases) { - ( - filterName, - query: String, - expectedIds: Seq[String], - clue: String - ) => - withClue(clue) { - assertJsonResponse( - routes, - path = - s"$rootPath/works?$filterName=${URLEncoder.encode(query, "UTF-8")}" - ) { - Status.OK -> worksListResponse(expectedIds) - } - } - } - } - } - } - - describe("filtering works by contributors") { - val patriciaWork = "works.examples.contributor-filters-tests.0" - val karlMarxWork = "works.examples.contributor-filters-tests.1" - val jakePaulWork = "works.examples.contributor-filters-tests.2" - val darwinWork = "works.examples.contributor-filters-tests.3" - val patriciaDarwinWork = "works.examples.contributor-filters-tests.4" - val noContributorsWork = "works.examples.contributor-filters-tests.5" - - val works = List( - patriciaWork, - karlMarxWork, - jakePaulWork, - darwinWork, - patriciaDarwinWork, - noContributorsWork - ) - - val testCases = Table( - ("query", "expectedIds", "clue"), - ("Karl Marx", Seq(karlMarxWork), "single match"), - ( - """"Bath, Patricia"""", - Seq(patriciaWork, patriciaDarwinWork), - "multi match" - ), - ( - "Karl Marx,Jake Paul", - Seq(karlMarxWork, jakePaulWork), - "comma separated" - ), - ( - """"Bath, Patricia",Karl Marx""", - Seq(patriciaWork, patriciaDarwinWork, karlMarxWork), - "commas in quotes" - ), - ( - """"Bath, Patricia",Karl Marx,"Darwin \"Jones\", Charles"""", - Seq(patriciaWork, karlMarxWork, darwinWork, patriciaDarwinWork), - "quotes in quotes" - ) - ) - - it("filters by contributors as a comma separated list") { - withWorksApi { - case (worksIndex, routes) => - indexTestDocuments(worksIndex, works: _*) - - forAll(testCases) { - (query: String, expectedIds: Seq[String], clue: String) => - withClue(clue) { - assertJsonResponse( - routes, - path = s"$rootPath/works?contributors.agent.label=${URLEncoder - .encode(query, "UTF-8")}" - ) { - Status.OK -> worksListResponse(expectedIds) - } - } - } } } } diff --git a/search/src/test/scala/weco/api/search/works/WorksIncludesTest.scala b/search/src/test/scala/weco/api/search/works/WorksIncludesTest.scala index da587b9861..ecebdd888d 100644 --- a/search/src/test/scala/weco/api/search/works/WorksIncludesTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksIncludesTest.scala @@ -1,6 +1,8 @@ package weco.api.search.works -class WorksIncludesTest extends ApiWorksTestBase { +import org.scalatest.funspec.AnyFunSpec + +class WorksIncludesTest extends AnyFunSpec with ApiWorksTestBase { describe("identifiers includes") { it( "includes a list of identifiers on a list endpoint if we pass ?include=identifiers" diff --git a/search/src/test/scala/weco/api/search/works/WorksRedirectsTest.scala b/search/src/test/scala/weco/api/search/works/WorksRedirectsTest.scala index 7ad43ad531..cdb3615051 100644 --- a/search/src/test/scala/weco/api/search/works/WorksRedirectsTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksRedirectsTest.scala @@ -1,6 +1,8 @@ package weco.api.search.works -class WorksRedirectsTest extends ApiWorksTestBase { +import org.scalatest.funspec.AnyFunSpec + +class WorksRedirectsTest extends AnyFunSpec with ApiWorksTestBase { val redirectSource = "4nwkprdt" val redirectTarget = "mv6kix0n" diff --git a/search/src/test/scala/weco/api/search/works/WorksTest.scala b/search/src/test/scala/weco/api/search/works/WorksTest.scala index c44ca5a4b2..46c3594274 100644 --- a/search/src/test/scala/weco/api/search/works/WorksTest.scala +++ b/search/src/test/scala/weco/api/search/works/WorksTest.scala @@ -1,8 +1,9 @@ package weco.api.search.works +import org.scalatest.funspec.AnyFunSpec import weco.api.search.models.request.WorksIncludes -class WorksTest extends ApiWorksTestBase { +class WorksTest extends AnyFunSpec with ApiWorksTestBase { it("returns a list of works") { withWorksApi { case (worksIndex, routes) => diff --git a/search/src/test/scala/weco/api/search/works/WorksTestDeleted.scala b/search/src/test/scala/weco/api/search/works/WorksTestDeleted.scala index 2df5ef7397..679d32750b 100644 --- a/search/src/test/scala/weco/api/search/works/WorksTestDeleted.scala +++ b/search/src/test/scala/weco/api/search/works/WorksTestDeleted.scala @@ -1,6 +1,8 @@ package weco.api.search.works -class WorksTestDeleted extends ApiWorksTestBase { +import org.scalatest.funspec.AnyFunSpec + +class WorksTestDeleted extends AnyFunSpec with ApiWorksTestBase { it("returns an HTTP 410 Gone if looking up a deleted work") { withWorksApi { case (worksIndex, routes) => diff --git a/search/src/test/scala/weco/api/search/works/WorksTestInvisible.scala b/search/src/test/scala/weco/api/search/works/WorksTestInvisible.scala index 6753b7477f..ae07878723 100644 --- a/search/src/test/scala/weco/api/search/works/WorksTestInvisible.scala +++ b/search/src/test/scala/weco/api/search/works/WorksTestInvisible.scala @@ -1,6 +1,8 @@ package weco.api.search.works -class WorksTestInvisible extends ApiWorksTestBase { +import org.scalatest.funspec.AnyFunSpec + +class WorksTestInvisible extends AnyFunSpec with ApiWorksTestBase { it("returns an HTTP 410 Gone if looking up a work with visible = false") { withWorksApi { case (worksIndex, routes) =>