diff --git a/README.md b/README.md index 00d5ba3..cacddec 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ Soubor: [`.github/workflows/api-tests.yml`](./.github/workflows/api-tests.yml) --- -## 📞 Kontakt & Podpora +## 📞 Podpora - **Issues**: [GitHub Issues](https://github.com/kankys/api_test/issues) - **Diskuse**: Použijte GitHub Discussions diff --git a/apiTest/JsonPlaceholder/Posts/Create new post.yml b/apiTest/JsonPlaceholder/Posts/Create new post.yml new file mode 100644 index 0000000..4be8f60 --- /dev/null +++ b/apiTest/JsonPlaceholder/Posts/Create new post.yml @@ -0,0 +1,44 @@ +info: + name: Create new post + type: http + seq: 2 + +http: + method: POST + url: https://jsonplaceholder.typicode.com/posts + auth: inherit + headers: + - name: Content-Type + value: application/json + body: + raw: |- + { + "title": "foo", + "body": "bar", + "userId": 1 + } + +runtime: + scripts: + - type: tests + code: |- + const status = res.getStatus(); + const responseBody = res.getBody(); + + test("Status code is 201", function() { + expect(status).to.equal(201); + }); + + test("Response has id", function() { + expect(responseBody).to.have.property('id'); + }); + + test("Response id is a number", function() { + expect(responseBody.id).to.be.a('number'); + }); + +settings: + encodeUrl: true + timeout: 10000 + followRedirects: true + maxRedirects: 5 diff --git a/apiTest/JsonPlaceholder/Posts/Get post by ID.yml b/apiTest/JsonPlaceholder/Posts/Get post by ID.yml new file mode 100644 index 0000000..776eacf --- /dev/null +++ b/apiTest/JsonPlaceholder/Posts/Get post by ID.yml @@ -0,0 +1,40 @@ +info: + name: Get post by ID + type: http + seq: 1 + +http: + method: GET + url: https://jsonplaceholder.typicode.com/posts/1 + auth: inherit + +runtime: + scripts: + - type: tests + code: |- + const status = res.getStatus(); + const body = res.getBody(); + + test("Status code is 200", function() { + expect(status).to.equal(200); + }); + + test("Response has id 1", function() { + expect(body.id).to.equal(1); + }); + + test("Response has title and body", function() { + expect(body).to.have.property('title'); + expect(body).to.have.property('body'); + }); + + test("Title is not empty", function() { + expect(body.title).to.not.be.empty; + }); + +settings: + encodeUrl: true + timeout: 10000 + followRedirects: true + maxRedirects: 5 + forwardAuthorizationHeader: true diff --git a/apiTest/JsonPlaceholder/Posts/folder.yml b/apiTest/JsonPlaceholder/Posts/folder.yml new file mode 100644 index 0000000..224dca8 --- /dev/null +++ b/apiTest/JsonPlaceholder/Posts/folder.yml @@ -0,0 +1,7 @@ +info: + name: Posts + type: folder + seq: 2 + +request: + auth: inherit diff --git a/apiTest/JsonPlaceholder/Users/Get all users.yml b/apiTest/JsonPlaceholder/Users/Get all users.yml new file mode 100644 index 0000000..d189f69 --- /dev/null +++ b/apiTest/JsonPlaceholder/Users/Get all users.yml @@ -0,0 +1,43 @@ +info: + name: Get all users + type: http + seq: 1 + +http: + method: GET + url: https://jsonplaceholder.typicode.com/users + auth: inherit + +runtime: + scripts: + - type: tests + code: |- + const status = res.getStatus(); + const body = res.getBody(); + + test("Status code is 200", function() { + expect(status).to.equal(200); + }); + + test("Response is an array", function() { + expect(body).to.be.an('array'); + }); + + test("Array has 10 users", function() { + expect(body).to.have.length(10); + }); + + test("Each user has id and name", function() { + body.forEach(user => { + expect(user).to.have.property('id'); + expect(user).to.have.property('name'); + expect(user).to.have.property('email'); + }); + }); + +settings: + encodeUrl: true + timeout: 10000 + followRedirects: true + maxRedirects: 5 + forwardAuthorizationHeader: true diff --git a/apiTest/JsonPlaceholder/Users/folder.yml b/apiTest/JsonPlaceholder/Users/folder.yml new file mode 100644 index 0000000..d0c4171 --- /dev/null +++ b/apiTest/JsonPlaceholder/Users/folder.yml @@ -0,0 +1,7 @@ +info: + name: Users + type: folder + seq: 1 + +request: + auth: inherit diff --git a/apiTest/JsonPlaceholder/opencollection.yml b/apiTest/JsonPlaceholder/opencollection.yml new file mode 100644 index 0000000..df04a0f --- /dev/null +++ b/apiTest/JsonPlaceholder/opencollection.yml @@ -0,0 +1,16 @@ +opencollection: 1.0.0 + +info: + name: JsonPlaceholder + type: collection + +request: + auth: inherit + +bundled: false + +extensions: + bruno: + ignore: + - node_modules + - .git