-
Notifications
You must be signed in to change notification settings - Fork 25
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
Improve Test Coverage #74
Conversation
@Brayden PTAL. I will test each function cleanly, push the code from on and have fixed few issues found too |
@Brayden Test coverage is good so far and few issues have been found in the DELETE operation so I have commented. I will take a close look fix it and improve some more files' test coverage to reach ~85-90 |
@Brayden It's weekend and I am out . I will push final remaining changes by tomorrow |
@varshith257 No worries. I was just updating your PR so it didn't have merge conflicts. I introduced a couple test changes so a report could be displayed on new PR's. I ran the test coverage here and figured I'd share: ![]() Also do you recall what error you were getting for DELETE operations? Curious to what bug was uncovered! |
@Brayden I can't remember what exactly found as I kept in a notes in my desktop but what i remember is it throwing bad request instead executing delete operation For example check this
and this too
It throwing 500 instead 400 above and delete query succes. I need to go another round of their implementation to validate whether I am wrongly testing the method or need a fix there. To capitalise i have commented and just console logged their results but here mock data receiving perfectly to the DELTE but when executed final result is getting undefined |
@varshith257 Wanted to check in and see if you had more ready to push up or not! :) |
@Brayden Sorry for the inconvenience. Actually I had on holiday from last 3 days so didn't push changes here. I am back and on the work |
@Brayden I will push the remainging changes by EOD. And maybe your eye on them would be good as some of tests are frequently failing as i am testing them wrong or maybe that tests we don't need |
Of course @varshith257, happy to take a look at the tests and verify them 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Brayden This is the failing test I don't know where it going wrong here as id receiving as undefined after pasing request
I'll take a look at this! |
@varshith257 It looks like in the We should probably do:
For the delete operation since the schema is missing and the last path value is the identifier it's acting as if no primary key identifier was passed into it so it doesn't know exactly what to delete. |
I am writing tests for rls then we are good to go hit >75 |
This reverts commit 3eeff5b.
}) | ||
}) | ||
|
||
describe('applyRLS - Multi-Table Queries', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Brayden Am I missing something here to test JOINS? Currently it returning the sql what we specified in test and not applying applyRLS to sql
]) | ||
}) | ||
|
||
it('should modify SELECT queries with WHERE conditions', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here too for SELECT
case the applyRLS isn't applying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this loading the policies like you do in the loadPolicies
test? It should check the policies and if a policy exists for a particular table (in this case users
) then it should be applied. I don't see the policies in play in this test but I could be missing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait I see it in the beforeEach
above this 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like if I convert the schema
from "public" to an empty string I get this result for this test, which probably indicates an issue in the code that should handle default schemas.:
FAIL src/rls/index.test.ts > applyRLS - Query Modification > should modify SELECT queries with WHERE conditions
AssertionError: expected 'SELECT * FROM `users` WHERE (`users`.…' to contain 'WHERE `user_id` = \'user123\''
Expected: "WHERE `user_id` = 'user123'"
Received: "SELECT * FROM `users` WHERE (`users`.`user_id` = 'user123')"
❯ src/rls/index.test.ts:114:29
112| it('should modify UPDATE queries with additional WHERE clause', async () => {
113| const sql = "UPDATE users SET name = 'Bob' WHERE age = 25"
114| const modifiedSql = await applyRLS({
| ^
115| sql,
116| isEnabled: true,
@Brayden I think there are till related issues for rls please check if wriitten tests are missing something or the implemetation lacks it. I have also found related issues in import and do files too. Do I push the tests here or lets ignore for now. I am thinking to wrap up this bounty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This serves as a great foundation for tests for the entire project. Moving forward with approving this to open up opportunities to start resolving some of the failed tests identified. Thanks for all of your hard work on this effort!
Purpose
This PR aims to increase the test coverage of the StarbaseDB project to 75%+ using Vitest. The improvements ensure meaningful tests that not only improve line coverage but also help detect potential issues by testing different scenarios and edge cases and fixed few of them too
Tasks
Added unit tests
Fixed found issues too
[ ]
Verify
Before
After
/claim #71