from http import HTTPMethod, HTTPStatus

from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair

from ...conftest import HttpApiProxy, LambdaContext


def test_update(
    app,
    seeds,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
):
    user_id = '15bacf02-1535-4bee-9022-19d106fd7518'
    r = app.lambda_handler(
        http_api_proxy(
            raw_path=f'/users/{user_id}',
            method=HTTPMethod.PATCH,
            body={
                'name': 'Sérgio Rafael Siqueira',
                'cpf': '07879819908',
            },
        ),
        lambda_context,
    )

    assert r['statusCode'] == HTTPStatus.OK

    r = dynamodb_persistence_layer.collection.get_item(KeyPair(user_id, '0'))
    assert r['name'] == 'Sérgio Rafael Siqueira'
