diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-27 09:09:13 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-27 09:09:13 -0500 |
| commit | dc1b9c834f3c1d38f46c4fedad00a91718f76cb9 (patch) | |
| tree | dba95896bb0afcf50dedaa3d2eda315eeac3b872 /Omni/Task.hs | |
| parent | f929bb23f9b55df81697579065cfeb42c4376799 (diff) | |
jr: Fix empty query param parsing and use XDG for db path
- FromHttpApiData instances return Left for empty strings (Servant
treats as missing param for QueryParam Maybe)
- getTasksDbPath now uses ~/.local/share/jr/jr.db via XDG - Remove
standalone task binary output - Add tests for parseQueryParam on
Priority/Status
Task-Id: t-145, t-146 Amp-Thread-ID:
https://ampcode.com/threads/T-2ad5310f-b7f5-451d-ad9b-35aa17c58774
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni/Task.hs')
| -rw-r--r-- | Omni/Task.hs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Omni/Task.hs b/Omni/Task.hs index 117d862..07883ac 100644 --- a/Omni/Task.hs +++ b/Omni/Task.hs @@ -3,9 +3,7 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} --- : out task -- : dep sqlite-simple --- : modified by benign worker module Omni.Task where import Alpha @@ -21,6 +19,7 @@ import qualified System.Console.Docopt as Docopt import System.Directory (createDirectoryIfMissing, doesFileExist, removeFile) import System.Environment (setEnv) import qualified Test.Tasty as Tasty +import Web.HttpApiData (parseQueryParam) import Prelude (read) main :: IO () @@ -618,7 +617,27 @@ unitTests = -- The test should probably fail if we have multiple tasks that match the same ID case-insensitively. let matches = filter (\t -> matchesId (taskId t) upperId) tasks - length matches Test.@?= 2 + length matches Test.@?= 2, + Test.unit "FromHttpApiData Priority: empty string returns Left" <| do + let result = parseQueryParam "" :: Either Text Priority + case result of + Left _ -> pure () + Right _ -> Test.assertFailure "Empty string should return Left", + Test.unit "FromHttpApiData Priority: valid values parse correctly" <| do + (parseQueryParam "P0" :: Either Text Priority) Test.@?= Right P0 + (parseQueryParam "P1" :: Either Text Priority) Test.@?= Right P1 + (parseQueryParam "P2" :: Either Text Priority) Test.@?= Right P2 + (parseQueryParam "P3" :: Either Text Priority) Test.@?= Right P3 + (parseQueryParam "P4" :: Either Text Priority) Test.@?= Right P4, + Test.unit "FromHttpApiData Status: empty string returns Left" <| do + let result = parseQueryParam "" :: Either Text Status + case result of + Left _ -> pure () + Right _ -> Test.assertFailure "Empty string should return Left", + Test.unit "FromHttpApiData Status: valid values parse correctly" <| do + (parseQueryParam "Open" :: Either Text Status) Test.@?= Right Open + (parseQueryParam "InProgress" :: Either Text Status) Test.@?= Right InProgress + (parseQueryParam "Done" :: Either Text Status) Test.@?= Right Done ] -- | Test CLI argument parsing to ensure docopt string matches actual usage |
