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

import events.stopgap.patch_course_metadata as app


def test_enroll(
    seeds,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'new_image': {
                'id': '47ZxxcVBjvhDS5TE98tpfQ',
                'sk': '0',
                'course': {
                    'id': '57',
                    'name': 'NR-33 Supervisor em Espaço Confinado',
                    'time_in_days': 360,
                },
            }
        }
    }
    assert app.lambda_handler(event, lambda_context)  # type: ignore

    r = dynamodb_persistence_layer.collection.get_item(
        KeyPair('47ZxxcVBjvhDS5TE98tpfQ', '0')
    )

    assert 'access_expires_at' in r
