Skip to content

Commit

Permalink
[#500] Trails-tests: Add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-stacey committed Aug 19, 2019
1 parent 9288093 commit 3b2b892
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion projects/trails/test/Mirza/Trails/Tests/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,24 @@ clientSpec = do
-- :
-- *---*---*
-- Note: ':' Denotes matching eventId (but otherwise distinct trails).
-- TODO:
let buildCommonEventIdDistinctTrails = do
topInput <- buildTwoEntryTrail
bottomTrail <- join $ fmap addNextEntry $ updateFirstEventId (trailEntryEventID $ head topInput) <$> buildTwoEntryTrail
topTrail <- addNextEntry $ topInput
pure $ topTrail <> bottomTrail
commonEventIdDistinctTrails <- buildCommonEventIdDistinctTrails
checkTrailWithContext "Two Distinct Trails with a common EventId mid trail" commonEventIdDistinctTrails

-- Trail: *---*---*
-- :
-- *---*---*
-- Note: ':' Denotes matching eventId (but otherwise distinct trails).


-- Trail: *---*---*
-- :
-- *---*---*
-- Note: ':' Denotes matching eventId (but otherwise distinct trails).

-- Trail: *---*---\
-- : *
Expand Down Expand Up @@ -293,6 +309,14 @@ addNextEntry [] = error "Error: There is a logic error in the tests. Can't add t
addPreviousEntrySignature :: TrailEntry -> SignaturePlaceholder -> TrailEntry
addPreviousEntrySignature entry sig = entry{trailEntryParentSignatures = sig : (trailEntryParentSignatures entry)}

updateFirstEventId :: EventId -> [TrailEntry] -> [TrailEntry]
updateFirstEventId eventId (entry : entries) = (updateEventId eventId entry) : entries
-- Could just define the following as NOP, but it seems that this is likely to be a logic error and so its probably better to just fail here.
updateFirstEventId _ [] = error "Error: There is a logic error in the tests. Can't add the update the EventId a non existant entry."

updateEventId :: EventId -> TrailEntry -> TrailEntry
updateEventId eventId entry = entry{trailEntryEventID = eventId} -- TODO: Need to resign at this point...


shouldMatchTrail :: (Show a, Eq a) => Either a [TrailEntry] -> [TrailEntry] -> Expectation
shouldMatchTrail actual@(Left _) _ = actual `shouldSatisfy` isRight
Expand Down

0 comments on commit 3b2b892

Please sign in to comment.