Editor: InteliJ
Running a test:
Feature: testing an API Background: * url 'http://localhost:5984/' Scenario: create a database Given path 'test/' Then method get Then match response contains { error:not_found,reason: Database does not exist.} Scenario: create verify and delete data # create Given path 'words/' And request {questionlanguage: English, answerlanguage: Spanish, question: which bus goes to the beach, answer: qué autobús va a la playa} Then method post And status 201 Then def dataId = response.id And def refId = response.rev # verify Given path 'words/' + dataId When method get And status 200 Then match response contains { question: which bus goes to the beach, answer: qué autobús va a la playa} # become admin Given path '_session' And form field username = 'admin' And form field password = 'asdfqwer1234#' When method post And print response Then status 200 # delete Given path 'words/' + dataId And param rev = refId And method DELETE Then status 200
Setup:
Karate API: Maven dependencies
<dependencies> <dependency> <groupId>com.intuit.karate</groupId> <artifactId>karate-junit4</artifactId> <version>0.2.7</version> <scope>test</scope> </dependency> </dependencies>
- Run couchDB: docker run -p 5984:5984 -d couchdb
- Access DB configuration: http://localhost:5984/_utils/
- Create Admin with terminal (optinal):
curl -X PUT 127.0.0.1:5984/somedatabase -u admin:mypassword
Create Database, a view and data:
View: http://localhost:5984/words/_design/view1/_view/new-view
CouchDB Document:
{
"_id": "15a13e99260c9aa4a066c904f700319b",
"_rev": "1-a1a3ba8da99d40870fe0b18277c873ac",
"first-language": "Englisch",
"second-language": "Spanisch",
"question": "which bus goes to the beach",
"answer": "qué autobús va a la playa"
}
View filter: Map function
function (doc) { emit(doc._id, {id:doc._id, refID:doc._rev, questionlanguage:doc.questionlanguage,answerlanguage:doc.answerlanguage,question:doc.question,answer:doc.answer}); }
Leave a comment