from myfab import api
import pytest
import json
import os

if not "TEST_JWT_TOKEN" in os.environ:
    print(
        "Please set TEST_JWT_TOKEN to a valid official DVIC JWT token for testing, or use a testing jwt_public.pem file"
    )
    exit(1)

JWT_TOKEN = os.environ["TEST_JWT_TOKEN"]


def test_jwt():
    with api.app.test_client() as c:
        resp = c.get("/whoami", headers={"Authorization": "Bearer %s" % JWT_TOKEN})
        print(resp.json)


def test_new_request():
    with api.app.test_client() as c:
        resp = c.post(
            "/requests/new",
            headers={"Authorization": "Bearer %s" % JWT_TOKEN},  # User authorization
            content_type="application/json",
            data=json.dumps(
                {
                    "title": "TEST project",
                    "description": "test description",
                    "project": "testing",
                }
            ),
        )
        print(resp.json)
        assert "request_id" in resp.json

