-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken SQL query for counting tasks
- Loading branch information
Showing
6 changed files
with
116 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module LibSpec where | ||
|
||
import Protolude ( | ||
Maybe (..), | ||
Text, | ||
pure, | ||
show, | ||
($), | ||
) | ||
import Protolude qualified as P | ||
|
||
import Config (defaultConfig) | ||
import Test.Hspec ( | ||
Spec, | ||
describe, | ||
it, | ||
shouldBe, | ||
) | ||
|
||
import Lib (countTasks, insertTags, insertTask) | ||
import Task (Task (body, ulid), zeroTask) | ||
import TestUtils (withMemoryDb) | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
describe "Lib" $ do | ||
it "counts tasks" $ do | ||
withMemoryDb defaultConfig $ \memConn -> do | ||
let | ||
task1 = | ||
zeroTask | ||
{ ulid = "01hs68z7mdg4ktpxbv0yfafznq" | ||
, body = "New task" | ||
} | ||
task2 = | ||
zeroTask | ||
{ ulid = "01hs690f9hkzk9z7zews9j2k1d" | ||
, body = "New task" | ||
} | ||
|
||
count0 <- countTasks defaultConfig memConn P.mempty | ||
show count0 `shouldBe` ("0" :: Text) | ||
|
||
insertTask memConn task1 | ||
count1 <- countTasks defaultConfig memConn P.mempty | ||
show count1 `shouldBe` ("1" :: Text) | ||
|
||
insertTask memConn task2 | ||
count2 <- countTasks defaultConfig memConn P.mempty | ||
show count2 `shouldBe` ("2" :: Text) | ||
|
||
insertTags memConn Nothing task2 ["test"] | ||
countWithTag <- countTasks defaultConfig memConn (Just ["+test"]) | ||
show countWithTag `shouldBe` ("1" :: Text) | ||
|
||
pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module TestUtils where | ||
|
||
import Protolude ( | ||
IO, | ||
($), | ||
) | ||
|
||
import Database.SQLite.Simple qualified as Sql | ||
|
||
import Config (Config (..)) | ||
import Migrations (runMigrations) | ||
|
||
|
||
withMemoryDb :: Config -> (Sql.Connection -> IO a) -> IO a | ||
withMemoryDb conf action = | ||
Sql.withConnection ":memory:" $ \memConn -> do | ||
_ <- runMigrations conf memConn | ||
action memConn |