@@ -2,6 +2,7 @@ module ClientResultTests
22
33open Expecto
44open Fossa.Bridge .Models .ApiModels
5+ open Fossa.Bridge .Models .ApiModels .Helpers
56
67let private problem =
78 { Type = " https://example.com/problems/conflict"
@@ -14,74 +15,18 @@ let private problem =
1415let tests =
1516 testList
1617 " ClientResultTests"
17- [ testList
18- " ClientResult helpers"
19- [ testCase " success helpers expose the value"
20- <| fun _ ->
21- let result = ClientResult.Success 21
18+ [ testCase " success helper creates success result"
19+ <| fun _ ->
20+ let result = ClientResultHelpers.success " bridge"
2221
23- Expect.isTrue ( ClientResult.isSuccess result) " Success should be success"
24- Expect.isFalse ( ClientResult.isProblem result) " Success should not be problem"
22+ Expect.isTrue result.Succeeded " Success should be success"
23+ Expect.equal result.Value " bridge" " Value should be set"
24+ Expect.isNull result.Problem " Problem should be absent"
2525
26- Expect.equal
27- ( ClientResult.map ((*) 2 ) result)
28- ( ClientResult.Success 42 )
29- " Map should transform value"
26+ testCase " problem helper creates problem result"
27+ <| fun _ ->
28+ let result : ClientResult < string > = ClientResultHelpers.problem problem
3029
31- Expect.equal ( ClientResult.defaultValue 0 result) 21 " Default value should not be used"
32- Expect.equal ( ClientResult.valueOrDefault result) 21 " Value should be returned"
33- Expect.equal ( ClientResult.valueOrNone result) ( Some 21 ) " Value option should be present"
34- Expect.equal ( ClientResult.problemOrNone result) None " Problem option should be absent"
35-
36- testCase " problem helpers expose the problem"
37- <| fun _ ->
38- let result : ClientResult < int > = ClientResult.Problem problem
39-
40- Expect.isFalse ( ClientResult.isSuccess result) " Problem should not be success"
41- Expect.isTrue ( ClientResult.isProblem result) " Problem should be problem"
42-
43- Expect.equal
44- ( ClientResult.map ((*) 2 ) result)
45- ( ClientResult.Problem problem)
46- " Map should preserve problem"
47-
48- Expect.equal
49- ( ClientResult.bind ( fun value -> ClientResult.Success( value * 2 )) result)
50- ( ClientResult.Problem problem)
51- " Bind should preserve problem"
52-
53- Expect.equal ( ClientResult.defaultValue 42 result) 42 " Default value should be used"
54- Expect.equal ( ClientResult.valueOrDefault result) 0 " Default int should be returned"
55- Expect.equal ( ClientResult.valueOrNone result) None " Value option should be absent"
56- Expect.equal ( ClientResult.problemOrNone result) ( Some problem) " Problem option should be present" ]
57-
58- testList
59- " ClientUnitResult helpers"
60- [ testCase " success converts to generic unit success"
61- <| fun _ ->
62- let result = ClientUnitResult.Success
63-
64- Expect.isTrue ( ClientUnitResult.isSuccess result) " Success should be success"
65- Expect.isFalse ( ClientUnitResult.isProblem result) " Success should not be problem"
66- Expect.equal ( ClientUnitResult.problemOrNone result) None " Problem option should be absent"
67-
68- Expect.equal
69- ( ClientUnitResult.toGeneric result)
70- ( ClientResult.Success())
71- " Generic result should be success"
72-
73- testCase " problem converts through generic unit result"
74- <| fun _ ->
75- let result = ClientUnitResult.Problem problem
76- let generic = ClientUnitResult.toGeneric result
77-
78- Expect.isFalse ( ClientUnitResult.isSuccess result) " Problem should not be success"
79- Expect.isTrue ( ClientUnitResult.isProblem result) " Problem should be problem"
80-
81- Expect.equal
82- ( ClientUnitResult.problemOrNone result)
83- ( Some problem)
84- " Problem option should be present"
85-
86- Expect.equal generic ( ClientResult.Problem problem) " Generic result should preserve problem"
87- Expect.equal ( ClientUnitResult.ofGeneric generic) result " Unit result should round-trip" ] ]
30+ Expect.isFalse result.Succeeded " Problem should not be success"
31+ Expect.isNull ( box result.Value) " Value should be absent"
32+ Expect.equal result.Problem problem " Problem should be set" ]
0 commit comments