Skip to content

Commit

Permalink
Merge pull request #117 from ELEVATE-Project/submittedForReviewWtithV…
Browse files Browse the repository at this point in the history
…alidations

Submitted for review API
  • Loading branch information
subash-cs authored Dec 23, 2024
2 parents cdc579f + 56a7224 commit 620e15c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/main/resources/config/automation_SCPAPI_QA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ [email protected]
scp.getreviewer.pass=Password@123
scp.getreviewer.list.verify=[email protected]
scp.qa.listPermissionByRole.endpoint=/scp/v1/permissions/list
scp.delete.permission.endpoint=/scp/v1/permissions/delete/
scp.delete.permission.endpoint=/scp/v1/permissions/delete/
scp.submitForReview.endpoint=/scp/v1/projects/submitForReview/
16 changes: 8 additions & 8 deletions src/main/resources/scp_project_details_payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
"id": "588",
"title": "Effective Classroom Management",
"categories": ["teachers", "students"],
"objective": "Teachers will learn strategies to manage classrooms effectively.",
"objective": "Teachers will learn strategies to manage classrooms effectively",
"recommended_duration": { "number": "3", "duration": "months" },
"keywords": "Classroom Management, Teacher Training",
"recommended_for": ["teacher", "principal"],
Expand Down Expand Up @@ -353,7 +353,7 @@
"name": "Classroom Management Certificate",
"issuer": "Teacher Training Institute",
"criteria": {
"validationText": "Complete the project tasks to receive the certificate.",
"validationText": "Complete the project tasks to receive the certificate",
"expression": "C1&&C2",
"conditions": {
"C1": {
Expand Down Expand Up @@ -389,11 +389,11 @@
"id": "589",
"title": "Effective Classroom Management",
"categories": ["teachers"],
"objective": "Teachers will learn strategies to manage classrooms effectively.",
"objective": "Teachers will learn strategies to manage classrooms effectively",
"recommended_duration": { "number": "2", "duration": "months" },
"keywords": "Classroom Management, Teacher Training",
"recommended_for": ["teacher"],
"languages": ["en", "bn"],
"recommended_for": ["teachers"],
"languages": ["en", "bengali"],
"learning_resources": [
{ "name": "Basic Math Skills Tutorial", "url": "https://diksha.gov.in/play/content/112233" }
],
Expand Down Expand Up @@ -434,7 +434,7 @@
"id": "590",
"title": "Effective Classroom Management",
"categories": ["teachers"],
"objective": "Teachers will learn strategies to manage classrooms effectively.",
"objective": "Teachers will learn strategies to manage classrooms effectively",
"recommended_duration": { "number": "1", "duration": "month" },
"keywords": "Classroom Management, Teacher Training",
"recommended_for": ["teacher", "trainer"],
Expand Down Expand Up @@ -479,7 +479,7 @@
"id": "591",
"title": "Effective Classroom Management",
"categories": ["students"],
"objective": "Teachers will learn strategies to manage classrooms effectively.",
"objective": "Teachers will learn strategies to manage classrooms effectively",
"recommended_duration": { "number": "3", "duration": "months" },
"keywords": "Classroom Management, Teacher Training",
"recommended_for": ["student"],
Expand Down Expand Up @@ -517,7 +517,7 @@
"id": "590",
"title": "Updated Classroom Management",
"categories": ["teachers"],
"objective": "Teachers will now learn advanced strategies to manage classrooms effectively.",
"objective": "Teachers will now learn advanced strategies to manage classrooms effectively",
"recommended_duration": { "number": "1", "duration": "month" },
"keywords": "Advanced Classroom Management, Teacher Training",
"recommended_for": ["teacher", "trainer"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

public class TestScpProjectCRUDOperations extends SelfCreationPortalBaseTest {
private static final Logger logger = LogManager.getLogger(TestScpProjectCRUDOperations.class);
private URI projectCreateEndpoint, projectUpdateEndpoint, getProjectDetailsEndpoint, projectDeletionEndpoint;
private URI projectCreateEndpoint, projectUpdateEndpoint, getProjectDetailsEndpoint, projectDeletionEndpoint, submitProjectToReviewerEndpoint;
private Integer createdId;
private List<Integer> reviewerIds = List.of(239, 240, 241);
private String contentCreatorToken;

@BeforeMethod()
Expand Down Expand Up @@ -215,7 +216,7 @@ public void testCreateProjectWithInvalidPayload() throws Exception {
}

@Test(dependsOnMethods = "testCreateProjectWithValidPayload", description = "Verifies the functionality of updating project with valid payload.")
public void testUpdateProjectWithValidPayload() throws Exception {
public void testUpdateProjectWithValidPayload() throws Exception {
logger.info("Started calling the UpdateProject API with valid payload:");

// Load JSON payload and ensure the file exists
Expand Down Expand Up @@ -251,7 +252,7 @@ public void testUpdateProjectWithCertificate() throws Exception {

// Modify values for updating
requestBody.put("title", "Updated Project Title with Certificate");
requestBody.put("objective", "Updated objective for project with certificate.");
requestBody.put("objective", "Updated objective for project with certificate");
requestBody.put("keywords", "Updated, Classroom Management");

// Make the API call to update the project
Expand All @@ -263,7 +264,7 @@ public void testUpdateProjectWithCertificate() throws Exception {
Assert.assertEquals(statusCode, 202, "Status code should be 202");

// Validate the updated content
validateUpdatedProjectContent(createdId, "Updated Project Title with Certificate", "Updated objective for project with certificate.", "Updated, Classroom Management");
validateUpdatedProjectContent(createdId, "Updated Project Title with Certificate", "Updated objective for project with certificate", "Updated, Classroom Management");

logger.info("Ended calling the UpdateProject API with certificates.");
}
Expand All @@ -277,7 +278,7 @@ public void testUpdateProjectWithoutCertificate() throws Exception {

// Modify values for updating
requestBody.put("title", "Updated Project Title without Certificate");
requestBody.put("objective", "Updated objective for project without certificate.");
requestBody.put("objective", "Updated objective for project without certificate");
requestBody.put("keywords", "Updated, Training");

// Make the API call to update the project
Expand All @@ -289,7 +290,7 @@ public void testUpdateProjectWithoutCertificate() throws Exception {
Assert.assertEquals(statusCode, 202, "Status code should be 202");

// Validate the updated content
validateUpdatedProjectContent(createdId, "Updated Project Title without Certificate", "Updated objective for project without certificate.", "Updated, Training");
validateUpdatedProjectContent(createdId, "Updated Project Title without Certificate", "Updated objective for project without certificate", "Updated, Training");

logger.info("Ended calling the UpdateProject API without certificates.");
}
Expand All @@ -303,7 +304,7 @@ public void testUpdateProjectWithNoSubtasks() throws Exception {

// Modify values for updating
requestBody.put("title", "Updated Project Title with No Subtasks");
requestBody.put("objective", "Updated objective for project with no subtasks.");
requestBody.put("objective", "Updated objective for project with no subtasks");
requestBody.put("keywords", "Updated, Subtask-less");

// Make the API call to update the project
Expand All @@ -315,7 +316,7 @@ public void testUpdateProjectWithNoSubtasks() throws Exception {
Assert.assertEquals(statusCode, 202, "Status code should be 202");

// Validate the updated content
validateUpdatedProjectContent(createdId, "Updated Project Title with No Subtasks", "Updated objective for project with no subtasks.", "Updated, Subtask-less");
validateUpdatedProjectContent(createdId, "Updated Project Title with No Subtasks", "Updated objective for project with no subtasks", "Updated, Subtask-less");

logger.info("Ended calling the UpdateProject API with no subtasks.");
}
Expand All @@ -329,7 +330,7 @@ public void testUpdateProjectWithOnlyMandatoryFields() throws Exception {

// Modify values for updating
requestBody.put("title", "Updated Project Title with Only Mandatory Fields");
requestBody.put("objective", "Updated objective for project with only mandatory fields.");
requestBody.put("objective", "Updated objective for project with only mandatory fields");
requestBody.put("keywords", "Updated, Basic");

// Make the API call to update the project
Expand All @@ -341,7 +342,7 @@ public void testUpdateProjectWithOnlyMandatoryFields() throws Exception {
Assert.assertEquals(statusCode, 202, "Status code should be 202");

// Validate the updated content
validateUpdatedProjectContent(createdId, "Updated Project Title with Only Mandatory Fields", "Updated objective for project with only mandatory fields.", "Updated, Basic");
validateUpdatedProjectContent(createdId, "Updated Project Title with Only Mandatory Fields", "Updated objective for project with only mandatory fields", "Updated, Basic");

logger.info("Ended calling the UpdateProject API with only mandatory fields.");
}
Expand Down Expand Up @@ -433,6 +434,50 @@ public void testDeletingNotTheExistingOne() {
logger.info("Ended calling the delete project API with a non-existing project id.");
}

@Test(description = "Verifies the functionality of submitting the created project to reviewer with valid payload")
public void testSubmitProjectForReviewValidPayload() {
logger.info("Started calling the submit project for review API with valid project id");

// Generate random reviewer id from the list
Integer reviewerId = reviewerIds.get(0);

// Build the request payload with dynamic reviewer IDs
JSONObject requestPayload = new JSONObject();
requestPayload.put("reviewer_ids", List.of(reviewerId));
requestPayload.put("notes", "Note to the reviewer");

// Make the API call to submit the project
Response response = submitProjectForReviewer(createdId, requestPayload);

// Log the status code and response body
response.prettyPrint();

// Validate response code
Assert.assertEquals(response.getStatusCode(), 200, "Status code should be 200 for valid payload");

logger.info("Ended calling the submit project for review API with valid project id");
}

@Test(description = "Verifies the functionality of submitting the created project to reviewer with invalid payload")
public void testSubmitProjectForReviewInvalidPayload() {
logger.info("Started calling the submit project for review API with invalid project id");

// Invalid payload - missing reviewer_ids or invalid format
JSONObject requestPayload = new JSONObject();
requestPayload.put("reviewer_ids", new Object());
requestPayload.put("notes", "Note to the reviewer");

// Make the API call to submit the project
Response response = submitProjectForReviewer(createdId, requestPayload);

// Log the status code and response body
response.prettyPrint();

// Validate response code
Assert.assertEquals(response.getStatusCode(), 400, "Status code should be 400 for invalid payload");
logger.info("Ended calling the submit project for review API with invalid payload");
}

//Method to create project
private JSONObject createProject(Map<String, Object> map) {
JSONObject requestBody = new JSONObject();
Expand Down Expand Up @@ -497,7 +542,7 @@ private Response getProjectDetailsRequest(Integer id) {
return response;
}

//Method to delete entityType
//Method to delete project
private Response projectDeleteRequest(Integer id) {
projectDeletionEndpoint = MentorBase.createURI(PROP_LIST.get("scp.delete.project.endpoint").toString());
// Make the DELETE project request
Expand All @@ -513,6 +558,35 @@ private Response projectDeleteRequest(Integer id) {
return response;
}

//Method to submit project for reviewer
private JSONObject submitProject(Map<String, Object> map) {
JSONObject requestBody = new JSONObject();
requestBody.putAll(map);
return requestBody;
}

// Method to submit the project for review
private Response submitProjectForReviewer(Integer id, JSONObject requestPayload) {
// Construct the URI for submitting the project for review
submitProjectToReviewerEndpoint = MentorBase.createURI(PROP_LIST.get("scp.submitForReview.endpoint").toString());

// Ensure the path parameter is correctly inserted in the URL
String endpoint = submitProjectToReviewerEndpoint + "{id}";

// Make the POST request to submit the project for review
Response response = given()
.header("X-auth-token", "bearer " + X_AUTH_TOKEN)
.contentType(ContentType.JSON)
.body(requestPayload.toString())
.pathParam("id", id) // Correctly passing the path parameter "id"
.when().post(endpoint); // Post the request with the correct endpoint and path parameter

// Pretty-print the response for debugging
response.prettyPrint();
return response;
}


//Method to load Json payload
private JSONObject loadJsonPayload(String key) throws Exception {
String filePath = "src/main/resources/scp_project_details_payload.json";
Expand All @@ -537,7 +611,7 @@ private void validateProjectContentAfterCreation() {
Assert.assertEquals(response.jsonPath().getString("result.title"), "Effective Classroom Management", "Project title mismatch");

// Validate the project objective
Assert.assertEquals(response.jsonPath().getString("result.objective"), "Teachers will learn strategies to manage classrooms effectively.", "Project objective mismatch");
Assert.assertEquals(response.jsonPath().getString("result.objective"), "Teachers will learn strategies to manage classrooms effectively", "Project objective mismatch");

// Validate the keywords
Assert.assertEquals(response.jsonPath().getString("result.keywords"), "Classroom Management, Teacher Training", "Project keywords mismatch");
Expand All @@ -562,7 +636,7 @@ private void validateProjectContentAfterCreation() {
// Validate the certificate criteria
Map<String, Object> criteria = (Map<String, Object>) certificate.get("criteria");
Assert.assertNotNull(criteria, "Certificate criteria should not be null");
Assert.assertEquals(criteria.get("validationText"), "Complete the project tasks to receive the certificate.", "Certificate validation text mismatch");
Assert.assertEquals(criteria.get("validationText"), "Complete the project tasks to receive the certificate", "Certificate validation text mismatch");

// Validate conditions C1 and C2
Map<String, Object> conditions = (Map<String, Object>) criteria.get("conditions");
Expand Down

0 comments on commit 620e15c

Please sign in to comment.