|
| 1 | +package apiTest; |
| 2 | + |
| 3 | +import com.google.gson.Gson; |
| 4 | +import helpers.Token; |
| 5 | +import io.restassured.http.ContentType; |
| 6 | +import io.restassured.path.json.JsonPath; |
| 7 | +import io.restassured.response.Response; |
| 8 | +import models.CreatePlaylistRequest; |
| 9 | +import io.restassured.response.Response; |
| 10 | +import models.CreatePlaylistResponse; |
| 11 | +import org.testng.Assert; |
| 12 | +import org.testng.annotations.BeforeMethod; |
| 13 | +import org.testng.annotations.Test; |
| 14 | +import static io.restassured.RestAssured.*; |
| 15 | + |
| 16 | +public class PlaylistTests { |
| 17 | + private String token; |
| 18 | + @BeforeMethod |
| 19 | + public void init(){ |
| 20 | + token = Token.retrieveToken(); |
| 21 | + } |
| 22 | + |
| 23 | +// private final String TOKEN = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMwMCwiaXNzIjoiaHR0cHM6Ly9rb2VsYXBwLnRlc3Rwcm8uaW8vYXBpL21lIiwiaWF0IjoxNTkwMDI2NzQwLCJleHAiOjE1OTA2MzE1NDAsIm5iZiI6MTU5MDAyNjc0MCwianRpIjoiQ1ZydTBCUTdPVHlydFpmTSJ9.kRvurIf5uDpIiWn0DoJBBUoT1taBu_k3jqDznMlZtDQ"; |
| 24 | + |
| 25 | + @Test |
| 26 | + public void playlistTests_CreatePlaylist_PlaylistCreated(){ |
| 27 | + String[] rules = {}; |
| 28 | + var playlist = new CreatePlaylistRequest("AAAtttAAA",rules); |
| 29 | + var requestBody = new Gson().toJson(playlist); |
| 30 | + |
| 31 | + Response response = given() |
| 32 | + .baseUri("https://koelapp.testpro.io/") |
| 33 | + .header("Authorization",token) |
| 34 | + .basePath("api/playlist") |
| 35 | + .contentType(ContentType.JSON) |
| 36 | + .body(requestBody) |
| 37 | + .when() |
| 38 | + .post() |
| 39 | + .then() |
| 40 | + .statusCode(200) |
| 41 | + .extract() |
| 42 | + .response(); |
| 43 | + |
| 44 | + JsonPath jsonPath = response.jsonPath(); |
| 45 | + CreatePlaylistResponse createdPlaylist = jsonPath.getObject("$",CreatePlaylistResponse.class); |
| 46 | + Assert.assertEquals(playlist.name,createdPlaylist.name); |
| 47 | + Assert.assertEquals(createdPlaylist.songs.length,0); |
| 48 | + } |
| 49 | + |
| 50 | +} |
0 commit comments