I have an API that has the following logic:
- Consume from Kafka.
- Process the record.
- Update the database, if the processing was successful.
- If the processing fails, then push it to a Kafka topic.
- If pushing to Kafka topic failed, then commit.
- If the record was processed successfully, then commit.
- If the commit fails, then log and move ahead with consuming the next event.
I am writing BDDs for this API. Currently, I feel like I am testing too many scenarios:
- ProcessingFailed -> Database is unchanged -> Event should be pushed to Kafka -> Should be committed.
- Kafka push failed -> Should be committed.
- Commit failed -> (what to do? Should I check if the log is printed correctly?)
- Happy path -> Database updated -> Kafka topic does not contained the event -> Commit was successful.
My question is, what's the proper way to test for such side effects?
Now suppose my process step is made of three steps:
- Fetch from the database.
- Make an HTTP call.
Now supposing that I am simulating a 'processing failed' by bringing my database down. Now do I also need to test that the HTTP call was not made?