Skip to content

Commit

Permalink
Add tests for NHA (#24)
Browse files Browse the repository at this point in the history
Add tests for different environments.
  • Loading branch information
shridharkalagi authored Aug 11, 2020
1 parent b899f3d commit 0013694
Show file tree
Hide file tree
Showing 30 changed files with 510 additions and 123 deletions.
122 changes: 117 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
# Sequence of patterns matched against refs/heads
branches:
- master
- forget-consent-pin
- nha-tests
jobs:
API-test:
runs-on: ubuntu-latest
Expand All @@ -22,6 +22,7 @@ jobs:
env:
ConsentManagerSecret: ${{ secrets.ConsentManagerSecret }} # required
HIPSecret: ${{ secrets.HIPSecret }} # required
env: ncg # required
- name: Print Run id
run: echo $GITHUB_RUN_ID
- uses: 8398a7/action-slack@v2
Expand All @@ -34,7 +35,7 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always()

mobile-test:
mobile-test-ncg:
runs-on: macOS-latest
steps:
- name: checkout
Expand All @@ -48,19 +49,130 @@ jobs:
node-version: '10.16'
java-version: 1.8
- run: npm install -g appium
- name: run tests
- name: run mobile tests on NCG
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
profile: Nexus 6
script: mvn clean "-Dtest=/**/MobileAppTests/Tests/*Test" test
env:
Authorization: ${{ secrets.Authorization }}
env: ncg # required
- name: Notify on Slack
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Functional Tests
text: Functional Mobile Tests
author_name: Functional Tests on NCG
text: Functional Mobile Tests on NCG
channel: '#botcave'
only_mention_fail: USXBM5WPQ,here
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always()

mobile-test-nhs-dev:
runs-on: macOS-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: set up node
uses: actions/setup-node@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
fetch-depth: 1
node-version: '10.16'
java-version: 1.8
- run: npm install -g appium
- name: run mobile tests on NHS Dev
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
profile: Nexus 6
script: mvn clean "-Dtest=/**/MobileAppTests/Tests/LoginTest" test
env:
Authorization: ${{ secrets.Authorization }}
env: nhsDev # required
- name: Notify on Slack
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Functional Tests on NHS Dev
text: Functional Mobile Tests on NHS Dev
channel: '#botcave'
only_mention_fail: USXBM5WPQ,here
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always()


# mobile-test-nhs-UAT:
# runs-on: macOS-latest
# steps:
# - name: checkout
# uses: actions/checkout@v2
# - name: set up node
# uses: actions/setup-node@v1
# - name: Set up JDK 1.8
# uses: actions/setup-java@v1
# with:
# fetch-depth: 1
# node-version: '10.16'
# java-version: 1.8
# - run: npm install -g appium
# - name: run mobile tests on NHS Dev
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: 29
# profile: Nexus 6
# script: mvn clean "-Dtest=/**/MobileAppTests/Tests/LoginTest" test
# env:
# Authorization: ${{ secrets.Authorization }}
# env: nhsUAT # required
# - name: Notify on Slack
# uses: 8398a7/action-slack@v2
# with:
# status: ${{ job.status }}
# author_name: Functional Tests on NHS UAT
# text: Functional Mobile Tests on NHS UAT
# channel: '#botcave'
# only_mention_fail: USXBM5WPQ,here
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
# if: always()

mobile-test-nhs-Sandbox:
runs-on: macOS-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: set up node
uses: actions/setup-node@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
fetch-depth: 1
node-version: '10.16'
java-version: 1.8
- run: npm install -g appium
- name: run mobile tests on NHS Dev
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
profile: Nexus 6
script: mvn clean "-Dtest=/**/MobileAppTests/Tests/LoginTest" test
env:
Authorization: ${{ secrets.Authorization }}
env: nhsSandbox # required
- name: Notify on Slack
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Functional Tests on NHS Sandbox
text: Functional Mobile Tests on NHS Sandbox
channel: '#botcave'
only_mention_fail: USXBM5WPQ,here
env:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
Env variable for local debugging
`Authorization` : `Bearer <Auth Token> ` with public_repo and workflow scope
`ConsentManagerSecret` : `Secret to generate JWT token with HIP service`

Environments

`env = ncg`
`env = nhsDev, nhsUAT, nhsSandbox `
19 changes: 17 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
<groupId>org.projecteka.tests</groupId>
<artifactId>ProjectEKA-tets</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<version>6.9.8</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
Expand All @@ -29,6 +39,11 @@
<artifactId>java-client</artifactId>
<version>7.3.0</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
Expand Down
79 changes: 79 additions & 0 deletions src/test/java/Tests/APITests/APIE2E/E2EAPITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//package Tests.APITests.APIE2E;
//
//import Tests.APITests.APIUtils.HIUConsentRequest;
//import Tests.APITests.APIUtils.PropertiesCache;
//import io.restassured.RestAssured;
//import io.restassured.builder.RequestSpecBuilder;
//import io.restassured.http.ContentType;
//import io.restassured.path.json.JsonPath;
//import io.restassured.response.Response;
//import io.restassured.specification.RequestSpecification;
//import org.testng.Assert;
//import org.testng.annotations.BeforeClass;
//import org.testng.annotations.Test;
//
//public class E2EAPITest {
// RequestSpecification specification;
//
// @BeforeClass
// public void setup() {
// RestAssured.baseURI = PropertiesCache.getInstance().getProperty("consentManagerURL");
// RestAssured.useRelaxedHTTPSValidation();
// RequestSpecBuilder builder = new RequestSpecBuilder();
// builder.setContentType(ContentType.JSON);
// specification = builder.build();
// }
//
// @Test
// public void createPatient() throws InterruptedException {
//
// RequestSpecification request = RestAssured.given().spec(specification);
// String body = "{\n" +
// "\t\"identifierType\": \"mobile\",\n" +
// "\t\"identifier\": \"+91-8888888888\"\n" +
// "}";
// Response response = request.body(body).post("/users/verify");
// JsonPath jsonPathEvaluator = response.jsonPath();
// Assert.assertEquals(response.getStatusCode(), 201);
// String id = jsonPathEvaluator.getString("sessionId");
// System.out.println(id);
//
// String userPermitRequestBody = "{\n" +
// "\t\"sessionId\": \"" + id + "\",\n" +
// "\t\"value\": \"666666\"\n" +
// "}";
//
// Response userPermitResponse = request.body(userPermitRequestBody).post("/users/permit");
// jsonPathEvaluator = userPermitResponse.jsonPath();
// System.out.println(jsonPathEvaluator.getString("temporaryToken"));
//
//
//
// }
//
// // @Test
// public void createConsentRequest() {
//
// RestAssured.baseURI = "https://hiu-dev.projecteka.in/api";
// RestAssured.useRelaxedHTTPSValidation();
//
// RequestSpecification request = RestAssured.given();
// request.header("Content-Type", "application/json");
// request.header("Authorization", "MUBuY2c=");//1@ncg
//
// HIUConsentRequest hiuConsentRequest = new HIUConsentRequest.ConsentRequestBuilder("1@ncg").buildConsentReuqest();
//
// request.body(hiuConsentRequest.getJSONRequestBody().toString());
// Response response = request.post("/consent-requests");
//
// JsonPath jsonPathEvaluator = response.jsonPath();
//
// Assert.assertEquals(response.getStatusCode(), 200);
// String id = jsonPathEvaluator.getString("id");
//
// System.out.println(id);
//
// }
//
//
//}
13 changes: 12 additions & 1 deletion src/test/java/Tests/APITests/APIUtils/PropertiesCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ public class PropertiesCache {

private PropertiesCache() {
//Private constructor to restrict new instances
InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties");
InputStream in;
if ("ncg".equalsIgnoreCase(System.getenv("env"))) {
in = this.getClass().getClassLoader().getResourceAsStream("config.properties");
} else if( "nhsDev".equalsIgnoreCase(System.getenv("env"))){
in = this.getClass().getClassLoader().getResourceAsStream("config-nhs-dev.properties");
} else if ("nhsUAT".equalsIgnoreCase(System.getenv("env"))) {
in = this.getClass().getClassLoader().getResourceAsStream("config-nhs-UAT.properties");
} else if ("nhsSandbox".equalsIgnoreCase(System.getenv("env"))) {
in = this.getClass().getClassLoader().getResourceAsStream("config-nhs-Sandbox.properties");
}
else
in = this.getClass().getClassLoader().getResourceAsStream("config-nhs-dev.properties");
System.out.println("Read all properties from file");
try {
configProp.load(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,45 @@

public class ResetPasswordAPITest {

String authToken;
String sessionId;
String otpAuthToken;
private static String sessionId;
private static String otpAuthToken;
RequestSpecification request;

@BeforeClass
public void setup() {
authToken = new LoginUser().getCMAuthToken();
RestAssured.baseURI = PropertiesCache.getInstance().getProperty("consentManagerURL");
RestAssured.useRelaxedHTTPSValidation();
request = RestAssured.given();
}

@Test
public void generateOTPAPI() {

//generate otp for enter phone #
RequestSpecification request = RestAssured.given();
request.header("Content-Type", "application/json");
request.body(new ResetPassword().getGenerateOTPRequestBody());
Response generateOTPResponse = request.post("/patients/generateotp");

Assert.assertEquals(generateOTPResponse.getStatusCode(), 201);
sessionId = generateOTPResponse.jsonPath().getString("sessionId");
}

@Test(dependsOnMethods = "generateOTPAPI")
public void verifyOTPAPI() {

//verify the otp
RequestSpecification request = RestAssured.given();
request.header("Content-Type", "application/json");
request.body(new ResetPassword().getVerifyOTPRequestBody(sessionId));
Response verifyOTPResponse = request.post("/patients/verifyotp");

Assert.assertEquals(verifyOTPResponse.getStatusCode(), 200);
otpAuthToken = verifyOTPResponse.jsonPath().getString("temporaryToken");
}

@Test(dependsOnMethods = "verifyOTPAPI")
public void resetPasswordAPI() {

//reset-password after otp confirmation
RequestSpecification request = RestAssured.given();
request.header("Content-Type", "application/json");
request.header("Authorization", otpAuthToken);
request.body(new ResetPassword().getResetPasswordRequestBody());

Response resetPasswordResponse = request.put("/patients/profile/reset-password");

Assert.assertEquals(resetPasswordResponse.getStatusCode(), 200);
}

Expand Down
Loading

0 comments on commit 0013694

Please sign in to comment.