from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair

import events.stopgap.patch_konviva as app


def test_patch_konviva(
    seeds,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'new_image': {
                'id': 'f321f0aa-66a3-4419-b41f-cb6b961e7e4f',
                'user': {'id': '5OxmMjL-ujoR5IMGegQz'},
                'course': {'id': '123'},
            },
        }
    }
    assert app.lambda_handler(event, lambda_context)  # type: ignore

    r = dynamodb_persistence_layer.collection.get_item(
        KeyPair('f321f0aa-66a3-4419-b41f-cb6b961e7e4f', 'konviva')
    )

    assert 'user_id' in r
