-- * Test cases

-- ** Node queries

-- | Tests that querying any existing fields, via either query or
-- queryFields, will not return unknown fields.
prop_queryNode_noUnknown :: Property
prop_queryNode_noUnknown =
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
  forAll (elements (Map.keys Node.fieldsMap)) $ \field -> monadicIO $ do
  QueryResult fdefs fdata <-
    run (query cluster False (Query (ItemTypeOpCode QRNode)
                              [field] EmptyFilter)) >>= resultProp
  QueryFieldsResult fdefs' <-
    resultProp $ queryFields (QueryFields (ItemTypeOpCode QRNode) [field])
  _ <- stop $ conjoin
              [ counterexample ("Got unknown fields via query (" ++
                                show fdefs ++ ")") (hasUnknownFields fdefs)
              , counterexample ("Got unknown result status via query (" ++
                                show fdata ++ ")")
                (all (all ((/= RSUnknown) . rentryStatus)) fdata)
              , counterexample ("Got unknown fields via query fields (" ++
                                show fdefs'++ ")") (hasUnknownFields fdefs')
              ]
  return ()

-- | Tests that an unknown field is returned as such.
prop_queryNode_noUnknown :: Property
prop_queryNode_noUnknown =
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
  forAll (elements (Map.keys Node.fieldsMap)) $ \field -> monadicIO $ do
  QueryResult fdefs fdata <-
    run (query cluster False (Query (ItemTypeOpCode QRNode)
                              [field] EmptyFilter)) >>= resultProp
  QueryFieldsResult fdefs' <-
    resultProp $ queryFields (QueryFields (ItemTypeOpCode QRNode) [field])
  _ <- stop $ conjoin
              [ counterexample ("Got unknown fields via query (" ++
                                show fdefs ++ ")") (hasUnknownFields fdefs)
              , counterexample ("Got unknown result status via query (" ++
                                show fdata ++ ")")
                (all (all ((/= RSUnknown) . rentryStatus)) fdata)
              , counterexample ("Got unknown fields via query fields (" ++
                                show fdefs'++ ")") (hasUnknownFields fdefs')
              ]
  return ()

-- | Tests that an unknown field is returned as such.
prop_queryNode_noUnknown =
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
  forAll (elements (Map.keys Node.fieldsMap)) $ \field -> monadicIO $ do
  QueryResult fdefs fdata <-
    run (query cluster False (Query (ItemTypeOpCode QRNode)
                              [field] EmptyFilter)) >>= resultProp
  QueryFieldsResult fdefs' <-
    resultProp $ queryFields (QueryFields (ItemTypeOpCode QRNode) [field])
  _ <- stop $ conjoin
              [ counterexample ("Got unknown fields via query (" ++
                                show fdefs ++ ")") (hasUnknownFields fdefs)
              , counterexample ("Got unknown result status via query (" ++
                                show fdata ++ ")")
                (all (all ((/= RSUnknown) . rentryStatus)) fdata)
              , counterexample ("Got unknown fields via query fields (" ++
                                show fdefs'++ ")") (hasUnknownFields fdefs')
              ]
  return ()

-- | Tests that an unknown field is returned as such.