Need help - Can we use Chai.js for database verification?

102 views
Skip to first unread message

Kedar Tiwaskar

unread,
Mar 3, 2016, 12:56:52 AM3/3/16
to Chai.js
Hi,

I am using Runscope for API automation. I discovered that Chai.js is an assertion library which can be used in the Scripts section of runscope to add extra assertions.

I just wanted to ask that using Chai.js can we perform database verification?

The situation is as below:

When a POST request is submitted, it is going to create some data (lets say field x having value abc)
Now after the above call, I just want to verify that abc value is inserted in database properly.

(I know we can use GET call after POST so that it will fetch data, but I want to test is explicitly from the database)

Can anybody give me some idea on it? Whether it is possible or not.

Thanks in advance!

-Kedar

Lucas Rafael Dutra

unread,
Dec 5, 2016, 10:40:56 AM12/5/16
to Chai.js
Hi, Kedar. How are u doing?


Supposing that you are using MongoDB (which is not longer a problem whether you're using an other database), when you insert a new document you get the id of the last document inserted.
Therefore, you could just create a new endpoint in your server which takes in this id and then you will be able to assert values returned by the database.

heads up: try to create a nested test case where firstly you do a post request to insert a data which you want and right after you query by document id to assert values.


Hope this helps!
Reply all
Reply to author
Forward
0 new messages