Skip to content

Commit ef2260b

Browse files
committed
Fix specs
1 parent 52f22bd commit ef2260b

File tree

2 files changed

+102
-9
lines changed

2 files changed

+102
-9
lines changed

cli/test/Anti/CliSpec.hs

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23

34
module Anti.CliSpec
45
( spec
@@ -14,6 +15,8 @@ import Anti.Types
1415
, Directory (..)
1516
, Host (..)
1617
, Options (..)
18+
, OracleCommand (..)
19+
, OutputReference (..)
1720
, Platform (..)
1821
, Port (..)
1922
, PublicKeyHash (..)
@@ -26,7 +29,8 @@ import Anti.Types
2629
)
2730
import Control.Concurrent (threadDelay)
2831
import Control.Concurrent.Async (async)
29-
import Data.Aeson (Value)
32+
import Data.Aeson (Value, (.=))
33+
import Data.Aeson.Types (object)
3034
import Network.Wai.Handler.Warp (run)
3135
import System.Environment (withArgs)
3236
import Test.Hspec
@@ -51,8 +55,6 @@ anti args = do
5155
, "localhost"
5256
, "--port"
5357
, "8084"
54-
, "--token-id"
55-
, "dummyTokenId"
5658
]
5759
++ args
5860
-- Call the main function with the simulated arguments
@@ -65,13 +67,16 @@ spec :: Spec
6567
spec = beforeAll_ runDummyServer $ do
6668
it "can request user registration" $ do
6769
let args =
68-
[ "register-public-key"
70+
[ "user"
71+
, "register-public-key"
6972
, "--platform"
7073
, "github"
7174
, "--username"
7275
, "bob"
7376
, "--pubkeyhash"
7477
, "607a0d8a64616a407537edf0d9b59cf4cb509c556f6d2de4250ce15df2"
78+
, "--token-id"
79+
, "dummyTokenId"
7580
]
7681
let opts =
7782
Options
@@ -92,13 +97,16 @@ spec = beforeAll_ runDummyServer $ do
9297
`shouldReturn` (opts, dummyTxId)
9398
it "can request user unregistration" $ do
9499
let args =
95-
[ "unregister-public-key"
100+
[ "user"
101+
, "unregister-public-key"
96102
, "--platform"
97103
, "github"
98104
, "--username"
99105
, "bob"
100106
, "--pubkeyhash"
101107
, "607a0d8a64616a407537edf0d9b59cf4cb509c556f6d2de4250ce15df2"
108+
, "--token-id"
109+
, "dummyTokenId"
102110
]
103111

104112
let opts =
@@ -120,7 +128,8 @@ spec = beforeAll_ runDummyServer $ do
120128

121129
it "can request adding user to a project" $ do
122130
let args =
123-
[ "register-role"
131+
[ "user"
132+
, "register-role"
124133
, "--platform"
125134
, "github"
126135
, "--repository"
@@ -129,6 +138,8 @@ spec = beforeAll_ runDummyServer $ do
129138
, "maintainer"
130139
, "--username"
131140
, "bob"
141+
, "--token-id"
142+
, "dummyTokenId"
132143
]
133144
let opts =
134145
Options
@@ -149,7 +160,8 @@ spec = beforeAll_ runDummyServer $ do
149160

150161
it "can request removing user from a project" $ do
151162
let args =
152-
[ "unregister-role"
163+
[ "user"
164+
, "unregister-role"
153165
, "--platform"
154166
, "github"
155167
, "--repository"
@@ -158,6 +170,8 @@ spec = beforeAll_ runDummyServer $ do
158170
, "maintainer"
159171
, "--username"
160172
, "bob"
173+
, "--token-id"
174+
, "dummyTokenId"
161175
]
162176
let opts =
163177
Options
@@ -178,7 +192,8 @@ spec = beforeAll_ runDummyServer $ do
178192

179193
it "can request antithesis run" $ do
180194
let args =
181-
[ "request-test"
195+
[ "user"
196+
, "request-test"
182197
, "--platform"
183198
, "github"
184199
, "--repository"
@@ -187,6 +202,8 @@ spec = beforeAll_ runDummyServer $ do
187202
, "bob"
188203
, "--commit"
189204
, "9114528e2343e6fcf3c92de71364275227e6b16d"
205+
, "--token-id"
206+
, "dummyTokenId"
190207
]
191208
let opts =
192209
Options
@@ -204,3 +221,79 @@ spec = beforeAll_ runDummyServer $ do
204221
}
205222
}
206223
anti args `shouldReturn` (opts, dummyTxId)
224+
it "can retract a request" $ do
225+
let args =
226+
[ "user"
227+
, "retract-request"
228+
, "--tx-hash"
229+
, "dummyTxId"
230+
, "--index"
231+
, "0"
232+
]
233+
let opts =
234+
Options
235+
{ host = Host "localhost"
236+
, port = Port 8084
237+
, command =
238+
UserCommand
239+
RetractRequest
240+
{ outputReference = OutputReference "dummyTxId" 0
241+
}
242+
}
243+
anti args `shouldReturn` (opts, dummyTxId)
244+
it "can create a token" $ do
245+
let args =
246+
[ "oracle"
247+
, "create-token"
248+
]
249+
let opts =
250+
Options
251+
{ host = Host "localhost"
252+
, port = Port 8084
253+
, command =
254+
OracleCommand
255+
CreateToken
256+
}
257+
anti args
258+
`shouldReturn` ( opts
259+
, object
260+
[ "tokenId" .= ("dummyTokenId" :: String)
261+
]
262+
)
263+
it "can delete a token" $ do
264+
let args =
265+
[ "oracle"
266+
, "delete-token"
267+
, "--token-id"
268+
, "dummyTokenId"
269+
]
270+
let opts =
271+
Options
272+
{ host = Host "localhost"
273+
, port = Port 8084
274+
, command =
275+
OracleCommand
276+
(DeleteToken $ TokenId "dummyTokenId")
277+
}
278+
anti args `shouldReturn` (opts, dummyTxId)
279+
it "can get a token" $ do
280+
let args =
281+
[ "oracle"
282+
, "get-token"
283+
, "--token-id"
284+
, "dummyTokenId"
285+
]
286+
let opts =
287+
Options
288+
{ host = Host "localhost"
289+
, port = Port 8084
290+
, command =
291+
OracleCommand
292+
(GetToken $ TokenId "dummyTokenId")
293+
}
294+
anti args
295+
`shouldReturn` ( opts
296+
, object
297+
[ "tokenId" .= ("dummyTokenId" :: String)
298+
]
299+
)

cli/test/Anti/Server.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ getTokenDummy :: TokenId -> Handler Value
4444
getTokenDummy _ = return dummyTokenId
4545

4646
dummyTokenId :: Value
47-
dummyTokenId = object ["tokenId " .= ("dummyTokenId" :: String)]
47+
dummyTokenId = object ["tokenId" .= ("dummyTokenId" :: String)]
4848

4949
dummyTxId :: Value
5050
dummyTxId = object ["txId " .= ("dummyTxId" :: String)]

0 commit comments

Comments
 (0)