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

Lf 4170 create or modify animal enum tables #3252

Open
wants to merge 14 commits into
base: integration
Choose a base branch
from

Conversation

navDhammu
Copy link
Collaborator

@navDhammu navDhammu commented Jun 20, 2024

Description

This PR includes some migrations, api for /animal_identifier_types and some small changes to the animal_identifier_placements api as specified in ticket: https://lite-farm.atlassian.net/browse/LF-4170

While working on this I had some issues with some of the tests. I'm not sure if its just me but when I create a new test database and run the migrations on it, I get some errors when trying to run individual files like animal_identifier_test (and some other files too). Its happening because initially the database has several constant tables with values already present in them like animal colors and placements, and the cleanup is done in the afterEach method which means that when the first test is executed the tables are not in an empty state and this is resulting in some errors. It doesn't happen when you run all the tests with npm run test because the test that runs first doesn't rely on any non-empty tables so when its finished, the cleanup is done in afterEach and all subsequent tests run with a clean state making all tests pass.

Going further on this topic, I had some ideas on improving on the overall testing strategy. Rather than running a cleanup of the whole db after each test, it may be better to run each test in a transaction and rollback once its complete, potentially eliminating the need to manually do the cleanup and maintain a list of tables that need to be cleaned in testEnvironment.js. Also it might make the tests run a bit faster.

If the dev team @Duncan-Brain , @SayakaOno , @kathyavini is alright with this, I can try to create a sample PR as a proof of concept.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@navDhammu navDhammu marked this pull request as ready for review June 21, 2024 03:25
@navDhammu navDhammu requested review from a team as code owners June 21, 2024 03:25
@navDhammu navDhammu requested review from Duncan-Brain and SayakaOno and removed request for a team June 21, 2024 03:25

export const up = async function (knex) {
// Synchronize the permissions_permission_id_seq sequence with the latest permission_id value.
await knex.raw(`
Copy link
Collaborator Author

@navDhammu navDhammu Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to let the db auto generate the permission id for new rows because it's currently out of sync and you have to manually look it up and add it in.

@Duncan-Brain
Copy link
Collaborator

@navDhammu Sorry it is taking a little longer to review than normal! We have had a lot of unexpected coding challenges happen this month and have been focusing on the Soil Health V1 ready for release. Apologies if it take a little longer.

In my opinion -- I really dislike our existing backend tests haha. So I am definitely open to that POC/discussion sometime after this release! My pet peeves with the tests are:

  • cleaning up enum tables unnecessarily
  • not testing the routes directly -- testing the db too much (with knex insertions)
  • knex is used liberally without the trx object
  • generally hard to navigate

@navDhammu
Copy link
Collaborator Author

@Duncan-Brain No worries!

Btw, not related to this ticket but I worked on an experimental PR which I thought might be useful. Once you have the time, if you can have a look and provide some feedback that would be appreciated!

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