mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
feat(backend): ✨ start multi-tenant support (WIP) (#680)
* fix ts types * feat(code-generation): ♻️ update code-generation formats * new scope * add step button * fix linter error * update code-generation tags * feat(backend): ✨ start multi-tenant support * feat(backend): ✨ group invitation token generation and signup * refactor(backend): ♻️ move group admin actions to admin router * set url base to include `/admin` * feat(frontend): ✨ generate user sign-up links * test(backend): ✅ refactor test-suite to further decouple tests (WIP) * feat(backend): 🐛 assign owner on backup import for recipes * fix(backend): 🐛 assign recipe owner on migration from other service Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
3c504e7048
commit
bdaf758712
90 changed files with 1793 additions and 949 deletions
|
@ -0,0 +1,76 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from tests.utils.factories import random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/recipes"
|
||||
user = "/api/users/self"
|
||||
|
||||
|
||||
GROUP_ID = 1
|
||||
ADMIN_ID = 1
|
||||
USER_ID = 2
|
||||
|
||||
|
||||
def test_ownership_on_new_with_admin(api_client: TestClient, admin_token):
|
||||
recipe_name = random_string()
|
||||
|
||||
response = api_client.post(Routes.base, json={"name": recipe_name}, headers=admin_token)
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
recipe = api_client.get(Routes.base + f"/{recipe_name}", headers=admin_token).json()
|
||||
|
||||
assert recipe["userId"] == ADMIN_ID
|
||||
assert recipe["groupId"] == GROUP_ID
|
||||
|
||||
|
||||
def test_ownership_on_new_with_user(api_client: TestClient, g2_user: TestUser):
|
||||
recipe_name = random_string()
|
||||
|
||||
response = api_client.post(Routes.base, json={"name": recipe_name}, headers=g2_user.token)
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
response = api_client.get(Routes.base + f"/{recipe_name}", headers=g2_user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
recipe = response.json()
|
||||
|
||||
assert recipe["userId"] == g2_user.user_id
|
||||
assert recipe["groupId"] == g2_user.group_id
|
||||
|
||||
|
||||
def test_get_all_only_includes_group_recipes(api_client: TestClient, unique_user: TestUser):
|
||||
for _ in range(5):
|
||||
recipe_name = random_string()
|
||||
response = api_client.post(Routes.base, json={"name": recipe_name}, headers=unique_user.token)
|
||||
|
||||
response = api_client.get(Routes.base, headers=unique_user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
recipes = response.json()
|
||||
|
||||
assert len(recipes) == 5
|
||||
|
||||
for recipe in recipes:
|
||||
assert recipe["groupId"] == unique_user.group_id
|
||||
assert recipe["userId"] == unique_user.user_id
|
||||
|
||||
|
||||
def test_unique_slug_by_group(api_client: TestClient, unique_user: TestUser, g2_user: TestUser) -> None:
|
||||
create_data = {"name": random_string()}
|
||||
|
||||
response = api_client.post(Routes.base, json=create_data, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
||||
response = api_client.post(Routes.base, json=create_data, headers=g2_user.token)
|
||||
assert response.status_code == 201
|
||||
|
||||
# Try to create a recipe again with the same name
|
||||
response = api_client.post(Routes.base, json=create_data, headers=g2_user.token)
|
||||
assert response.status_code == 400
|
Loading…
Add table
Add a link
Reference in a new issue