i'm new to cypress and i'm wondering how can i do the following checks: I have case: I have a product in the db, that can have statuses: InStock and OutOfStock and Discontinued. If product is in 'InStock ' status, i should be able to dispatch it to a customer, if in 'OutOfStock'/ 'Discontinued' i should not be able to dispatch to a customer. With an api call i can dispatch the product to a customer. If product is in 'InStock' status, the api response is 200, if not the response is with statusCode 400. So my question is: How can i change the status of the product in the db for each test, so i can check each of the 3 statuses (if the api returns the proper response)? I know how to check the api response itself, but it's not clear to me how to change the status of the product in the db, before each test.
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- NOT DISTINCT query in mySQL
- google-drive can't get push notifications
- Flush single app django 1.9
- How to reimport module with ES6 import
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Connection pooling vs persist connection mysqli
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
Unlike @Maccurt, I would actually do it the way you propose (change the DB), so you can properly test e2e flow.
And instead of setting up test routes which would write to the DB you can use
cy.task
to talk to the Cypress Runner's node process which can write to the DB directly. It'd look like this:Using postgres (node-postgres) in this example.
your-test.spec.js
cypress/plugins/index.js
You want to mock your api call so it responds with what you want. Cypress calls it stubbing. This will allow you to intercept your Rest call and replace it with what you want. You could also call an API to reset your DB, but I would not recommend that.
https://docs.cypress.io/guides/guides/network-requests.html#Requests