Merry Christmas everybody!
Has somebody used Node.Express.Test.Mock
before?
In the real app I have something like
manageRequests :: Handle -> App
manageRequests h = do
useExternal jsonBodyParser
get "/v1/users" $ listUsers h
get "/v1/user/:id" $ getUser h
post "/v1/users" $ createUser h
and in test
showResponse :: User -> MockResponse -> TestMockApp
showResponse expected response = liftEffect $ log response.data
testServer :: Free TestF Unit
testServer =
testExpress "GET"
$ do
setupMockApp $ manageRequests
sendTestRequest GET "http://example.com/v1/users" $ assertData $ encodeJSON listUsersValue
sendRequest GET "http://example.com/v1/user/1" withRouteParam $ showResponse findUserRightValue
sendRequest POST "http://example.com/v1/users" withBody $ showResponse insertUserRightValue
where
withRouteParam = setRouteParam "id" "1"
withBody = setBody $ encodeJSON insertUserRightValue
All requests succeed with the real implementation. In test only the first request is going through. The second does not work unless, :id
is hardcoded to 1. The last request returns
{"errors":{"value0":"Error at array index 0: Error at property \"name\": Type mismatch: expected String, found Undefined","value1":{}}}
should be {"id":1,"name":"user1"}
.
Are route param replacement and the body parser not suppose to work in Mock?