From 5eccc8260328a4d76d0a2518bf2dfa51030680b8 Mon Sep 17 00:00:00 2001 From: kankys Date: Sun, 13 Sep 2026 23:14:39 +0200 Subject: [PATCH] newTests --- apiTest/PotterAPI/Get specific spell.yml | 34 ++++++++++++++++++++ apiTest/PotterAPI/Get spells.yml | 41 ++++++++++++++++++++++++ apiTest/PotterAPI/ShortingHat.yml | 11 +++++-- 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 apiTest/PotterAPI/Get specific spell.yml create mode 100644 apiTest/PotterAPI/Get spells.yml diff --git a/apiTest/PotterAPI/Get specific spell.yml b/apiTest/PotterAPI/Get specific spell.yml new file mode 100644 index 0000000..5fa67fe --- /dev/null +++ b/apiTest/PotterAPI/Get specific spell.yml @@ -0,0 +1,34 @@ +info: + name: Get specific spell + type: http + seq: 3 + +http: + method: GET + url: http://localhost:3000/spells/5b74ed6d3228320021ab622f + auth: inherit + +runtime: + scripts: + - type: tests + code: |- + const expectedSpell={ + "id": "5b74ed6d3228320021ab622f", + "spell": "Alohomora", + "type": "Charm", + "effect": "opens locked objects", + "isUnforgivable": false + } + + test("It should return the correct spell", function(){ + expect(res.getBody()).to.deep.equal(expectedSpell) + }) + + //deep porovná vše 1:1 + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 + forwardAuthorizationHeader: false diff --git a/apiTest/PotterAPI/Get spells.yml b/apiTest/PotterAPI/Get spells.yml new file mode 100644 index 0000000..8e496b0 --- /dev/null +++ b/apiTest/PotterAPI/Get spells.yml @@ -0,0 +1,41 @@ +info: + name: Get spells + type: http + seq: 2 + +http: + method: GET + url: http://localhost:3000/spells?type=Curse&limit=2 + params: + - name: type + value: Curse + type: query + - name: limit + value: "2" + type: query + auth: inherit + +runtime: + scripts: + - type: tests + code: |- + const body = res.getBody() + + // Ověřím že se mi vrací Curse z (Query Params) + test("Each spell should have type Curse", function(){ + body.forEach(spellMember => expect(spellMember.type).to.eql("Curse")) + }); + + + + // Ověřím že se mi vrací pouze 2 záznamy (limit) + test("Response should contain exactly 2 spells", function(){ + expect(body).has.length(2) + }); + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 + forwardAuthorizationHeader: false diff --git a/apiTest/PotterAPI/ShortingHat.yml b/apiTest/PotterAPI/ShortingHat.yml index 23c4ebf..506a8d8 100644 --- a/apiTest/PotterAPI/ShortingHat.yml +++ b/apiTest/PotterAPI/ShortingHat.yml @@ -24,17 +24,22 @@ runtime: }) test("Message from sorting hat should not be empty", function(){ - expect(res.getBody().sortingHatSays).not.to.be.empty + expect(body.sortingHatSays).not.to.be.empty }) test("Message from house should not be empty", function(){ - expect(res.getBody().house).not.to.be.empty + expect(body.house).not.to.be.empty }) test("House is one of Gryffindor, Slytherin, Ravenclaw, Hufflepuff",function(){ - expect(res.getBody().house).is.oneOf(["Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff" ]) + expect(body.house).is.oneOf(["Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff" ]) }) + // Ověřím odpověď do 550 ms + test("Response time is less than 550 ms", function(){ + expect(res.responseTime).to.be.below(550) + }) + settings: encodeUrl: true timeout: 0