leldridg / swesp2024

2 stars 2 forks source link

[medium] frontend tests commit transactions directly to the the database #69

Closed leldridg closed 6 months ago

leldridg commented 7 months ago

When you any test in the frontend.queries.test file, a new token is generated for the admin user and this token is committed to the database.

I have tried using db.query('BEGIN') and db.query('ROLLBACK') in several ways to avoid this, but I can't seem to figure out a way to get around committing these changes to the database without issues.

For reference, when you try to use the begin/rollback around the generateToken function, it will only rollback the removeToken query inside the function, and not the changes made by all of the queries in the function. If you try to use the begin/rollback around a single query (e.g., insertToken), other issues occur that cause the server to crash.

leldridg commented 6 months ago

I have managed to make this fix, but it's worth noting that making the fix results in all of the tests for non-admin users failing and the node server crashing (at least, for now). The issue here was "fixed" by adding the following lines to the top of the file and using a single-query function (insertToken) to temporarily add a test token/session_id to the database instead of using the generateToken function (which contains several queries within it).

`beforeEach(async () => { await db.query('BEGIN;'); });

afterEach(async () => { await db.query('ROLLBACK;'); });`

I think I'm going to opt to keep this version of the frontend tests over the other version, as I believe that avoiding commits to the production database may be more important than trying to get more tests to pass. I do, however, want to acknowledge that it's kind of strange that most of these non-admin tests were passing prior to making this change when they aren't now.

leldridg commented 6 months ago

Node server and non-admin user fails fixed (for the most part). The logic on the edit-product page was messing up on the admin tests, resulting in the non-admin tests failing afterwards due to the node server crashing. A few of the front-end tests are still failing for unclear reasons. Namely, the addProduct page tests for urls with session ids.