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

import events.set_access_expired as app


def test_set_access_expired(
    seeds,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'old_image': {
                'id': '6437a282-6fe8-4e4d-9eb0-da1007238007',
                'sk': '0',
            }
        }
    }
    assert app.lambda_handler(event, lambda_context)  # type: ignore

    r = dynamodb_persistence_layer.collection.get_items(
        TransactKey('6437a282-6fe8-4e4d-9eb0-da1007238007')
        + SortKey('0')
        + SortKey('SCHEDULE#SET_ACCESS_EXPIRED#EXECUTED', rename_key='executed')
    )
    assert r['status'] == 'IN_PROGRESS'
    assert 'executed' in r
    assert 'access_expired' in r
