Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest assured get recently played #34

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cll2
Copy link

@cll2 cll2 commented Aug 13, 2024

I'm getting errors: For the first test, it 'passes' but is returning just HTML and not json
For the bottom2 tests, I'm getting ['](qa.koel: nodename nor servname provided, or not known)'

cll2 added 5 commits June 28, 2024 23:19
Login test works, sprint 1 errors
Cucumber
Play a song
Increase song count
Get recently played
@Berichicko
Copy link

I'm getting errors: For the first test, it 'passes' but is returning just HTML and not json For the bottom2 tests, I'm getting ['](qa.koel: nodename nor servname provided, or not known)'

Hi

I'll try to help you fix this.

image

HINT

Authorization Header: Ensure proper spacing.
Correct URL: Double-check that all URLs are accurate and include the full domain.
Verify API Endpoints: Ensure that the API endpoints you're testing exist and are properly set up to handle the requests.

package apiTests;
import static io.restassured.RestAssured.given;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Sprint8 {

    RequestSpecification requestSpec;

    @BeforeClass
    public void AuthSetup() {
        Response response = given()
            .params("email", "[email protected]", "password", "Koelapp1!!")
            .post("https://qa.koel.app/api/me")
            .then().statusCode(200).extract().response();
        String accessToken = response.path("token");
        String Authorization = "Bearer " + accessToken;  // Note the space after "Bearer"
        RequestSpecBuilder builder = new RequestSpecBuilder();
        builder.addHeader("Authorization", Authorization);
        requestSpec = builder.build();
    }

    @Test
    public void getRecentlyPlayed() {
        Response response = given()
            .spec(requestSpec).log().all()
            .when()
            .get("https://qa.koel.app/api/interaction/recently-played/1")
            .then().statusCode(200).extract().response();
        String responseBody = response.getBody().asString();
        System.out.println("Response body: " + responseBody);
    }

    @Test
    public void playASong() {
        String songId = "0aedf0c1c02188e8b73483d1bf2eacab";
        Response response = given()
            .spec(requestSpec).log().all()
            .when()
            .get("https://qa.koel.app/api/songs/" + songId + "/play")
            .then().statusCode(200).extract().response();
        String responseBody = response.getBody().asString();
        System.out.println("Response body: " + responseBody);
    }



    @Test
    public void increasePlayCount() {
        Response response = given()
            .spec(requestSpec).log().all()
            .params("song", "0aedf0c1c02188e8b73483d1bf2eacab")
            .when()
            .post("https://qa.koel.app/api/interaction/play")
            .then().statusCode(200).extract().response();
        String responseBody = response.getBody().asString();
        System.out.println("Response body: " + responseBody);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants