Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Server Side Tests #221

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

smallrussian
Copy link

Fixes #212

What was changed?

Added a new test file: server/tests/rest/service_shift/test_service_shift.py, which contains unit tests for the /service_shift REST API endpoint.
Updated the import paths and patch decorators within the test file to ensure proper resolution of modules when running tests from different directories.

Why was it changed?

Issue #212 highlighted that there were no test cases for the /service_shift endpoint.
This change ensures that both the GET and POST methods for the endpoint are covered by automated tests. It protects against regressions by verifying that the endpoint returns the correct responses when interacting with mocked business logic components.

How was it changed?

Test File Creation:
A new file, server/tests/rest/service_shift/test_service_shift.py, was created. This file contains two main tests:
    A POST test that sends a JSON payload with proper headers, mocks the shift_add_use_case, and asserts that the endpoint returns a 200 status code along with the expected JSON response.
    A GET test that mocks the service_shifts_list_use_case and asserts that the endpoint returns a predefined list of shifts.

Import and Patch Updates:
To resolve module import issues, the import statements in the test file were updated to use relative paths (e.g., from application.rest.service_shifts import app), and the patch decorators were adjusted accordingly (e.g., @patch('application.rest.service_shifts.shift_add_use_case')). This ensures the tests run correctly both locally and in GitHub Actions.

Testing Framework:
The tests leverage Python’s unittest framework and use unittest.mock.patch to isolate the REST API layer from its underlying business logic, ensuring that only the API behavior is verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add data validation to the server side
1 participant