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

[Question] How to use views in tests? #425

Open
callumfrance opened this issue Jun 12, 2023 · 0 comments
Open

[Question] How to use views in tests? #425

callumfrance opened this issue Jun 12, 2023 · 0 comments

Comments

@callumfrance
Copy link

Context

In my MongoDB cluster, I have a database userDB with the collection users. This userDB.users collection has a property status which can either have the value active or deleted.

I have also created a mongodb view users.notDeleted. This read-only view performs a simple $match aggregation on users to just provide all users that have not been
marked as deleted.

Screenshot 2023-06-12 at 12 02 25 pm

MongoDB Compass sidebar indicating the structure of DB, view, and collection

Screenshot 2023-06-12 at 12 03 56 pm

An excerpt of the users validation schema showing the possible values of the status field

Screenshot 2023-06-12 at 12 04 14 pm

The very simple $match aggregation that is used to create the users.notDeleted view

The test in question

I want to write a unit test for my code that validates a user. A user is created via insertion into the users collection, but you can only login to users that are found in the users.notDeleted view.

Currently I can just mock users.notDeleted, but I am wondering if it can be possible to set up the view in the test environment?

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

No branches or pull requests

1 participant