import json
import urllib.parse as parse
from http import HTTPMethod, HTTPStatus

from ..conftest import HttpApiProxy, LambdaContext


def test_orders(
    mock_app,
    dynamodb_seeds,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
):
    # This data was added from seeds
    r = mock_app.lambda_handler(
        http_api_proxy(
            raw_path='/orders',
            queryStringParameters={
                'filter': parse.quote('status = PENDING AND due_date >= 202025-07-09'),
            },
            method=HTTPMethod.GET,
            headers={'x-tenant': 'cJtK9SsnJhKPyxESe7g3DG'},
        ),
        lambda_context,
    )

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


def test_get_order(
    mock_app,
    dynamodb_seeds,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
):
    # This data was added from seeds
    r = mock_app.lambda_handler(
        http_api_proxy(
            raw_path='/orders/KpZTYvu4RzgMJW3A2DF6cC',
            method=HTTPMethod.GET,
        ),
        lambda_context,
    )

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

    body = json.loads(r['body'])
    print(body)
