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 endpoint for creating and editing rules #305

Closed rhystmills closed 1 year ago

rhystmills commented 1 year ago

What does this change?

This PR adds endpoints for creating and editing rules in the rule manager.

The endpoints are:

The create endpoint expects a POST request with a JSON body that contains at minimum a ruleType.

An example request body might look like:

{
    "ruleType": "regex",
    "pattern": "/example/",
    "description": "A perfectly fine word"
}

The update endpoint expects a POST request with a JSON body that contains at minimum an id.

An example request body might look like:

{
    "pattern": "/embiggens/",
    "id": 53
}

The validation rules are pretty sparse currently - for create the only custom validation is checking that the ruleType is one of "regex", "languageToolXML" or "languageToolCore".

N.b. The rules displayed in the rule-manager UI will not be updated currently as a result of your changes to the rules in the DB - they're only updated by re-ingesting the Google Sheet.

How to test

Automated tests:

  1. Run the application from the project root with ./script/start
  2. In another tab, run sbt from the project root
  3. Use the rule-manager project with project ruleManager in the sbt shell
  4. Run the tests with test Do all the tests pass?

Manual testing:

You may want to do some testing of the endpoints using something like Postman. I found I needed to grab some cookies from the browser in order to be validated, specifically PLAY_SESSION, guToolsAuth and gutoolsAuth-assym.

I used application/json as the Content-Type header with the json listed at the top of this page as the request body.