-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PAYINS-504): Set Authorization header to `GET v3/payments-provid…
…ers/{id}` (#270)
- Loading branch information
1 parent
171cdde
commit 5233eec
Showing
7 changed files
with
92 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/main/java/com/truelayer/java/paymentsproviders/PaymentsProvidersHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
package com.truelayer.java.paymentsproviders; | ||
|
||
import static com.truelayer.java.Constants.Scopes.PAYMENTS; | ||
|
||
import com.truelayer.java.IAuthenticatedHandler; | ||
import com.truelayer.java.entities.RequestScopes; | ||
import com.truelayer.java.http.entities.ApiResponse; | ||
import com.truelayer.java.paymentsproviders.entities.PaymentsProvider; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.Value; | ||
import lombok.Builder; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Value | ||
public class PaymentsProvidersHandler implements IPaymentsProvidersHandler { | ||
|
||
String clientId; | ||
@Builder | ||
public class PaymentsProvidersHandler implements IAuthenticatedHandler, IPaymentsProvidersHandler { | ||
|
||
IPaymentsProvidersApi paymentsProvidersApi; | ||
|
||
public static PaymentsProvidersHandlerBuilder New() { | ||
return new PaymentsProvidersHandlerBuilder(); | ||
@Builder.Default | ||
private RequestScopes scopes = RequestScopes.builder().scope(PAYMENTS).build(); | ||
|
||
@Override | ||
public RequestScopes getRequestScopes() { | ||
return scopes; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ApiResponse<PaymentsProvider>> getProvider(String providerId) { | ||
return paymentsProvidersApi.getProvider(providerId, clientId); | ||
return paymentsProvidersApi.getProvider(getRequestScopes(), providerId); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/com/truelayer/java/paymentsproviders/PaymentsProvidersHandlerBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/com/truelayer/java/paymentsproviders/PaymentsProvidersHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.truelayer.java.paymentsproviders; | ||
|
||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.truelayer.java.Constants; | ||
import com.truelayer.java.entities.RequestScopes; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class PaymentsProvidersHandlerTests { | ||
|
||
private static final String A_PROVIDER_ID = "a-provider-id"; | ||
private static final RequestScopes SCOPES = | ||
RequestScopes.builder().scope("a-custom-scope").build(); | ||
|
||
private PaymentsProvidersHandler sut; | ||
private IPaymentsProvidersApi paymentsProvidersApiMock; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
paymentsProvidersApiMock = Mockito.mock(IPaymentsProvidersApi.class); | ||
sut = PaymentsProvidersHandler.builder() | ||
.paymentsProvidersApi(paymentsProvidersApiMock) | ||
.scopes(SCOPES) | ||
.build(); | ||
} | ||
|
||
@Test | ||
@DisplayName("It should call the get payments-providers by id endpoint with the default scopes") | ||
public void shouldCallCreatePaymentWithDefaultScopes() { | ||
PaymentsProvidersHandler sut = PaymentsProvidersHandler.builder() | ||
.paymentsProvidersApi(paymentsProvidersApiMock) | ||
.build(); | ||
|
||
sut.getProvider(A_PROVIDER_ID); | ||
|
||
RequestScopes expectedDefaultScopes = | ||
RequestScopes.builder().scope(Constants.Scopes.PAYMENTS).build(); | ||
verify(paymentsProvidersApiMock, times(1)).getProvider(expectedDefaultScopes, A_PROVIDER_ID); | ||
} | ||
|
||
@Test | ||
@DisplayName("It should call the get payments-providers by id endpoint") | ||
public void shouldCallGetPaymentById() { | ||
sut.getProvider(A_PROVIDER_ID); | ||
|
||
verify(paymentsProvidersApiMock, times(1)).getProvider(SCOPES, A_PROVIDER_ID); | ||
} | ||
} |