-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A framework for declaratively writing curl based API tests
--   
--   Please see the README on Github at
--   <a>https://github.com/aviaviavi/curl-runnings#readme</a>
@package curl-runnings
@version 0.6.0


-- | This module specifies any utilities used by this package. At this
--   time, consider everything in this module to be private to the
--   curl-runnings package
module Testing.CurlRunnings.Internal
makeRed :: String -> String
makeGreen :: String -> String
tracer :: Show a => String -> a -> a
mapRight :: (b -> c) -> Either a b -> Either a c

-- | Array indexing with negative values allowed
arrayGet :: [a] -> Int -> a
makeLogger :: LogLevel -> CurlRunningsLogger
makeUnsafeLogger :: Show a => LogLevel -> CurlRunningsUnsafeLogger a
data LogLevel
ERROR :: LogLevel
INFO :: LogLevel
DEBUG :: LogLevel

-- | A logger that respects the verbosity level given by input args
type CurlRunningsLogger = (LogLevel -> String -> IO ())

-- | A tracer that respects the verbosity level given by input args.
--   Logging with this calls out to Debug.trace and can be used in pure
--   code, but be aware of the unsafe IO.
type CurlRunningsUnsafeLogger a = (LogLevel -> String -> a -> a)
instance GHC.Enum.Enum Testing.CurlRunnings.Internal.LogLevel
instance GHC.Classes.Ord Testing.CurlRunnings.Internal.LogLevel
instance GHC.Classes.Eq Testing.CurlRunnings.Internal.LogLevel
instance GHC.Show.Show Testing.CurlRunnings.Internal.LogLevel


-- | Data types for curl-runnings tests
module Testing.CurlRunnings.Types

-- | Represents the different type of test failures we can have. A single
--   test case | might return many assertion failures.
data AssertionFailure

-- | The json we got back was wrong. We include this redundant field (it's
--   included in the CurlCase field above) in order to enforce at the type
--   level that we have to be expecting some data in order to have this
--   type of failure.
DataFailure :: CurlCase -> JsonMatcher -> (Maybe Value) -> AssertionFailure

-- | The status code we got back was wrong
StatusFailure :: CurlCase -> Int -> AssertionFailure

-- | The headers we got back were wrong
HeaderFailure :: CurlCase -> HeaderMatcher -> Headers -> AssertionFailure

-- | Something went wrong with a test case json query
QueryFailure :: CurlCase -> QueryError -> AssertionFailure

-- | Something else
UnexpectedFailure :: AssertionFailure

-- | A type representing the result of a single curl, and all associated
--   assertions
data CaseResult
CasePass :: CurlCase -> (Maybe Headers) -> (Maybe Value) -> CaseResult
CaseFail :: CurlCase -> (Maybe Headers) -> (Maybe Value) -> [AssertionFailure] -> CaseResult

-- | A wrapper type around a set of test cases. This is the top level spec
--   type that we parse a test spec file into
newtype CurlSuite
CurlSuite :: [CurlCase] -> CurlSuite

-- | A single curl test case, the basic foundation of a curl-runnings test.
data CurlCase
CurlCase :: String -> String -> HttpMethod -> Maybe Value -> Maybe Headers -> Maybe JsonMatcher -> StatusCodeMatcher -> Maybe HeaderMatcher -> CurlCase

-- | The name of the test case
[name] :: CurlCase -> String

-- | The target url to test
[url] :: CurlCase -> String

-- | Verb to use for the request
[requestMethod] :: CurlCase -> HttpMethod

-- | Payload to send with the request, if any
[requestData] :: CurlCase -> Maybe Value

-- | Headers to send with the request, if any
[headers] :: CurlCase -> Maybe Headers

-- | The assertions to make on the response payload, if any
[expectData] :: CurlCase -> Maybe JsonMatcher

-- | Assertion about the status code returned by the target
[expectStatus] :: CurlCase -> StatusCodeMatcher

-- | Assertions to make about the response headers, if any
[expectHeaders] :: CurlCase -> Maybe HeaderMatcher

-- | A representation of a single header
data Header
Header :: Text -> Text -> Header

-- | Collection of matchers to run against a single curl response
data HeaderMatcher
HeaderMatcher :: [PartialHeaderMatcher] -> HeaderMatcher

-- | Simple container for a list of headers, useful for a vehicle for
--   defining a fromJSON
data Headers
HeaderSet :: [Header] -> Headers

-- | A basic enum for supported HTTP verbs
data HttpMethod
GET :: HttpMethod
POST :: HttpMethod
PUT :: HttpMethod
PATCH :: HttpMethod
DELETE :: HttpMethod

-- | A predicate to apply to the json body from the response
data JsonMatcher

-- | Performs <a>==</a>
Exactly :: Value -> JsonMatcher

-- | A list of matchers to make assertions about some subset of the
--   response.
Contains :: [JsonSubExpr] -> JsonMatcher

-- | A matcher for a subvalue of a json payload
data JsonSubExpr

-- | Assert some value anywhere in the json has a value equal to a given
--   value. The motivation for this field is largely for checking contents
--   of a top level array. It's also useful if you don't know the key ahead
--   of time.
ValueMatch :: Value -> JsonSubExpr

-- | Assert the key value pair can be found somewhere the json.
KeyValueMatch :: Text -> Value -> JsonSubExpr
[matchKey] :: JsonSubExpr -> Text
[matchValue] :: JsonSubExpr -> Value

-- | Specify a key, value, or both to match against in the returned headers
--   of a response.
data PartialHeaderMatcher
PartialHeaderMatcher :: (Maybe Text) -> (Maybe Text) -> PartialHeaderMatcher

-- | Check the status code of a response. You can specify one or many valid
--   codes.
data StatusCodeMatcher
ExactCode :: Int -> StatusCodeMatcher
AnyCodeIn :: [Int] -> StatusCodeMatcher

-- | Different errors relating to querying json from previous test cases
data QueryError

-- | The query was malformed and couldn't be parsed
QueryParseError :: Text -> Text -> QueryError

-- | The retrieved a value of the wrong type or was otherwise operating on
--   the wrong type of thing
QueryTypeMismatch :: Text -> Value -> QueryError

-- | The query was parse-able
QueryValidationError :: Text -> QueryError

-- | Tried to access a value in a null object
NullPointer :: Text -> Text -> QueryError

-- | A single lookup operation in a json query
data Index

-- | Drill into the json of a specific test case. The SUITE object is
--   accessible as an array of values that have come back from previous
--   test cases
CaseResultIndex :: Integer -> Index

-- | A standard json key lookup.
KeyIndex :: Text -> Index

-- | A standard json array index lookup.
ArrayIndex :: Integer -> Index

-- | A single entity to be queries from a json value
data Query

-- | A single query contains a list of discrete index operations
Query :: [Index] -> Query

-- | Lookup a string in the environment
EnvironmentVariable :: Text -> Query

-- | A distinct parsed unit in a query
data InterpolatedQuery

-- | Regular text, no query
LiteralText :: Text -> InterpolatedQuery

-- | Some leading text, then a query
InterpolatedQuery :: Text -> Query -> InterpolatedQuery

-- | Just a query, no leading text
NonInterpolatedQuery :: Query -> InterpolatedQuery

-- | The full string in which a query appears, eg
--   "prefix-${{SUITE[0].key.another_key[0].last_key}}"
type FullQueryText = Text

-- | The string for one query given the FullQueryText above, the single
--   query text would be SUITE[0].key.another_key[0].last_key
type SingleQueryText = Text

-- | The state of a suite. Tracks environment variables, and all the test
--   results so far
data CurlRunningsState
CurlRunningsState :: Environment -> [CaseResult] -> LogLevel -> CurlRunningsState

-- | Simple predicate that checks if the result is failing
isFailing :: CaseResult -> Bool

-- | Simple predicate that checks if the result is passing
isPassing :: CaseResult -> Bool
logger :: CurlRunningsState -> CurlRunningsLogger
unsafeLogger :: Show a => CurlRunningsState -> CurlRunningsUnsafeLogger a
instance GHC.Show.Show Testing.CurlRunnings.Types.InterpolatedQuery
instance GHC.Show.Show Testing.CurlRunnings.Types.Query
instance GHC.Show.Show Testing.CurlRunnings.Types.Index
instance GHC.Generics.Generic Testing.CurlRunnings.Types.CurlSuite
instance GHC.Show.Show Testing.CurlRunnings.Types.CurlSuite
instance GHC.Generics.Generic Testing.CurlRunnings.Types.CurlCase
instance GHC.Show.Show Testing.CurlRunnings.Types.CurlCase
instance GHC.Generics.Generic Testing.CurlRunnings.Types.StatusCodeMatcher
instance GHC.Show.Show Testing.CurlRunnings.Types.StatusCodeMatcher
instance GHC.Generics.Generic Testing.CurlRunnings.Types.JsonMatcher
instance GHC.Show.Show Testing.CurlRunnings.Types.JsonMatcher
instance GHC.Generics.Generic Testing.CurlRunnings.Types.JsonSubExpr
instance GHC.Show.Show Testing.CurlRunnings.Types.JsonSubExpr
instance GHC.Generics.Generic Testing.CurlRunnings.Types.HeaderMatcher
instance GHC.Show.Show Testing.CurlRunnings.Types.HeaderMatcher
instance GHC.Generics.Generic Testing.CurlRunnings.Types.PartialHeaderMatcher
instance GHC.Show.Show Testing.CurlRunnings.Types.PartialHeaderMatcher
instance GHC.Generics.Generic Testing.CurlRunnings.Types.Headers
instance GHC.Show.Show Testing.CurlRunnings.Types.Headers
instance GHC.Generics.Generic Testing.CurlRunnings.Types.Header
instance GHC.Show.Show Testing.CurlRunnings.Types.Header
instance GHC.Generics.Generic Testing.CurlRunnings.Types.HttpMethod
instance GHC.Show.Show Testing.CurlRunnings.Types.HttpMethod
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.CurlSuite
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.CurlSuite
instance GHC.Show.Show Testing.CurlRunnings.Types.CaseResult
instance GHC.Show.Show Testing.CurlRunnings.Types.AssertionFailure
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.CurlCase
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.CurlCase
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.StatusCodeMatcher
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.StatusCodeMatcher
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.JsonMatcher
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.JsonMatcher
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.JsonSubExpr
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.JsonSubExpr
instance GHC.Show.Show Testing.CurlRunnings.Types.QueryError
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.HeaderMatcher
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.HeaderMatcher
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.PartialHeaderMatcher
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.Headers
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.Headers
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.Header
instance Data.Aeson.Types.FromJSON.FromJSON Testing.CurlRunnings.Types.HttpMethod
instance Data.Aeson.Types.ToJSON.ToJSON Testing.CurlRunnings.Types.HttpMethod


-- | Internal module for parsing string based directives inside of curl
--   runnings suites. Use this module at your own risk, it may change.
--   Currently, string interpolation can be performed, where interpolated
--   values are json quries into responses from past test cases.
--   
--   <pre>
--   "$&lt;SUITE[0].key[0].another_key&gt;"
--   </pre>
--   
--   here the <tt>SUITE</tt> keyword references the results of previous
--   test cases. Here, the whole string is a query, so if the value
--   referenced by this query is itself a json value, the entire value will
--   replace this string in a json matcher. Additionally, interpolation of
--   the form:
--   
--   <pre>
--   "some text to interpolate with $&lt;SUITE[0].key.key&gt;"
--   </pre>
--   
--   will substitute a string found at the specified query and subsitute
--   the string.
--   
--   Rules for the language are similar to JQ or regular JSON indexing
--   rules. All queries must start with a SUITE[integer] index, and be
--   written between a
--   
--   <pre>
--   $&lt; ... &gt;
--   </pre>
--   
--   to signify an interpolation. You can have mutliple queries inside a
--   single string, but if interpolation is occuring, then the query
--   specified must resolve to a string value. Otheriwse, a type error will
--   be thrown.
module Testing.CurlRunnings.Internal.Parser

-- | Given some query text, attempt to parse it to a list of interplated
--   query objects. This data representation may change.
parseQuery :: FullQueryText -> Either QueryError [InterpolatedQuery]


-- | curl-runnings is a framework for writing declaratively writing curl
--   based tests for your API's. Write your test specifications with yaml
--   or json, and you're done!
module Testing.CurlRunnings

-- | Run a single test case, and returns the result. IO is needed here
--   since this method is responsible for actually curling the test case
--   endpoint and parsing the result.
runCase :: CurlRunningsState -> CurlCase -> IO CaseResult

-- | Runs the test cases in order and stop when an error is hit. Returns
--   all the results
runSuite :: CurlSuite -> LogLevel -> IO [CaseResult]

-- | decode a json or yaml file into a suite object
decodeFile :: FilePath -> IO (Either String CurlSuite)
