Appearance
Controller File Prompt
Use the following prompt to generate the unit test for the controller file.
javascript
Unit Test For Class: SampleController (extends BaseController).
Write comprehensive unit tests using Jest for all existing methods in the controller layer. Ensure that the controller's methods are tested in isolation from the service layer and other dependencies using mock objects. Remember all existing methods in active controller.
## Import
- Import required modules – Import the necessary controller, services, and helpers for the specific controller.
## Mock Dependencies
- Use jest.mock to mock services and helper functions related to the new controller.
- Service Layer (mandatory) : All the service methods should be mocked, as we don't want to interact with the real business logic in unit tests for controllers.
- Request and Response objects (mandatory) : Use Jest's mock functions to create req and res objects
- Other dependencies (optional) : Mock any other dependencies used by the controller if used in the controller like base controller, base service, transformers, configuration, logging.
## Test Scenario
- Test all the methods in the controller layer.
- Test the methods in the controller layer should not have any side effects.
- Test the methods in the controller layer should not interact with the service or other dependencies.
- Test the methods in the controller layer should not interact with the database.