D
D
DenniLa22018-03-30 16:25:31
Node.js
DenniLa2, 2018-03-30 16:25:31

How to properly test a POST request to nodejs?

Application in nodejs. There is a request to create an entity, say a user. As a result, a user should be created with a unique email (which then needs to be activated) and other parameters that are unique or not.
I would like to check with a test that the entity was created in the database, it was assigned an id. But when writing a test, you need to write a generator of unique email addresses and other unique parameters. Or am I thinking wrong?
How in general is it correct to test so that the database would not be littered? Or after the creation test, run a request to delete this entity? But then there will be an unnecessary hole in the API. I still admit this is not a dev / test server, but then how to test it on prod?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Lebedinsky, 2018-04-02
@Lebed71

When you run the tests, a new clean database is created (you can preload any mocks you need into it).
All the necessary test cases are tested, and the e-mail must be unique, but this is easily done in the spirit:
And used in the future.
After passing all the tests, the database is deleted.
Everything is done by Mocha and related technologies.
Why run tests on prod when you can bring the dev server environment to prod and get the same result?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question