aboutsummaryrefslogtreecommitdiff
path: root/tests/test_api.py
blob: 8d9768fb925d0cff303ec088426397d92aa739af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pytest
from fastapi.testclient import TestClient

from poker.api import app


@pytest.fixture(scope="function")
def client() -> TestClient:
    return TestClient(app)


def test_health_check(client: TestClient) -> None:
    response = client.get("/")

    assert response.status_code == 200
    assert response.json() == "OK"


@pytest.mark.parametrize(
    "body,expected",
    [
        ("AH KH QH JH 10H", "royal flush: hearts"),
        ("6H 7H 8H 9H 10H", "straight flush: 10-high hearts"),
        ("AH AC AD AS KH", "four of a kind: ace"),
        ("AH AC AD KS KH", "full house: ace over king"),
        ("KC 10C 8C 7C 5C", "flush: clubs"),
        ("10H 9C 8D 7S 6H", "straight: 10-high"),
        ("AH AC AD KS QH", "three of a kind: ace"),
        ("AH AC KD KS 7H", "two pair: ace and king"),
        ("AH AC KD JS 7H", "pair: ace"),
        ("AH KC QD 9S 7H", "high card: ace"),
    ],
    ids=[
        "royal-flush",
        "straight-flush",
        "four-of-a-kind",
        "full-house",
        "flush",
        "straight",
        "three-of-a-kind",
        "two-pair",
        "pair",
        "high-card",
    ],
)
def test_rank(client: TestClient, body: str, expected: str) -> None:
    response = client.post("/rank", json=body)

    assert response.status_code == 200
    assert response.json() == expected


@pytest.mark.parametrize(
    "body",
    [
        "AH KH QH JH",
        "AH KH QH JH 99W",
    ],
    ids=[
        "too-few",
        "not-a-card",
    ],
)
def test_rank_bad_input(client: TestClient, body: str) -> None:
    response = client.post("/rank", json=body)

    assert response.status_code != 200