Re:Is it only me that mocking server API is sooo hard?
by whateveracct on Thursday August 11, 2022 @03:32PM
(#32430630)
The mock is just an in-memory implementation of the service API I'm mocking. It's a bit more complex, but you have APIs to create entities, fetch them by id, etc. And you actually generate ids, store them, query them.
So for, say, the Slack API. You'd create a workspace and some channels. Send some messages. And then when you ask for the chat history of a channel, it'll be the actual messages you send.
Slack is a bit more complicated because it would also include webhooks. Not impossible to wire up and send realistic ones. But it's of course more (fixed-cost) work. But if your business relies on this API so much, maybe it's worth it.
The fun part is if you do it this way, you can - in theory at least - run your test suite both against your mock and against the real thing.
The big killer feature here is servant and Haskell make it relatively easy to do this. The code is not complicated and it's hard to mess up. It can just be tedious. But it's good work for a junior engineer or new hire or intern to do.
So for, say, the Slack API. You'd create a workspace and some channels. Send some messages. And then when you ask for the chat history of a channel, it'll be the actual messages you send.
Slack is a bit more complicated because it would also include webhooks. Not impossible to wire up and send realistic ones. But it's of course more (fixed-cost) work. But if your business relies on this API so much, maybe it's worth it.
The fun part is if you do it this way, you can - in theory at least - run your test suite both against your mock and against the real thing.
The big killer feature here is servant and Haskell make it relatively easy to do this. The code is not complicated and it's hard to mess up. It can just be tedious. But it's good work for a junior engineer or new hire or intern to do.