Skip to content

Commit

Permalink
Merge branch 'master' into tests_for_PO-749
Browse files Browse the repository at this point in the history
  • Loading branch information
rajanigandra authored Oct 25, 2024
2 parents 97e7696 + 31bd2df commit 09ac39c
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,77 @@ public void patchDraftAccount(DataTable data) throws JSONException {

String draftAccountId = DraftAccountUtils.getAllDraftAccountIds().getFirst();
SerenityRest
.given()
.header("Authorization", "Bearer " + getToken())
.accept("*/*")
.contentType("application/json")
.body(patchBody.toString())
.when()
.patch(getTestUrl() + "/draft-accounts/" + draftAccountId);
.given()
.header("Authorization", "Bearer " + getToken())
.accept("*/*")
.contentType("application/json")
.body(patchBody.toString())
.when()
.patch(getTestUrl() + "/draft-accounts/" + draftAccountId);
}

@When("I patch the {string} draft account with the following details")
public void patchDraftAccount(String draftAccountId, DataTable data) throws JSONException {
Map<String, String> dataToPatch = data.asMap(String.class, String.class);
JSONObject patchBody = new JSONObject();

patchBody.put("business_unit_id", dataToPatch.get("business_unit_id"));
patchBody.put("account_status", dataToPatch.get("account_status"));
patchBody.put("validated_by", dataToPatch.get("validated_by"));

JSONObject timelineData = new JSONObject();
timelineData.put("username", dataToPatch.get("validated_by"));
timelineData.put("status", dataToPatch.get("account_status"));

ZonedDateTime currentDateTime = ZonedDateTime.now();
timelineData.put("status_date", currentDateTime.format(DateTimeFormatter.ISO_INSTANT));

if (dataToPatch.containsKey("reason_text")) {
timelineData.put("reason_text", dataToPatch.get("reason_text"));
}
patchBody.put("timeline_data", timelineData);

SerenityRest
.given()
.header("Authorization", "Bearer " + getToken())
.accept("*/*")
.contentType("application/json")
.body(patchBody.toString())
.when()
.patch(getTestUrl() + "/draft-accounts/" + draftAccountId);
}

@When("I attempt to patch a draft account with an unsupported content type")
public void patchDraftAccountWithUnsupportedContentType() {
SerenityRest
.given()
.header("Authorization", "Bearer " + getToken())
.accept("text/plain")
.contentType("application/json")
.when()
.patch(getTestUrl() + "/draft-accounts/" + "1");
}

@When("I attempt to patch a draft account with an unsupported media type")
public void patchDraftAccountWithInvalidMediaType() {
SerenityRest
.given()
.header("Authorization", "Bearer " + getToken())
.accept("application/json")
.contentType("application/xml")
.when()
.patch(getTestUrl() + "/draft-accounts/" + "1");
}

@When("I patch the draft account trying to provoke an internal server error")
public void patchDraftAccountInternalServerError() {
SerenityRest
.given()
.urlEncodingEnabled(false)
.header("Authorization", "Bearer " + getToken())
.accept("*/*")
.contentType("application/json")
.when()
.patch(getTestUrl() + "/draft-accounts/%20");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@Opal
Feature: PO-747 patch draft account error handling

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP1 - Invalid Request Payload
Given I am testing as the "opal-test@hmcts.net" user
When I create a draft account with the following details
| business_unit_id | 73 |
| account | draftAccounts/accountJson/account.json |
| account_type | Fine |
| account_status | |
| submitted_by | BUUID |
| timeline_data | |
Then The draft account response returns 201
And I store the created draft account ID

When I patch the draft account with the following details
| business_unit_id__ | 73 |
| account_status | Rejected |
| validated_by | BUUID_REVIEWER |
| reason_text | Reason for rejection |
Then The draft account response returns 400

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP2 - Invalid or No Access Token
Given I am testing as the "opal-test@hmcts.net" user
When I create a draft account with the following details
| business_unit_id | 73 |
| account | draftAccounts/accountJson/account.json |
| account_type | Fine |
| account_status | |
| submitted_by | BUUID |
| timeline_data | |
Then The draft account response returns 201
And I store the created draft account ID

When I set an invalid token
And I patch the draft account with the following details
| business_unit_id | 73 |
| account_status | Rejected |
| validated_by | BUUID_REVIEWER |
| reason_text | Reason for rejection |
Then The draft account response returns 401

Then I am testing as the "opal-test@hmcts.net" user

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP4 - Resource Not Found
Given I am testing as the "opal-test@hmcts.net" user
When I patch the "1000000000" draft account with the following details
| business_unit_id | 73 |
| account_status | Rejected |
| validated_by | BUUID_REVIEWER |
| reason_text | Reason for rejection |
Then The draft account response returns 404

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP5 - Unsupported Content Type
Given I am testing as the "opal-test@hmcts.net" user
When I attempt to patch a draft account with an unsupported content type
Then The draft account response returns 406

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP7 - Unsupported Media Type
Given I am testing as the "opal-test@hmcts.net" user
When I attempt to patch a draft account with an unsupported media type
Then The draft account response returns 415

@PO-747 @cleanUpData
Scenario: Patch draft account - CEP9 - Other Server Error
Given I am testing as the "opal-test@hmcts.net" user
When I patch the draft account trying to provoke an internal server error
Then The draft account response returns 500

0 comments on commit 09ac39c

Please sign in to comment.