MongoDB / Mongoose Unit Testing - Best practice? [closed] - node.js

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm writing a npm package to import GIS data into MongoDB via mongoose. I've written unit tests using mocha to test the data transformations that happen BEFORE the mongoose model is saved.
I'd like to be sure that all the mongoose data got saved correctly to the database (including any updates that needed to occur). What would be the best practice, in this case?
My intuition create a test collection, insert all the records, ensure that it looks the way I expect it to look, and drop the collection.

Yes, setting up and tearing down all the collections in the database is necessary for ensuring there are no side effects between unit tests. In practice, this means a beforeEach() where you reconnect to the database and drop all collections, and an afterEach() where you disconnect from the database.
Some deeper information: What you are trying to do here is integration testing, where you are testing the actual integration between your code and mongo. Unit tests are tests that never call the database or other resources. More info on this here: What's the difference between unit tests and integration tests? For me, I separate them into tests/unit and tests/integration.
I'm not aware of any packages or libraries that do this for you, but take a look at this tutorial for one way to go about this.

Related

When should I use nodejs and when should I use mongoDB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 9 months ago.
Improve this question
I read many documents about node js and MongoDB. But the regret is that I can't understand when I should use nodejs and when I should use MongoDB. If anyone here who can tell me the details, it will be very helpful for me.
MongoDB and NodeJS are two different technologies. MonogDB is a database system which gives you a chance to efficiently store documents in a database and to perform operations like data updates, or to search documents by some criterias.
Otherhand,
NodeJS's responsibilty is especially to execute your application.
Node.js is a javaScript runtime environment where you can run/execute your javaScript codes meaning it's like the grill to barbeque the turkey and MongoDB on the other hand is totally different technology where you will store your data's in mostly .json format meaning it's like the chilli sauce you can use it to your barbeque or if it's not your likeness you can choose tomato sauce instead. But if you are going to learn MERN stack then you need to learn both with react.js and express.js. Home it helps.
You are comparing two totally different things. MongoDB is a Database while Node JS is a coding environment. They are related in the sense that you can configure MongoDB in Node JS.
The thing is pretty straightforward.
NodeJs is better for high I/O intensive applications and bad for CPU intensive applications.
Use MongoDB if you have no/fewer relationships among the data you are storing. But if you have a specific structure of data that you are storing or there are some relations between the data you are storing then go for a relational database.

Should my integration tests reuse persistence library to have access to db? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have an implementation of DDD.IdentityAccess.Domain which contains IUserRepository abstraction. There is another dll -> DDD.IdentityAccess.Persistence.Sql which contains implementation of the IUserRepository abstraction. Now, I want to test my IdentityAccess all way down -> Api -> DomainLogic -> Database. Let's take a 'CreateUser' usecase. I call 'CreateUser' through my httpClient, then I want to query db to check if the user is actually added to db. I don't have 'user/id' operation on my rest api, so the only option is to use DDD.IdentityAccess.Persistence.Sql but it will bring dependency to DDD.IdentityAccess.Domain. Should I reuse this dll, or create another DAL, which is not related to Domain?
This is less related to domain driven design than to organizing your test setup.
Integration tests are expensive to write, but can bring enormous value by showing that several components work together as expected. It's a tradeoff.
That said, if I understand you correctly, your question is if you should mock the sql data access object(s) or go down all the way to the database, executing the same sql statements.
There isn't a right or wrong answer here. If the focus is on testing business logic, then concentrate on testing the domain and mock the database access layer.
If the focus is on testing that a simple save operation works from top to bottom, then don't mock. (But use a test database, of course.)

nightwatch.js - how to prevent browser to open for api tests [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am looking for best javascript framework that can be used for both UI and api tests. I am wondering if nightwatch.js can be good for it.
Works great with browser, but can't prevent browser to open for api tests
You could avoid calling any browser commands of nightwatch and just use the test structure of nightwatchjs to trigger api calls and assert them with good old node assert but personally I would keep them separate.
UI tests take time and are brittle where API tests take a fraction of the time and require less maintenance.
Nightwatchjs is designed as UI test framework and although you could possibly hack it to do what you want, you will end up spending more resources to do so.

Is there a batteries-included server framework for graphQL api? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I enjoy using loopback to quickly build a REST api, with a fair amount of scaffolding. All I need to do is define my data, write any custom validations, and add any other server-side logic. For simple requirements, you can have a RESTful API in minutes. What about GraphQL?
Loopback doesn't support GraphQL. A quick websearch shows a few grapql servers like express-graphql. Is there a more batteries-included option? I don't want to write a web-server. I want a framework, but I can't find such.
I just want a functioning and stable data-abstraction layer, access control, a graphQL interface, and a solid way to connect all of these reliably. Is there a solution available already?
I would prefer a solution using either nodejs or python
It may help you to know that I have just discovered GraphQL. So maybe my question shows a fundamental misunderstanding of the topic, maybe I'm ignoring something obvious. If so, enlighten me.
Does Apollo server come closer to what you're looking for? https://github.com/apollostack/apollo-server/blob/master/README.md
express-graphql's main goal is to be a minimal reference implementation, whereas Apollo Server's goal is to be a complete production-ready GraphQL server.

pure javascript client for mongo on node? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a javascript only mongo client?
the node mongo driver is native, right? I can see kerberos being compiled on install. plus some places it is called "native mongo node.js client".
this page says the following
It is written in pure JavaScript and provides a native asynchronous Node.js interface to MongoDB
but that just means it has compiled dependencies, right?
it is all very confusing.
I am looking for a mongo client that does not require any kind of compilation for nodejs. does one exist?
The top end of the driver is javascript, the speed critical parts are native, or it was easier to include an established/proven package like kerberos. Note that easier does not imply lazy - it implies that no implementor has yet thought the effort justified the benefit.
Drivers are listed here and it is interesting to note that there are not even minor projects that attempt to write a javascript only solution - as one might see in, say, Java.
Many more complex/mature node packages require compiled dependencies; building node products for the target platform is standard and services like Travis make this easy.
I suggested you using mongoose. this very popular.

Resources