Skip to content

Commit

Permalink
Add tests for greeting attempt events
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Feb 6, 2025
1 parent 1a12e5d commit 11f965e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
authenticated_cmds,
invited_cmds,
)
from parsec.events import EventGreetingAttemptCancelled
from tests.common import (
Backend,
CoolorgRpcClients,
Expand Down Expand Up @@ -232,6 +233,28 @@ async def test_authenticated_invite_greeter_cancel_greeting_attempt_with_deleted
)


async def test_authenticated_invite_greeter_cancel_greeting_attempt_cancelled_event(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
backend: Backend,
) -> None:
with backend.event_bus.spy() as spy:
rep = await coolorg.alice.invite_greeter_cancel_greeting_attempt(
greeting_attempt=greeting_attempt,
reason=CancelledGreetingAttemptReason.MANUALLY_CANCELLED,
)
assert rep == authenticated_cmds.latest.invite_greeter_cancel_greeting_attempt.RepOk()

await spy.wait_event_occurred(
EventGreetingAttemptCancelled(
organization_id=coolorg.organization_id,
greeting_attempt=greeting_attempt,
token=coolorg.invited_alice_dev3.token,
greeter=coolorg.alice.user_id,
)
)


async def test_authenticated_invite_greeter_cancel_greeting_attempt_http_common_errors(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
Expand Down
35 changes: 35 additions & 0 deletions server/tests/api_v5/authenticated/test_invite_greeter_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
invited_cmds,
)
from parsec.components.invite import NotReady
from parsec.events import EventGreetingAttemptJoined
from tests.common import (
Backend,
CoolorgRpcClients,
Expand Down Expand Up @@ -299,6 +300,40 @@ async def test_authenticated_invite_greeter_step_with_deleted_shamir(
assert rep == authenticated_cmds.latest.invite_greeter_step.RepInvitationCancelled()


async def test_authenticated_invite_greeter_step_greeting_attempt_joined_event(
coolorg: CoolorgRpcClients,
backend: Backend,
greeting_attempt: GreetingAttemptID,
claimer_wait_peer_public_key: PublicKey,
) -> None:
greeter_key = PrivateKey.generate()
greeter_step = authenticated_cmds.latest.invite_greeter_step.GreeterStepNumber0WaitPeer(
public_key=greeter_key.public_key
)
expected_claimer_step = (
authenticated_cmds.latest.invite_greeter_step.ClaimerStepNumber0WaitPeer(
public_key=claimer_wait_peer_public_key
)
)

with backend.event_bus.spy() as spy:
rep = await coolorg.alice.invite_greeter_step(
greeting_attempt=greeting_attempt, greeter_step=greeter_step
)
assert rep == authenticated_cmds.latest.invite_greeter_step.RepOk(
claimer_step=expected_claimer_step
)

await spy.wait_event_occurred(
EventGreetingAttemptJoined(
organization_id=coolorg.organization_id,
greeter=coolorg.alice.user_id,
token=coolorg.invited_alice_dev3.token,
greeting_attempt=greeting_attempt,
)
)


async def test_authenticated_invite_greeter_step_http_common_errors(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
authenticated_cmds,
invited_cmds,
)
from parsec.events import EventGreetingAttemptCancelled
from tests.common import (
Backend,
CoolorgRpcClients,
Expand Down Expand Up @@ -201,6 +202,28 @@ async def do():
await invited_greeting_with_deleted_shamir_tester(do)


async def test_invited_invite_claimer_cancel_greeting_attempt_cancelled_event(
coolorg: CoolorgRpcClients,
backend: Backend,
greeting_attempt: GreetingAttemptID,
) -> None:
with backend.event_bus.spy() as spy:
rep = await coolorg.invited_alice_dev3.invite_claimer_cancel_greeting_attempt(
greeting_attempt=greeting_attempt,
reason=CancelledGreetingAttemptReason.MANUALLY_CANCELLED,
)
assert rep == invited_cmds.latest.invite_claimer_cancel_greeting_attempt.RepOk()

await spy.wait_event_occurred(
EventGreetingAttemptCancelled(
organization_id=coolorg.organization_id,
greeting_attempt=greeting_attempt,
token=coolorg.invited_alice_dev3.token,
greeter=coolorg.alice.user_id,
)
)


async def test_invited_invite_claimer_cancel_greeting_attempt_http_common_errors(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
Expand Down
46 changes: 46 additions & 0 deletions server/tests/api_v5/invited/test_invite_claimer_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
invited_cmds,
)
from parsec.components.invite import NotReady
from parsec.events import EventGreetingAttemptReady
from tests.common import (
Backend,
CoolorgRpcClients,
Expand Down Expand Up @@ -278,6 +279,51 @@ async def do():
await invited_greeting_with_deleted_shamir_tester(do)


async def test_invited_invite_claimer_step_greeting_attempt_ready_event(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
backend: Backend,
) -> None:
greeter_key = PrivateKey.generate()
claimer_step = invited_cmds.latest.invite_claimer_step.ClaimerStepNumber0WaitPeer(
public_key=greeter_key.public_key
)
# Run once

with backend.event_bus.spy() as spy:
rep = await coolorg.invited_alice_dev3.invite_claimer_step(
greeting_attempt=greeting_attempt, claimer_step=claimer_step
)
assert rep == invited_cmds.latest.invite_claimer_step.RepNotReady()

await spy.wait_event_occurred(
EventGreetingAttemptReady(
organization_id=coolorg.organization_id,
greeter=coolorg.alice.user_id,
token=coolorg.invited_alice_dev3.token,
greeting_attempt=greeting_attempt,
)
)

# Run twice

with backend.event_bus.spy() as spy:
rep = await coolorg.invited_alice_dev3.invite_claimer_step(
greeting_attempt=greeting_attempt,
claimer_step=claimer_step,
)
assert rep == invited_cmds.latest.invite_claimer_step.RepNotReady()

await spy.wait_event_occurred(
EventGreetingAttemptReady(
organization_id=coolorg.organization_id,
greeter=coolorg.alice.user_id,
token=coolorg.invited_alice_dev3.token,
greeting_attempt=greeting_attempt,
)
)


async def test_invited_invite_claimer_step_http_common_errors(
coolorg: CoolorgRpcClients,
greeting_attempt: GreetingAttemptID,
Expand Down

0 comments on commit 11f965e

Please sign in to comment.