Skip to content

Commit

Permalink
Fix: add structure in store schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Jan 15, 2025
1 parent f7e7116 commit 65984ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
13 changes: 12 additions & 1 deletion app/core/myeclpay/endpoints_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ async def create_store(
await db.rollback()
raise

Check warning on line 362 in app/core/myeclpay/endpoints_myeclpay.py

View check run for this annotation

Codecov / codecov/patch

app/core/myeclpay/endpoints_myeclpay.py#L360-L362

Added lines #L360 - L362 were not covered by tests

return store_db
return schemas_myeclpay.Store(
id=store_db.id,
name=store_db.name,
structure_id=store_db.structure_id,
wallet_id=store_db.wallet_id,
structure=structure,
)


@router.get(
Expand Down Expand Up @@ -439,6 +445,11 @@ async def get_user_stores(
id=store.id,
name=store.name,
structure_id=store.structure_id,
structure=schemas_myeclpay.Structure(
id=store.structure.id,
name=store.structure.name,
manager_user_id=store.structure.manager_user_id,
),
wallet_id=store.wallet_id,
can_bank=seller.can_bank,
can_see_history=seller.can_see_history,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# revision identifiers, used by Alembic.
revision: str = "e16b58cc6084"
down_revision: str | None = "53c163acf327"
down_revision: str | None = "a1e6e8b52103"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

Expand Down Expand Up @@ -161,8 +161,8 @@ def upgrade() -> None:
"myeclpay_user_payment",
sa.Column("user_id", sa.String(), nullable=False),
sa.Column("wallet_id", sa.Uuid(), nullable=False, unique=True),
sa.Column("accepted_cgu_signature", TZDateTime(), nullable=False),
sa.Column("accepted_cgu_version", sa.Integer(), nullable=False),
sa.Column("accepted_tos_signature", TZDateTime(), nullable=False),
sa.Column("accepted_tos_version", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["user_id"],
["core_user.id"],
Expand Down
50 changes: 25 additions & 25 deletions tests/test_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
WalletDeviceStatus,
WalletType,
)
from app.core.myeclpay.utils_myeclpay import LATEST_CGU, compute_signable_data
from app.core.myeclpay.utils_myeclpay import LATEST_TOS, compute_signable_data
from app.types.membership import AvailableAssociationMembership
from tests.commons import (
TestingSessionLocal,
Expand Down Expand Up @@ -116,8 +116,8 @@ async def init_objects() -> None:
ecl_user_payment = models_myeclpay.UserPayment(
user_id=ecl_user.id,
wallet_id=ecl_user_wallet.id,
accepted_cgu_signature=datetime.now(UTC),
accepted_cgu_version=LATEST_CGU,
accepted_tos_signature=datetime.now(UTC),
accepted_tos_version=LATEST_TOS,
)
await add_object_to_db(ecl_user_payment)

Expand Down Expand Up @@ -174,8 +174,8 @@ async def init_objects() -> None:
ecl_user2_payment = models_myeclpay.UserPayment(
user_id=ecl_user2.id,
wallet_id=ecl_user2_wallet.id,
accepted_cgu_signature=datetime.now(UTC),
accepted_cgu_version=LATEST_CGU,
accepted_tos_signature=datetime.now(UTC),
accepted_tos_version=LATEST_TOS,
)
await add_object_to_db(ecl_user2_payment)

Expand Down Expand Up @@ -733,23 +733,23 @@ async def test_get_user_stores(client: TestClient):
assert len(response.json()) > 0


async def test_get_cgu_for_unregistered_user(client: TestClient):
async def test_get_tos_for_unregistered_user(client: TestClient):
response = client.get(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
headers={"Authorization": f"Bearer {unregistered_ecl_user_access_token}"},
)
assert response.status_code == 400
assert response.json()["detail"] == "User is not registered for MyECL Pay"


async def test_get_cgu(client: TestClient):
async def test_get_tos(client: TestClient):
response = client.get(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
headers={"Authorization": f"Bearer {ecl_user_access_token}"},
)
assert response.status_code == 200
assert response.json()["latest_cgu_version"] == LATEST_CGU
assert response.json()["accepted_cgu_version"] == LATEST_CGU
assert response.json()["latest_tos_version"] == LATEST_TOS
assert response.json()["accepted_tos_version"] == LATEST_TOS


async def test_register_new_user(client: TestClient):
Expand All @@ -772,27 +772,27 @@ async def test_register_new_user(client: TestClient):
assert response.json()["detail"] == "User is already registered for MyECL Pay"


async def test_sign_cgu_for_old_cgu_version(client: TestClient):
async def test_sign_tos_for_old_tos_version(client: TestClient):
response = client.post(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
headers={"Authorization": f"Bearer {unregistered_ecl_user_access_token}"},
json={"accepted_cgu_version": 0},
json={"accepted_tos_version": 0},
)
assert response.status_code == 400
assert response.json()["detail"][:27] == "Only the latest CGU version"
assert response.json()["detail"][:27] == "Only the latest TOS version"


async def test_sign_cgu_for_unregistered_user(client: TestClient):
async def test_sign_tos_for_unregistered_user(client: TestClient):
response = client.post(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
headers={"Authorization": f"Bearer {unregistered_ecl_user_access_token}"},
json={"accepted_cgu_version": 1},
json={"accepted_tos_version": 1},
)
assert response.status_code == 400
assert response.json()["detail"] == "User is not registered for MyECL Pay"


async def test_sign_cgu(client: TestClient):
async def test_sign_tos(client: TestClient):
unregistered_user = await create_user_with_groups(
groups=[],
)
Expand All @@ -805,9 +805,9 @@ async def test_sign_cgu(client: TestClient):
assert response.status_code == 204

response = client.post(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
headers={"Authorization": f"Bearer {unregistered_user_token}"},
json={"accepted_cgu_version": LATEST_CGU},
json={"accepted_tos_version": LATEST_TOS},
)
assert response.status_code == 204

Expand Down Expand Up @@ -1441,7 +1441,7 @@ def test_store_scan_store_from_store_wallet(client: TestClient):
ensure_qr_code_id_is_already_used(qr_code_id=qr_code_id, client=client)


async def test_store_scan_store_from_wallet_with_old_cgu_version(client: TestClient):
async def test_store_scan_store_from_wallet_with_old_tos_version(client: TestClient):
ecl_user = await create_user_with_groups(
groups=[],
)
Expand All @@ -1456,8 +1456,8 @@ async def test_store_scan_store_from_wallet_with_old_cgu_version(client: TestCli
ecl_user_payment = models_myeclpay.UserPayment(
user_id=ecl_user.id,
wallet_id=ecl_user_wallet.id,
accepted_cgu_signature=datetime.now(UTC),
accepted_cgu_version=0,
accepted_tos_signature=datetime.now(UTC),
accepted_tos_version=0,
)
await add_object_to_db(ecl_user_payment)

Expand Down Expand Up @@ -1503,7 +1503,7 @@ async def test_store_scan_store_from_wallet_with_old_cgu_version(client: TestCli
},
)
assert response.status_code == 400
assert response.json()["detail"] == "Debited user has not signed the latest CGU"
assert response.json()["detail"] == "Debited user has not signed the latest TOS"

ensure_qr_code_id_is_already_used(qr_code_id=qr_code_id, client=client)

Expand Down

0 comments on commit 65984ed

Please sign in to comment.