-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: Allow reused customer email after deletion
- Loading branch information
1 parent
4d24d0b
commit 4c6e2b8
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
from polar.models import Customer, Organization, User, UserOrganization | ||
from polar.postgres import AsyncSession | ||
from tests.fixtures.auth import AuthSubjectFixture | ||
from tests.fixtures.database import SaveFixture | ||
from tests.fixtures.random_objects import create_customer | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -122,3 +124,56 @@ async def test_valid( | |
|
||
assert customer.email == email | ||
assert customer.name == "John" | ||
|
||
|
||
@pytest.mark.asyncio | ||
class TestDelete: | ||
|
||
async def test_valid( | ||
self, | ||
session: AsyncSession, | ||
save_fixture: SaveFixture, | ||
organization: Organization, | ||
customer: Customer, | ||
) -> None: | ||
customer = await create_customer( | ||
save_fixture, | ||
organization=organization, | ||
email="[email protected]", | ||
) | ||
customer = await customer_service.delete( | ||
session, | ||
customer, | ||
) | ||
await session.flush() | ||
assert customer.deleted_at is not None | ||
|
||
async def test_valid_recreation( | ||
self, | ||
session: AsyncSession, | ||
save_fixture: SaveFixture, | ||
organization: Organization, | ||
customer: Customer, | ||
) -> None: | ||
email = "[email protected]" | ||
customer = await create_customer( | ||
save_fixture, | ||
organization=organization, | ||
email=email, | ||
) | ||
customer = await customer_service.delete( | ||
session, | ||
customer, | ||
) | ||
|
||
assert customer.deleted_at is not None | ||
assert customer.email.startswith("deleted.") | ||
assert customer.email.endswith(email) | ||
await session.commit() | ||
|
||
recreated = await create_customer( | ||
save_fixture, | ||
organization=organization, | ||
email=email, | ||
) | ||
assert recreated |