Skip to content

Commit

Permalink
✅ Test save_exchange_record for request_credential
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Nov 21, 2024
1 parent bad466d commit c71aacc
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions app/tests/e2e/issuer/test_save_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,96 @@ async def test_issue_credential_with_save_exchange_record(
)


@pytest.mark.anyio
@pytest.mark.parametrize("save_exchange_record", [None, False, True])
async def test_request_credential_with_save_exchange_record(
faber_client: RichAsyncClient,
credential_definition_id: str,
faber_and_alice_connection: FaberAliceConnect,
alice_member_client: RichAsyncClient,
save_exchange_record: bool,
):
# This test asserts that the holder can control `save_exchange_records` behaviour
credential = {
"connection_id": faber_and_alice_connection.faber_connection_id,
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": "20", "name": "Alice", "age": "44"},
},
}

# Create and send credential offer - issuer
faber_send_response = (
await faber_client.post(
CREDENTIALS_BASE_PATH,
json=credential,
)
).json()

faber_credential_exchange_id = faber_send_response["credential_exchange_id"]
thread_id = faber_send_response["thread_id"]

try:
# Wait for holder to receive offer
payload = await check_webhook_state(
client=alice_member_client,
topic="credentials",
state="offer-received",
filter_map={
"thread_id": thread_id,
},
)

alice_credential_exchange_id = payload["credential_exchange_id"]

# Send credential request - holder
await alice_member_client.post(
f"{CREDENTIALS_BASE_PATH}/{alice_credential_exchange_id}/request",
params={"save_exchange_record": save_exchange_record},
)

await check_webhook_state(
client=alice_member_client,
topic="credentials",
state="done",
filter_map={
"credential_exchange_id": alice_credential_exchange_id,
},
)

await asyncio.sleep(1) # short sleep before fetching; allow records to update

if save_exchange_record:
# Get exchange record from alice side - should exist if save_exchange_record=True
alice_cred_ex_record = (
await alice_member_client.get(
f"{CREDENTIALS_BASE_PATH}/{alice_credential_exchange_id}"
)
).json()

assert (
alice_cred_ex_record["credential_exchange_id"]
== alice_credential_exchange_id
)
else:
# If save_exchange_record was False, credential should not exist for holder
with pytest.raises(HTTPException) as exc:
await alice_member_client.get(
f"{CREDENTIALS_BASE_PATH}/{alice_credential_exchange_id}"
)
assert exc.value.status_code == 404

finally:
# Clean up
if save_exchange_record:
await alice_member_client.delete(
f"{CREDENTIALS_BASE_PATH}/{alice_credential_exchange_id}"
)
await faber_client.delete(
f"{CREDENTIALS_BASE_PATH}/{faber_credential_exchange_id}"
)


@pytest.mark.anyio
async def test_get_cred_exchange_records(
faber_client: RichAsyncClient,
Expand Down

0 comments on commit c71aacc

Please sign in to comment.