Update tests

This commit is contained in:
Rene Vergara 2022-08-29 11:23:48 -05:00
parent ca01dd0a14
commit 4132eb3a3c
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -52,7 +52,7 @@ main = do
prop "encoding and decoding are inverse" $ \x -> prop "encoding and decoding are inverse" $ \x ->
(decodeHexText . encodeHexText) x == x (decodeHexText . encodeHexText) x == x
describe "zToZGoTx" $ do describe "zToZGoTx" $ do
it "converts zcash tx to ZGo tx" $ do it "converts ZecWallet tx to ZGo tx" $ do
let t = let t =
ZcashTx ZcashTx
"someId" "someId"
@ -73,6 +73,69 @@ main = do
0.5 0.5
"someId" "someId"
"ZGO::5d3d4494-51c0-432d-8495-050419957aea\nReply-To:\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e" "ZGO::5d3d4494-51c0-432d-8495-050419957aea\nReply-To:\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e"
it "converts YWallet tx to ZGo tx" $ do
let t =
ZcashTx
"someId"
0.5
50000000
1602000
18732456
False
20
"fjbMSG\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e\nZGO::5d3d4494-51c0-432d-8495-050419957aea"
zToZGoTx t `shouldBe`
ZGoTx
Nothing
"zs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e"
"5d3d4494-51c0-432d-8495-050419957aea"
20
18732456
0.5
"someId"
"fjbMSG\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e\nZGO::5d3d4494-51c0-432d-8495-050419957aea"
it "converts ZecWallet payment tx to ZGo tx" $ do
let t =
ZcashTx
"someId"
0.5
50000000
1602000
18732456
False
20
"ZGOp::5d3d4494-51c0-432d-8495-050419957aea\nReply-To:\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e"
zToZGoTx t `shouldBe`
ZGoTx
Nothing
""
"5d3d4494-51c0-432d-8495-050419957aea"
20
18732456
0.5
"someId"
"ZGOp::5d3d4494-51c0-432d-8495-050419957aea\nReply-To:\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e"
it "converts YWallet payment tx to ZGo tx" $ do
let t =
ZcashTx
"someId"
0.5
50000000
1602000
18732456
False
20
"fjbMSG\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e\nZGOp::5d3d4494-51c0-432d-8495-050419957aea"
zToZGoTx t `shouldBe`
ZGoTx
Nothing
""
"5d3d4494-51c0-432d-8495-050419957aea"
20
18732456
0.5
"someId"
"fjbMSG\nzs1w6nkameazc5gujm69350syl5w8tgvyaphums3pw8eytzy5ym08x7dvskmykkatmwrucmgv3er8e\nZGOp::5d3d4494-51c0-432d-8495-050419957aea"
describe "PIN generator" $ do describe "PIN generator" $ do
it "should give a 7 digit" $ do it "should give a 7 digit" $ do
length (T.unpack (unsafePerformIO (generatePin 1010))) `shouldBe` 7 length (T.unpack (unsafePerformIO (generatePin 1010))) `shouldBe` 7
@ -103,12 +166,6 @@ main = do
req <- testGet "/api/xero" [] req <- testGet "/api/xero" []
res <- httpJSON req res <- httpJSON req
getResponseStatus (res :: Response A.Value) `shouldBe` ok200 getResponseStatus (res :: Response A.Value) `shouldBe` ok200
describe "xero token endpoint" $ do
prop "save token" testTokenAdd
it "return token" $ do
req <- testGet "/api/xerotoken" [("address", Just "Zaddy")]
res <- httpLBS req
getResponseStatus res `shouldBe` ok200
describe "User endpoint" $ do describe "User endpoint" $ do
it "returns a user for a session" $ do it "returns a user for a session" $ do
req <- req <-
@ -287,8 +344,10 @@ main = do
Nothing Nothing
"Zaddy" "Zaddy"
"superFakeToken123" "superFakeToken123"
(UTCTime (fromGregorian 2022 9 16) (secondsToDiffTime 0)) 1800
"anotherSuperFakeToken" "anotherSuperFakeToken"
(UTCTime (fromGregorian 2022 9 16) (secondsToDiffTime 0))
(UTCTime (fromGregorian 2022 9 16) (secondsToDiffTime 0))
_ <- access p master "test" $ upsertToken myToken _ <- access p master "test" $ upsertToken myToken
t <- access p master "test" $ findToken "Zaddy" t <- access p master "test" $ findToken "Zaddy"
let t1 = (cast' . Doc) =<< t let t1 = (cast' . Doc) =<< t
@ -483,14 +542,6 @@ testItemAdd i = do
res <- httpLBS req res <- httpLBS req
assert $ getResponseStatus res == created201 assert $ getResponseStatus res == created201
testTokenAdd :: XeroToken -> Property
testTokenAdd t = do
monadicIO $ do
req <-
run $ testPostJson "/api/xerotoken" (A.object ["payload" A..= A.toJSON t])
res <- httpLBS req
assert $ getResponseStatus res == created201
-- | Open the MongoDB connection -- | Open the MongoDB connection
openDbConnection :: IO Pipe openDbConnection :: IO Pipe
openDbConnection = do openDbConnection = do
@ -670,4 +721,6 @@ instance Arbitrary XeroToken where
a <- arbitrary a <- arbitrary
t <- arbitrary t <- arbitrary
e <- arbitrary e <- arbitrary
XeroToken i a t e <$> arbitrary r <- arbitrary
aD <- arbitrary
XeroToken i a t e r aD <$> arbitrary