package ai.elimu.rest.v2.crowdsource;

import ai.elimu.util.JsonLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import selenium.DomainHelper;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class WordPeerReviewsRestControllerTest {

    private Logger logger = LogManager.getLogger();

    @Test
    public void testGetRequest() {
        String jsonResponse = JsonLoader.loadJson(DomainHelper.getRestUrlV2() +
                "/crowdsource/word-peer-reviews");

        logger.info("jsonResponse: " + jsonResponse);

        JSONArray wordPeerReviewsJSONArray = new JSONArray(jsonResponse);
        logger.info("wordPeerReviewsJSONArray.length(): " + wordPeerReviewsJSONArray.length());
        assertThat(wordPeerReviewsJSONArray.length() > 0, is(true));

        JSONObject wordPeerReviewsJsonObject = wordPeerReviewsJSONArray.getJSONObject(0);
        assertThat(wordPeerReviewsJsonObject.getLong("id"), not(nullValue()));
        assertThat(wordPeerReviewsJsonObject.has("wordText"), is(true));
    }
}

@@ -740,38 +740,38 @@
 JSON
-Array wordPeerReviewsJSONArray
+Object errorResponseJSONObject
  = n
@@ -777,21 +777,22 @@
 new JSON
-Array
+Object
 (jsonRes
@@ -811,404 +811,165 @@
     
-logger.info(%22wordPeerReviewsJSONArray.length(): %22 + wordPeerReviewsJSONArray.length());%0A        assertThat(wordPeerReviewsJSONArray.length() %3E 0, is(true));%0A%0A        JSONObject wordPeerReviewsJsonObject = wordPeerReviewsJSONArray.getJSONObject(0);%0A        assertThat(wordPeerReviewsJsonObject.getLong(%22id%22), not(nullValue()));%0A        assertThat(wordPeerReviewsJsonObject.has(%22wordText%22), is(true
+assertThat(errorResponseJSONObject.get(%22result%22), is(%22error%22));%0A        assertThat(errorResponseJSONObject.get(%22errorMessage%22), is(%22Missing providerIdGoogle%22
 ));%0A

change WordPeerReviewsRestControllerTest to return missing providerIdGoogle