|
| 1 | +module StatusCodeHelpersTests |
| 2 | + |
| 3 | +open Expecto |
| 4 | +open Fossa.Bridge.Models.ApiModels |
| 5 | +open Fossa.Bridge.Services.StatusCodeHelpers |
| 6 | + |
| 7 | +let private problemWithStatus status = |
| 8 | + { Type = null |
| 9 | + Title = null |
| 10 | + Status = status |
| 11 | + Detail = null |
| 12 | + Instance = null } |
| 13 | + |
| 14 | +[<Tests>] |
| 15 | +let tests = |
| 16 | + testList |
| 17 | + "StatusCodeHelpersTests" |
| 18 | + [ testList |
| 19 | + "isStatusCodeClientError" |
| 20 | + [ testCase "returns false below 400" |
| 21 | + <| fun _ -> Expect.isFalse (isStatusCodeClientError 399) "399 should not be a client error" |
| 22 | + |
| 23 | + testCase "returns true at 400" |
| 24 | + <| fun _ -> Expect.isTrue (isStatusCodeClientError 400) "400 should be a client error" |
| 25 | + |
| 26 | + testCase "returns true at 499" |
| 27 | + <| fun _ -> Expect.isTrue (isStatusCodeClientError 499) "499 should be a client error" |
| 28 | + |
| 29 | + testCase "returns false at 500" |
| 30 | + <| fun _ -> Expect.isFalse (isStatusCodeClientError 500) "500 should not be a client error" ] |
| 31 | + |
| 32 | + testList |
| 33 | + "isStatusCodeServerError" |
| 34 | + [ testCase "returns false at 499" |
| 35 | + <| fun _ -> Expect.isFalse (isStatusCodeServerError 499) "499 should not be a server error" |
| 36 | + |
| 37 | + testCase "returns true at 500" |
| 38 | + <| fun _ -> Expect.isTrue (isStatusCodeServerError 500) "500 should be a server error" |
| 39 | + |
| 40 | + testCase "returns true at 599" |
| 41 | + <| fun _ -> Expect.isTrue (isStatusCodeServerError 599) "599 should be a server error" |
| 42 | + |
| 43 | + testCase "returns false at 600" |
| 44 | + <| fun _ -> Expect.isFalse (isStatusCodeServerError 600) "600 should not be a server error" ] |
| 45 | + |
| 46 | + testList |
| 47 | + "ProblemDetailsModel helpers" |
| 48 | + [ testCase "client problem returns client true and server false" |
| 49 | + <| fun _ -> |
| 50 | + let problem = problemWithStatus 404 |
| 51 | + |
| 52 | + Expect.isTrue (isClientProblem problem) "4xx problem should be a client problem" |
| 53 | + Expect.isFalse (isServerProblem problem) "4xx problem should not be a server problem" |
| 54 | + |
| 55 | + testCase "server problem returns server true and client false" |
| 56 | + <| fun _ -> |
| 57 | + let problem = problemWithStatus 500 |
| 58 | + |
| 59 | + Expect.isTrue (isServerProblem problem) "5xx problem should be a server problem" |
| 60 | + Expect.isFalse (isClientProblem problem) "5xx problem should not be a client problem" |
| 61 | + |
| 62 | + testCase "non-error problem returns false for both helpers" |
| 63 | + <| fun _ -> |
| 64 | + let problem = problemWithStatus 200 |
| 65 | + |
| 66 | + Expect.isFalse (isClientProblem problem) "Non-error problem should not be a client problem" |
| 67 | + Expect.isFalse (isServerProblem problem) "Non-error problem should not be a server problem" ] ] |
0 commit comments