-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from near-daos/develop
Merge develop to release branch
- Loading branch information
Showing
20 changed files
with
376 additions
and
20 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
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
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
70 changes: 70 additions & 0 deletions
70
test-framework/src/main/java/api/app/astrodao/com/core/controllers/SubscriptionsApi.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,70 @@ | ||
package api.app.astrodao.com.core.controllers; | ||
|
||
import api.app.astrodao.com.core.clients.HttpClient; | ||
import api.app.astrodao.com.core.utils.JsonUtils; | ||
import api.app.astrodao.com.openapi.models.SubscriptionDeleteDto; | ||
import api.app.astrodao.com.openapi.models.SubscriptionDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.util.Collections; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SubscriptionsApi { | ||
protected final HttpClient httpClient; | ||
|
||
@Value("${framework.api.url}") | ||
private String apiUrl; | ||
|
||
public ResponseEntity<String> subscribeDao(String accountId, String publicKey, String signature, String daoId) { | ||
HttpHeaders httpHeaders = httpClient.getBasicHeaders(); | ||
httpHeaders.setContentType(MediaType.APPLICATION_JSON); | ||
httpHeaders.setAccept(Collections.singletonList(MediaType.ALL)); | ||
|
||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(apiUrl); | ||
builder.pathSegment("subscriptions"); | ||
|
||
SubscriptionDto subscriptionDto = new SubscriptionDto(); | ||
subscriptionDto.setAccountId(accountId); | ||
subscriptionDto.setPublicKey(publicKey); | ||
subscriptionDto.setSignature(signature); | ||
subscriptionDto.setDaoId(daoId); | ||
|
||
HttpEntity<?> httpEntity = new HttpEntity<>(JsonUtils.writeValueAsString(subscriptionDto), httpHeaders); | ||
return httpClient.post(builder.toUriString(), httpEntity, String.class); | ||
} | ||
|
||
public ResponseEntity<String> accountSubscriptions(String accountId) { | ||
HttpHeaders httpHeaders = httpClient.getBasicHeaders(); | ||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); | ||
|
||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(apiUrl); | ||
builder.pathSegment("subscriptions", "account-subscriptions", "{accountId}"); | ||
|
||
return httpClient.get(builder.build().toString(), new HttpEntity<>(httpHeaders), String.class, accountId); | ||
} | ||
|
||
public ResponseEntity<String> deleteSubscription(String accountId, String publicKey, String signature, String daoId) { | ||
HttpHeaders httpHeaders = httpClient.getBasicHeaders(); | ||
httpHeaders.setContentType(MediaType.APPLICATION_JSON); | ||
httpHeaders.setAccept(Collections.singletonList(MediaType.ALL)); | ||
|
||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(apiUrl); | ||
builder.pathSegment("subscriptions", daoId); | ||
|
||
SubscriptionDeleteDto subscriptionDto = new SubscriptionDeleteDto(); | ||
subscriptionDto.setAccountId(accountId); | ||
subscriptionDto.setPublicKey(publicKey); | ||
subscriptionDto.setSignature(signature); | ||
|
||
HttpEntity<?> httpEntity = new HttpEntity<>(JsonUtils.writeValueAsString(subscriptionDto), httpHeaders); | ||
return httpClient.delete(builder.toUriString(), httpEntity, String.class); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...framework/src/main/java/api/app/astrodao/com/core/dto/api/subscription/Subscriptions.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,8 @@ | ||
package api.app.astrodao.com.core.dto.api.subscription; | ||
|
||
import api.app.astrodao.com.openapi.models.Subscription; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Subscriptions extends ArrayList<Subscription> { | ||
} |
7 changes: 7 additions & 0 deletions
7
...framework/src/main/java/api/app/astrodao/com/core/exceptions/EntityNotFoundException.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,7 @@ | ||
package api.app.astrodao.com.core.exceptions; | ||
|
||
public class EntityNotFoundException extends RuntimeException { | ||
public EntityNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...amework/src/main/java/api/app/astrodao/com/core/exceptions/NotEnoughBalanceExecution.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,7 @@ | ||
package api.app.astrodao.com.core.exceptions; | ||
|
||
public class NotEnoughBalanceExecution extends RuntimeException { | ||
public NotEnoughBalanceExecution(String message) { | ||
super(message); | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
test-framework/src/test/java/api/app/astrodao/com/steps/SubscriptionsApiSteps.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,60 @@ | ||
package api.app.astrodao.com.steps; | ||
|
||
import api.app.astrodao.com.core.annotations.Steps; | ||
import api.app.astrodao.com.core.controllers.SubscriptionsApi; | ||
import api.app.astrodao.com.core.dto.api.subscription.Subscriptions; | ||
import api.app.astrodao.com.core.exceptions.EntityNotFoundException; | ||
import api.app.astrodao.com.openapi.models.Subscription; | ||
import io.qameta.allure.Step; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
|
||
@Steps | ||
@RequiredArgsConstructor | ||
public class SubscriptionsApiSteps extends BaseSteps { | ||
private final SubscriptionsApi subscriptionsApi; | ||
|
||
public void cleanUpSubscriptions(String accountId, String publicKey, String signature) { | ||
ResponseEntity<String> response = subscriptionsApi.accountSubscriptions(accountId); | ||
assertResponseStatusCode(response, HttpStatus.OK); | ||
Subscriptions subscriptions = getResponseDto(response, Subscriptions.class); | ||
subscriptions.forEach(p -> { | ||
ResponseEntity<String> resp = subscriptionsApi.deleteSubscription(accountId, publicKey, signature, p.getId()); | ||
assertResponseStatusCode(resp, HttpStatus.OK); | ||
}); | ||
} | ||
|
||
@Step("User subscribes to DAO") | ||
public ResponseEntity<String> subscribeDao(String accountId, String publicKey, String signature, String daoId) { | ||
return subscriptionsApi.subscribeDao(accountId, publicKey, signature, daoId); | ||
} | ||
|
||
@Step("User get subscriptions") | ||
public ResponseEntity<String> accountSubscriptions(String accountId) { | ||
return subscriptionsApi.accountSubscriptions(accountId); | ||
} | ||
|
||
@Step("User deletes subscription") | ||
public ResponseEntity<String> deleteSubscription(String accountId, String publicKey, String signature, String daoId) { | ||
return subscriptionsApi.deleteSubscription(accountId, publicKey, signature, daoId); | ||
} | ||
|
||
public Subscription getCreatedSubscription(Subscriptions subscriptions, String subscriptionId) { | ||
return subscriptions.stream() | ||
.filter(p -> Objects.equals(p.getId(), subscriptionId)).findFirst() | ||
.orElseThrow(() -> new EntityNotFoundException("Subscription not found")); | ||
} | ||
|
||
@Step("User sees subscription is not present in a list") | ||
public void verifySubscriptionHasBeenDeleted(Subscriptions subscriptions, String subscriptionId) { | ||
assertThat(subscriptions) | ||
.as(String.format("'%s' subscription should not be present in collection.", subscriptionId)) | ||
.map(Subscription::getId) | ||
.doesNotContain(subscriptionId); | ||
} | ||
} |
Oops, something went wrong.