guardian / typerighter

Even if you’re the right typer, couldn’t hurt to use Typerighter!
Apache License 2.0
276 stars 12 forks source link

Add a method to the checker service to test a single rule #382

Closed jonathonherbert closed 1 year ago

jonathonherbert commented 1 year ago

PR 1/3 to to fulfil the workflow described in https://github.com/guardian/typerighter/discussions/344.

What does this change?

Adds a method to the checker service to test a single rule, and exposes an endpoint to call it in the controller.

Here's an example of a valid request:

{
    "requestId": "1650f358-4dfe-4f74-aa4b-1d07ae4478ea",
    "rule": {
        "id": "0298e1b6-e28d-4091-a9b4-0c0ff1d3450f",
        "category": {
            "id": "Style guide and names",
            "name": "Style guide and names"
        },
        "description": "MP last elected in 2019: Conservative, South West Surrey",
        "suggestions": [],
        "replacement": {
            "type": "TEXT_SUGGESTION",
            "text": "Jeremy Hunt"
        },
        "regex": "Jeremy Hunt",
        "_type": "com.gu.typerighter.model.RegexRule"
    },
    "documents": [
        {
            "id": "business/2023/jul/13/uk-economy-shrinks-by-01-in-may-despite-coronation-festivities",
            "blocks": [
                {
                    "id": "elem-0",
                    "text": "The chancellor, [Jeremy Hunt](https://www.theguardian.com/politics/jeremy-hunt), said the best way to get growth going again was to ease pressure on households by bringing down inflation. “While an extra bank holiday had an impact on growth in May, high inflation remains a drag anchor on economic growth,” he said.",
                    "from": 0,
                    "to": 413
                }
            ]
        }
    ]
}

How to test

To succesfully request a check, you'll need to add a pan-domain auth cookie to the request. Postman can be really useful here – this is perhaps most easily done by right-clicking a valid request to checker.typerighter.{stage}.dev-gutools.co.uk, right clicking, and selecting 'copy as curl'. You can then import the request (which will have a valid cookie) in Postman, and alter it for the correct URL and verb (POST /checkSingle).