mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +02:00
chore: file generation cleanup (#1736)
This PR does too many things :( 1. Major refactoring of the dev/scripts and dev/code-generation folders. Primarily this was removing duplicate code and cleaning up some poorly written code snippets as well as making them more idempotent so then can be re-run over and over again but still maintain the same results. This is working on my machine, but I've been having problems in CI and comparing diffs so running generators in CI will have to wait. 2. Re-Implement using the generated api routes for testing This was a _huge_ refactor that touched damn near every test file but now we have auto-generated typed routes with inline hints and it's used for nearly every test excluding a few that use classes for better parameterization. This should greatly reduce errors when writing new tests. 3. Minor Perf improvements for the All Recipes endpoint A. Removed redundant loops B. Uses orjson to do the encoding directly and returns a byte response instead of relying on the default jsonable_encoder. 4. Fix some TS type errors that cropped up for seemingly no reason half way through the PR. See this issue https://github.com/phillipdupuis/pydantic-to-typescript/issues/28 Basically, the generated TS type is not-correct since Pydantic will automatically fill in null fields. The resulting TS type is generated with a ? to indicate it can be null even though we _know_ that i can't be.
This commit is contained in:
parent
a8f0fb14a7
commit
9ecef4c25f
107 changed files with 2520 additions and 1948 deletions
|
@ -3,18 +3,10 @@ from datetime import datetime, timezone
|
|||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from tests.utils import assert_derserialize, jsonify
|
||||
from tests.utils import api_routes, assert_derserialize, jsonify
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/groups/webhooks"
|
||||
|
||||
@staticmethod
|
||||
def item(item_id: int) -> str:
|
||||
return f"{Routes.base}/{item_id}"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def webhook_data():
|
||||
return {
|
||||
|
@ -27,15 +19,15 @@ def webhook_data():
|
|||
|
||||
|
||||
def test_create_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
||||
response = api_client.post(Routes.base, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
||||
response = api_client.post(Routes.base, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
item_id = response.json()["id"]
|
||||
|
||||
response = api_client.get(Routes.item(item_id), headers=unique_user.token)
|
||||
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
||||
webhook = assert_derserialize(response, 200)
|
||||
|
||||
assert webhook["id"] == item_id
|
||||
|
@ -46,7 +38,7 @@ def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_dat
|
|||
|
||||
|
||||
def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
||||
response = api_client.post(Routes.base, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
item_dict = assert_derserialize(response, 201)
|
||||
item_id = item_dict["id"]
|
||||
|
||||
|
@ -54,7 +46,9 @@ def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestU
|
|||
webhook_data["url"] = "https://my-new-fake-url.com"
|
||||
webhook_data["enabled"] = False
|
||||
|
||||
response = api_client.put(Routes.item(item_id), json=jsonify(webhook_data), headers=unique_user.token)
|
||||
response = api_client.put(
|
||||
api_routes.groups_webhooks_item_id(item_id), json=jsonify(webhook_data), headers=unique_user.token
|
||||
)
|
||||
updated_webhook = assert_derserialize(response, 200)
|
||||
|
||||
assert updated_webhook["name"] == webhook_data["name"]
|
||||
|
@ -63,12 +57,12 @@ def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestU
|
|||
|
||||
|
||||
def test_delete_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
||||
response = api_client.post(Routes.base, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
||||
item_dict = assert_derserialize(response, 201)
|
||||
item_id = item_dict["id"]
|
||||
|
||||
response = api_client.delete(Routes.item(item_id), headers=unique_user.token)
|
||||
response = api_client.delete(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.get(Routes.item(item_id), headers=unique_user.token)
|
||||
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue