integration-0.1.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Testlib.JSON

Synopsis

Documentation

class MakesValue a where Source #

All library functions should use this typeclass for all untyped value arguments wherever possible. This design choice has advantages:

No need convert value between different representations. E.g. if a function needs a user id as a string, all these input types become valid input:

  • String
  • Text
  • Value
  • App Text
  • App String
  • App Value

Internally the function calls asString to convert to App String

Since (App a) are treated as first-class values values this means we can compose operations that might fail without giving up nice error messages:

callMe (response.json %. "user" & "foo.bar.baz" %.= 2)

This can fail if 1. the response is not application/json 2. has no "user" field 3. the nested update fails

Methods

make :: HasCallStack => a -> App Value Source #

Instances

Instances details
MakesValue FedConn Source # 
Instance details

Defined in API.BrigInternal

Methods

make :: FedConn -> App Value Source #

MakesValue CreateConv Source # 
Instance details

Defined in API.Galley

MakesValue PushToken Source # 
Instance details

Defined in API.Gundeck

MakesValue Domain Source # 
Instance details

Defined in Testlib.App

Methods

make :: Domain -> App Value Source #

MakesValue ClientIdentity Source # 
Instance details

Defined in Testlib.JSON

MakesValue CredentialType Source # 
Instance details

Defined in Testlib.JSON

MakesValue AnyFedDomain Source # 
Instance details

Defined in Testlib.VersionedFed

MakesValue StaticDomain Source # 
Instance details

Defined in Testlib.VersionedFed

ToJSON a => MakesValue a Source # 
Instance details

Defined in Testlib.JSON

Methods

make :: a -> App Value Source #

ToJSON a => MakesValue (App a) Source # 
Instance details

Defined in Testlib.JSON

Methods

make :: App a -> App Value Source #

(MakesValue a, MakesValue b) => MakesValue (OneOf a b) Source # 
Instance details

Defined in Testlib.PTest

Methods

make :: OneOf a b -> App Value Source #

MakesValue (FedDomain 0) Source # 
Instance details

Defined in Testlib.VersionedFed

Methods

make :: FedDomain 0 -> App Value Source #

MakesValue (FedDomain 1) Source # 
Instance details

Defined in Testlib.VersionedFed

Methods

make :: FedDomain 1 -> App Value Source #

(.=) :: ToJSON a => String -> a -> Pair Source #

asOptional :: HasCallStack => MakesValue a => a -> App (Maybe Value) Source #

Convert JSON null to Nothing.

asListOf :: HasCallStack => (Value -> App b) -> MakesValue a => a -> App [b] Source #

asSetOf :: (HasCallStack, Ord b) => (Value -> App b) -> MakesValue a => a -> App (Set b) Source #

(%.) Source #

Arguments

:: (HasCallStack, MakesValue a) 
=> a 
-> String

A plain key, e.g. "id", or a nested key "user.profile.id"

-> App Value 

Get a (nested) field of a JSON object Raise an AssertionFailure if the field at the (nested) key is missing. See lookupField for details.

liftP2 :: (MakesValue a, MakesValue b, HasCallStack) => (Value -> Value -> c) -> a -> b -> App c Source #

lookupFieldM Source #

Arguments

:: (HasCallStack, MakesValue a) 
=> a 
-> String

A plain key, e.g. "id", or a nested key "user.profile.id"

-> MaybeT App Value 

like lookupField but wrapped in MaybeT for convenience

lookupField Source #

Arguments

:: (HasCallStack, MakesValue a) 
=> a 
-> String

A plain key, e.g. "id", or a nested key "user.profile.id"

-> App (Maybe Value) 

Look up (nested) field of a JSON object

If the field key has no dots then returns Nothing if the key is missing from the object.

If the field key has dots (describes a nested lookuyp) then returns Nothing if the last component of the key field selector is missing from nested object. If any other component is missing this function raises an AssertionFailure.

Objects and arrays are supported. Array keys should be integers.

setField Source #

Arguments

:: forall a b. (HasCallStack, MakesValue a, ToJSON b) 
=> String

Selector, e.g. "id", "user.team.id"

-> b

The value that should insert or replace the value at the selector

-> a 
-> App Value 

Update nested fields E.g. ob & "foo.bar.baz" %.= ("quux" :: String) The selector path will be created if non-existing.

modifyField :: (HasCallStack, MakesValue a, ToJSON b) => String -> (Maybe Value -> App b) -> a -> App Value Source #

Update nested fields, using the old value with a stateful action The selector path will be created if non-existing.

removeField :: (HasCallStack, MakesValue a) => String -> a -> App Value Source #

`removeField "a.b" {"a": {"b": 3}, "c": true} == {"a": {}, "c": true}`

printJSON :: MakesValue a => a -> App () Source #

Useful for debugging

traceJSON :: MakesValue a => a -> App a Source #

useful for debugging, same as printJSON but returns input JSON

objQidObject :: HasCallStack => MakesValue a => a -> App Value Source #

Get "qualified_id" field as {"id": _, "domain": _} object or - if already is a qualified id object - return that.

objSubConv :: (HasCallStack, MakesValue a) => a -> App (Value, Maybe String) Source #

Get conversation ID and optional subconversation ID.

This accepts subconversation objects in the format: { "parent_qualified_id": { "domain": "example.com", "id": "7b6c21d1-322d-4be6-a923-85225691f398" }, "subconv_id": "conference" }

as well as conversation objects in the general format supported by objQid. Conversation objects can optionally contain a subconv_id field. So, in particular, a flat subconversation format, like { "domain": "example.com", "id": "7b6c21d1-322d-4be6-a923-85225691f398", "subconv_id": "conference" } is also supported.

objSubConvObject :: (HasCallStack, MakesValue a) => a -> App Value Source #

Turn an object parseable by objSubConv into a canonical flat representation.