import app.events.stopgap.add_tenant as app
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair


def test_add_tenant(
    dynamodb_client,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'new_image': {
                'id': 'orgmembers#cJtK9SsnJhKPyxESe7g3DG',
                'sk': '5OxmMjL-ujoR5IMGegQz',
            },
        }
    }
    assert app.lambda_handler(event, lambda_context)  # type: ignore
    result = dynamodb_persistence_layer.collection.get_item(
        KeyPair('5OxmMjL-ujoR5IMGegQz', '0')
    )

    assert 'cJtK9SsnJhKPyxESe7g3DG' in result['tenant']
