Koha-clms/t/db_dependent/api
Martin Renvoize df27f4884b
Bug 41901: Unit tests
Extends the existing `post() tests` subtest in
t/db_dependent/api/v1/authorities.t with coverage for the new
`x-koha-matchrule` header that selects a Koha record matching rule
(`C4::Matcher`, record_type=authority) for duplicate detection when
creating authorities via POST /api/v1/authorities.

The new cases exercise:
* non-integer id (rejected by the OpenAPI schema validator)
* unknown matcher id -> 400 `matching_rule_not_found`
* biblio matcher id -> 400 `invalid_matching_rule_type`
* valid authority matcher returning duplicates -> 409 with a
  `matches` array of `{authid, score}` objects
* valid authority matcher returning no duplicates -> 201
* matcher combined with `x-koha-override: duplicate` -> 201
  (override wins, matcher is skipped)

`C4::Matcher` is mocked deterministically to avoid relying on the
authority search engine in the test database.

These tests fail without the controller/spec changes introduced in
the follow-up commit.

Test plan:
1) Apply only this patch and run
   `prove t/db_dependent/api/v1/authorities.t`.
   => Failures are expected in the `post() tests` subtest for the
      `x-koha-matchrule` cases.
2) Apply the next patch in the series and re-run the tests.
   => All subtests pass.

Signed-off-by: Brian J. Barr <brian.barr@churchofjesuschrist.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5feb1e03eb)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
2026-05-24 13:42:22 +01:00
..
v1 Bug 41901: Unit tests 2026-05-24 13:42:22 +01:00