Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support specify user in buy-product api #94

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/org/casbin/casdoor/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public CasdoorResponse<String, Object> updateProduct(Product product) throws IOE
return modifyProduct(ProductOperations.UPDATE_PRODUCT, product, null);
}

public Product buyProduct(String name, String providerName) throws IOException {
public Product buyProduct(String name, String providerName, String userName) throws IOException {
java.util.Map<String, String> queryMap = Map.of(
"id", config.organizationName + "/" + name,
"providerName", providerName
"providerName", providerName,
"userName", userName
);
CasdoorResponse<Product, Object> response = doPost("buy-product", queryMap, "", new TypeReference<CasdoorResponse<Product, Object>>() {
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/casbin/casdoor/ProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -47,6 +48,8 @@ public void testProduct() {
0,
"Published"
);
product.providers = new ArrayList<>();
product.providers.add("provider_payment_dummy");
assertDoesNotThrow(() -> productService.addProduct(product));

// Get all objects, check if our added object is inside the list
Expand Down Expand Up @@ -89,7 +92,7 @@ public void testProduct() {
// Test the buyProduct function
Product boughtProduct;
try {
boughtProduct = productService.buyProduct(name, "provider_payment_paypal");
boughtProduct = productService.buyProduct(name, "provider_payment_dummy", "admin");
} catch (Exception e) {
String errorMessage = e.getMessage();
if (errorMessage.contains("The user") && errorMessage.contains("doesn't exist")) {
Expand Down
Loading