Service Testing and GitHub Testing Action Workflow #67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ℹ️ Issue
Closes #98 #99,
📝 Description
For this PR, I used the
orders.service.spec.tsfile to show an example of how to setup the service testing to actually use a local database representation for testing. The testing follows these steps:This was all accomplished by creating a
DataSourceOptionsobject, which utilizes the database configurations in the .env file to run all of the migrations that we need to properly spin up an accurate database. We then utilize his data source in each of our service tests so they can properly connect to the test database, and run the above steps.With this change, we now no longer need any form of mocking in the service, and can just call the database normally, like we have been doing in the service functions. NOTE: It is important that the data we use though matches the data from the
CreateDummyDatamigration. Therefore, it is crucial that we are very aware of the changes we make to this migration moving forward, so that we are not breaking other tests.I also setup a GitHub action workflow to setup the exact dependencies and perform this workflow automatically on any pull request or push made to the repository.
✔️ Verification
I made sure that all tests passed both locally, and on GitHub actions. To test (which the reviewer should do), follow these steps:
DATABASE_NAME_TESTand assign it to "securing-safe-food-test". This will allow the specific database to be affected, rather than the one we are using in development.npx jest, and observe that all of the tests pass.🏕️ (Optional) Future Work / Notes
typeorm.tsfile, we need to do the same with thetypeormTestDataSource.tsfile as well. It should be pretty self-explanatory on how to do it based on the structure.