import json
from typing import List


def test_handler(monkeypatch, lambda_module, context, apigateway_event, order):
    """
    Test handler()
    """

    event = apigateway_event(
        iam="USER_ARN",
        body=json.dumps({"products": order["products"], "address": order["address"]})
    )

    def get_pricing(products: List[dict], address: dict) -> int:
        assert products == order["products"]
        assert address == order["address"]

        return 1000

    monkeypatch.setattr(lambda_module, "get_pricing", get_pricing)

    retval = lambda_module.handler(event, context)

    assert "statusCode" in retval
    assert retval["statusCode"] == 200
    assert "body" in retval

    body = json.loads(retval["body"])
    assert "pricing" in body
    assert body["pricing"] == 1000