I'm coming from Rails world,
On rails I used FactoryGirl to create some db data before testing api.
I've searched on the web for similar methods and I couldn't find any good results.
How do you test your API if you want to insert some db data before?
Related
I am doing testing on Nodejs APIs using mocha and chai. Each time when I do testing, the database populates with some new entries, is there a way to avoid these entries in my database while testing and keep the database unchanged?
I want to make some unit tests on my nodejs app in order to test the insertion of a user on a database or the read of a user from the database.
I'm using Objection.js such an ORM and I searched through the net how to do these Test, thus I found Sinon to mock a database or a model.Concerning this issue I found also this question Mocking database in node.js?.
For example if I have a table Users contains 10 users, is there any solutions to get all the rows of such table for example of fetch if a user exists in the table? I don't really understand the concept of mocking and if it is the suitable solution to make such tests?
There are lots of libs for unit testing of NodeJS such as Moca, Chai, Jasmine.
here is some tutorial link:
https://www.codementor.io/davidtang/unit-testing-and-tdd-in-node-js-part-1-8t714s877
https://blog.risingstack.com/node-hero-node-js-unit-testing-tutorial/
I am beginner in Reactjs and Nodejs.
I just want to build a simple application which performs CRUD operations.
ReactJS for displaying data and act as a front-end.
Nodejs have some API which returns static data.
If anyone know about some blog or have some example with you than please share. This will help me to start with this.
I also searched for many articles online but they all are consist database connection, ExpressJs which i don not need at this time.
You can see here:-
In this repository you can see crud operation in reactjs and nodejs and mysql database used here.
https://github.com/abhi4pr/express-react-app
I am trying out React-Starter-Kit for the first time and loving all the cutting edge features baked in (apollo/graphql-client in particular). A crucial part of any app for me is the database, and for that my understanding is the same author provides nodejs-api-starter which sets up a REST interface for accessing Postgres at localhost:5000 and has a graphql webui at localhost:5000/graphl.
That is about as far as I have been able to understand of the setup so far. I have changed the frontend code a little bit so a new Component "Counter" is loaded on the home page. I need to be able to make a new counter, fetch the latest counter, and increment decrement the counter. Write now the component just outputs the 'value' retrieved from the server at 5000.
I do not think I am accessing the 5000 server correctly, do I put the port in this url line somehow?
You can pull the repo down from : https://github.com/Falieson/react-starter-kit-crud-counter-demo
This is my first time setting up a nodejs api server, I am used to using MeteorJS which has pub/sub to MongoDB baked in. I am looking forward to the separation the RSK strategy (which seems more industry standard?) provides.
I've just done setting up the full site with Database from React-Stater-Kit, I'm also a newbie so I understand your frustration.
About this question, you don't need the NodeJS-API-Starter, it has enhanced function ( such as Redis cache ) and it's not suited for newbies. You should look deeper into the RSK, it already has the DB. If you ran the boilerplate and played around, change is you'll see file database.sqlite in your folder, it's the database. Here are the things you should learn:
Use SequelizeJS to connect the NodeJS server with database. Your database can be MySQL/MariaDB, PostgreSQL or SQLite. The connection is easy and there's tool to auto-generate Models from your database
How to create GraphQL's Types and Queries. If your queries need to search through the database, import Sequelize's models and use its functions.
Test your API via GraphQLi
Note: if you want to use MongoDB or other NoSQL, try Mongoose instead of Sequelize.
I want to clone a public api into a mongodb database with nodejs so I can run my own queries and extend the data like I want. My problem is that I want to fetch the newest updates as well. The good thing is that I know when the data will change at the api app approximately.
I thought about something like cronjobs or a setInterval.
In the internet I could find many solutions how to transform a database into a rest api but no vice versa.
Please give me suggestions how to solve this problem.