Skip to content

Commit

Permalink
Fix broken tests and automate maven publish (#7)
Browse files Browse the repository at this point in the history
* Add return_url field to PostData

* Create ChapaException class to handle 4XX and 5XX response codes

* Prepare 1.2.2 release

* Prepare 1.2.2 release

* Fix broken tests

* Update README.md

* Automate publish to maven to workflow
  • Loading branch information
yaphet17 committed Jun 1, 2023
1 parent c4c1199 commit 2538296
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/maven-publish.yml
@@ -0,0 +1,31 @@
name: Publish package to the Maven Central Repository
on:
push:
branches:
- main
paths:
- 'docs/**'
- 'src/**'
- 'pom.xml'
workflow_dispatch:


jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Publish package
run: mvn --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -36,16 +36,19 @@ Visit official [Chapa's API Documentation](https://developer.chapa.co/docs)
<dependency>
<groupId>io.github.yaphet17</groupId>
<artifactId>Chapa</artifactId>
<version>1.1.0</version>
<version>1.2.2</version>
</dependency>
```
Or add the below gradle dependency to your `build.gradle` file.
```groovy
implementation 'io.github.yaphet17:Chapa:1.1.0'
implementation 'io.github.yaphet17:Chapa:1.2.2'
```

## Usage

> **Note** : This doc is not updated with the latest changes of this library (which have several amazing but breaking ): changes). I appreciate any contribution to the docs until I find some time to do it my self.

Instantiate a `Chapa` class.
```java
Chapa chapa = new Chapa("your-secrete-key");
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/yaphet/chapa/ChapaTest.java
Expand Up @@ -80,6 +80,7 @@ public void shouldInitializeTransaction_asString() throws Throwable {

// when
when(chapaClient.post(anyString(), anyMap(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
String actualResponse = underTest.initialize(postData).asString();

// then
Expand All @@ -93,12 +94,14 @@ public void shouldInitializeTransaction_asResponseData() throws Throwable {
InitializeResponseData expectedResponseData = new InitializeResponseData()
.setMessage("Transaction reference has been used before")
.setStatus("failed")
.setStatusCode(200)
.setData(new InitializeResponseData.Data().setCheckOutUrl("https://checkout.chapa.co/checkout/payment/somestring"));

String expectedResponse = "{\"data\":{\"checkout_url\":\"https://checkout.chapa.co/checkout/payment/somestring\"},\"message\":\"Transaction reference has been used before\",\"status\":\"failed\"}";

// when
when(chapaClient.post(anyString(), anyMap(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
InitializeResponseData actualResponseData = underTest.initialize(postData);

// then
Expand All @@ -113,6 +116,7 @@ public void shouldInitializeTransaction_With_Json_Input() throws Throwable {

// when
when(chapaClient.post(anyString(), anyString(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
String actualResponse = underTest.initialize(postDataString).asString();

// then
Expand All @@ -127,6 +131,7 @@ public void shouldVerifyTransaction_asString() throws Throwable {

// when
when(chapaClient.get(anyString(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
String actualResponse = underTest.verify("test-transaction").asString();

// then
Expand All @@ -140,11 +145,13 @@ public void shouldVerifyTransaction_asResponseData() throws Throwable {
VerifyResponseData expectedResponseData = new VerifyResponseData()
.setMessage("Payment not paid yet")
.setStatus("null")
.setStatusCode(200)
.setData(null);
String expectedResponse = "{\"data\":null,\"message\":\"Payment not paid yet\",\"status\":\"null\"}";

// when
when(chapaClient.get(anyString(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
VerifyResponseData actualResponseData = underTest.verify("test-transaction");

// then
Expand All @@ -166,6 +173,7 @@ public void shouldGetListOfBanks() throws Throwable {
.setUpdatedAt("2022-07-04T21:34:03.000000Z"));
// when
when(chapaClient.get(anyString(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
List<Bank> actualBanks = underTest.banks();

// then
Expand All @@ -180,6 +188,7 @@ public void shouldCreateSubAccount_asString() throws Throwable {

// when
when(chapaClient.post(anyString(), anyMap(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
String actualResponse = underTest.createSubAccount(subAccount).asString();

// then
Expand All @@ -194,6 +203,7 @@ public void shouldCreateSubAccount_With_Json_Input() throws Throwable {

// when
when(chapaClient.post(anyString(), anyString(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
String actualResponse = underTest.createSubAccount(subAccountString).asString();

// then
Expand All @@ -207,11 +217,13 @@ public void shouldCreateSubAccount_asResponseData() throws Throwable {
SubAccountResponseData expectedResponseData = new SubAccountResponseData()
.setMessage("The Bank Code is incorrect please check if it does exist with our getbanks endpoint.")
.setStatus("failed")
.setStatusCode(200)
.setData(null);
String expectedResponse = "{\"data\":null,\"message\":\"The Bank Code is incorrect please check if it does exist with our getbanks endpoint.\",\"status\":\"failed\"}";

// when
when(chapaClient.post(anyString(), anyMap(), anyString())).thenReturn(expectedResponse);
when(chapaClient.getStatusCode()).thenReturn(200);
SubAccountResponseData actualResponse = underTest.createSubAccount(subAccount);

// then
Expand Down

0 comments on commit 2538296

Please sign in to comment.