From 7ade7605e2e1a10b074367791c0b71024bda2060 Mon Sep 17 00:00:00 2001 From: Szymon Szczubkowski Date: Sun, 21 Jan 2024 00:55:57 +0100 Subject: [PATCH] add: sets tests --- src/test/java/org/example/SetsTest.java | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/org/example/SetsTest.java diff --git a/src/test/java/org/example/SetsTest.java b/src/test/java/org/example/SetsTest.java new file mode 100644 index 0000000..e1e8f67 --- /dev/null +++ b/src/test/java/org/example/SetsTest.java @@ -0,0 +1,49 @@ +package org.example; + +import io.restassured.RestAssured; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; + +public class SetsTest { + + @BeforeAll + public static void setsTestSetup() { + RestAssured.baseURI = "https://api.magicthegathering.io/v1/sets"; + } + + @Test + public void getAllSetsShouldReturnFiveHundredElements(){ + when().get().then().statusCode(200).header("Count", equalTo("500")); + } + + @Test + public void getSetsWithInvalidPathShouldReturnErrorNotFound(){ + given().pathParam("id", 0).get("/{id}").then().statusCode(404); + } + + @Test + public void getSetsWithParametersShouldReturnCorrectData(){ + Map expectedNames = Map.of( + "khans", "Khans of Tarkir", + "origins", "Magic Origins Clash Pack", + "tenth", "Tenth Edition"); + expectedNames.keySet().forEach(name -> given().param("name", name).get().then().body("sets[0].name", equalTo(expectedNames.get(name)))); + } + + @Test + public void getSetsWithSpecificPathShouldReturnCorrectData(){ + given().pathParam("id", "ktk").get("/{id}").then().body("set.name", equalTo("Khans of Tarkir")); + } + + @Test + public void getSetsWithBoosterPathParamShouldReturnCorrectData(){ + given().pathParam("id", "ktk").get("/{id}/booster").then().body("cards", hasSize(14)); + } +}