from layercake.dateutils import now
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey

import events.batch.csv_into_chunks as app


def test_chunk_csv(
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context,
):
    pk = 'BATCH_JOB#ORG#1411844c-10d6-456e-959d-e91775145461'
    sk = 'FILE#2025-11-13T16:04:53.024743'
    event = {
        'detail': {
            'new_image': {
                'id': pk,
                'sk': sk,
                's3_uri': 's3://saladeaula.digital/samples/large_users.csv',
                'columns': {
                    '1:email',
                    '2:cpf',
                    '3:name',
                },
                'org': {
                    'id': '1411844c-10d6-456e-959d-e91775145461',
                    'name': 'EDUSEG',
                    'cnpj': '15608435000190',
                },
                'created_at': now(),
            },
        },
    }

    app.lambda_handler(event, lambda_context)  # type: ignore

    r = dynamodb_persistence_layer.collection.query(PartitionKey(pk), limit=100)
    assert len(r['items']) == 67
