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

Add HTTP tests for /source route #2036

Conversation

AlexeySachkov
Copy link
Member

This PR introduces a few tests for /source route, which check that the app is able to correctly retrieve brew sources and send them back to user. It also introduces a very basic mock for GoogleActions module so we can run HTTP tests without actual access to Google Drive servers.

@calculuschild calculuschild added the P3 - low priority Obscure tweak or fix for a single user label Mar 27, 2022
Comment on lines +93 to +95
afterAll(()=>{
return Homebrew.model.deleteMany();
});
Copy link
Member

@calculuschild calculuschild Apr 2, 2022

Choose a reason for hiding this comment

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

@AlexeySachkov Um.... this deletes all brews in the database, not just the tested ones. Just ran it on my local install and sure enough, everything was deleted. We definitely don't want this running on the live server.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good thing that you have spotted that. Actually, I would expect tests to be connected to a different DB, because they are launched under "test" node environment. Probably I don't fully understand the API to work with Mongo here.

I suggest we block this PR from an accidental merge by explicitly requesting changes

Copy link
Member Author

Choose a reason for hiding this comment

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

@calculuschild , sorry that it took so long for me to respond here, but I finally figured it out: what you saw is indeed happening. The reason for that is that even in tests we by default connect to the main database.

In 6a2581e I added config/test.json to override database in test environment.

However, there is still caveat: jest sets NODE_ENV=test only if NODE_ENV is not set yet (link to docs). So, in local environment where you likely have NODE_ENV=local, it won't work.

I wonder what would be the preferred way of handling that? I doubt that ignoring database cleanup in local environment is a good idea, because someone who has local database with their brews won't be happy to see them all removed just by (possibly accidentally) running tests. We could update package.json to include NODE_ENV=test to all test-related commands, but I'm concerned that we might miss some, because there are 4 of them already.

Copy link
Member

@calculuschild calculuschild left a comment

Choose a reason for hiding this comment

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

Test needs fixing to not delete the live database.

@calculuschild calculuschild added the 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging label Apr 3, 2022
@calculuschild calculuschild temporarily deployed to homebrewery-pr-2036 April 24, 2023 18:53 Inactive
@dbolack-ab
Copy link
Collaborator

Do the two new commits fix the requested change?

@calculuschild
Copy link
Member

Still not fixed.

@5e-Cleric 5e-Cleric added Orphan This project's original dev is not going to finish this, feel free to pick it up and removed P3 - low priority Obscure tweak or fix for a single user labels Aug 22, 2024
@dbolack-ab
Copy link
Collaborator

Do we need this route?

@calculuschild
Copy link
Member

Do we need this route?

I don't know how often /source gets used, but its been around for years at this point. I don't think we need to get rid of it given we just spent a lot of effort adding /css.

@5e-Cleric
Copy link
Member

I'd say we can close this, and maybe start from scratch, what is the issue? we should log it as an issue.

@dbolack-ab
Copy link
Collaborator

I'd say we can close this, and maybe start from scratch, what is the issue? we should log it as an issue.

Makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Orphan This project's original dev is not going to finish this, feel free to pick it up 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add HTTP tests for /source route, and mock for googleActions
4 participants