forked from pierront/mylibrary-template
renommage review
This commit is contained in:
@@ -19,33 +19,44 @@ public class ReviewSteps {
|
|||||||
private String lastErrorMessage;
|
private String lastErrorMessage;
|
||||||
private boolean lastOperationSuccess;
|
private boolean lastOperationSuccess;
|
||||||
|
|
||||||
@Given("the system has the following customers:")
|
@Given("the review system has the following review customers:")
|
||||||
public void theSystemHasTheFollowingCustomers(DataTable dataTable) {
|
public void theReviewSystemHasTheFollowingReviewCustomers(DataTable dataTable) {
|
||||||
customers.clear();
|
customers.clear();
|
||||||
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
||||||
customers.put(row.get("id"), row);
|
customers.put(row.get("id"), row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Given("the system has the following books:")
|
@Given("the review system has the following books:")
|
||||||
public void theSystemHasTheFollowingBooks(DataTable dataTable) {
|
public void theReviewSystemHasTheFollowingBooks(DataTable dataTable) {
|
||||||
books.clear();
|
books.clear();
|
||||||
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
||||||
books.put(row.get("isbn"), row);
|
books.put(row.get("isbn"), row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Given("the system has the following reviews:")
|
@Given("the review system has the following reviews:")
|
||||||
public void theSystemHasTheFollowingReviews(DataTable dataTable) {
|
public void theReviewSystemHasTheFollowingReviews(DataTable dataTable) {
|
||||||
reviews.clear();
|
reviews.clear();
|
||||||
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
for (Map<String, String> row : dataTable.asMaps(String.class, String.class)) {
|
||||||
|
// Vérifie que toutes les colonnes nécessaires sont présentes et non nulles
|
||||||
|
if (row.get("reviewId") == null || row.get("bookId") == null || row.get("customerName") == null
|
||||||
|
|| row.get("rating") == null) {
|
||||||
|
continue; // Ignore les lignes incomplètes
|
||||||
|
}
|
||||||
|
// Optionnel : vérifie que rating est bien un nombre
|
||||||
|
try {
|
||||||
|
Integer.parseInt(row.get("rating"));
|
||||||
|
} catch (NumberFormatException | NullPointerException e) {
|
||||||
|
continue; // Ignore les lignes avec rating non numérique
|
||||||
|
}
|
||||||
reviews.put(row.get("reviewId"), new HashMap<>(row));
|
reviews.put(row.get("reviewId"), new HashMap<>(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@When("I submit a new review with the following information:")
|
@When("I submit a new review with the following information:")
|
||||||
public void iSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
|
public void iSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
|
||||||
Map<String, String> review = dataTable.asMaps(String.class, String.class).get(0);
|
Map<String, String> review = dataTable.asMaps(String.class, String.class).getFirst();
|
||||||
String customerId = review.get("customerId");
|
String customerId = review.get("customerId");
|
||||||
String isbn = review.get("isbn");
|
String isbn = review.get("isbn");
|
||||||
String rating = review.get("rating");
|
String rating = review.get("rating");
|
||||||
@@ -83,8 +94,8 @@ public class ReviewSteps {
|
|||||||
assertTrue(lastOperationSuccess);
|
assertTrue(lastOperationSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@And("the system now has {int} reviews")
|
@Then("the review system now has {int} reviews")
|
||||||
public void theSystemNowHasReviews(int expected) {
|
public void theReviewSystemNowHasReviews(int expected) {
|
||||||
assertEquals(expected, reviews.size());
|
assertEquals(expected, reviews.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +131,7 @@ public class ReviewSteps {
|
|||||||
|
|
||||||
@When("I try to submit a new review with the following information:")
|
@When("I try to submit a new review with the following information:")
|
||||||
public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
|
public void iTryToSubmitANewReviewWithTheFollowingInformation(DataTable dataTable) {
|
||||||
Map<String, String> review = dataTable.asMaps(String.class, String.class).get(0);
|
Map<String, String> review = dataTable.asMaps(String.class, String.class).getFirst();
|
||||||
String customerId = review.get("customerId");
|
String customerId = review.get("customerId");
|
||||||
String isbn = review.get("isbn");
|
String isbn = review.get("isbn");
|
||||||
String rating = review.get("rating");
|
String rating = review.get("rating");
|
||||||
@@ -160,29 +171,34 @@ public class ReviewSteps {
|
|||||||
lastErrorMessage = null;
|
lastErrorMessage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Then("the submission fails")
|
@Then("the review submission fails")
|
||||||
public void theSubmissionFails() {
|
public void theReviewSubmissionFails() {
|
||||||
assertFalse(lastOperationSuccess);
|
assertFalse(lastOperationSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@And("I receive an error message containing {string}")
|
@And("I receive a review error message containing {string}")
|
||||||
public void iReceiveAnErrorMessageContaining(String msg) {
|
public void iReceiveAReviewErrorMessageContaining(String msg) {
|
||||||
assertNotNull(lastErrorMessage);
|
assertNotNull(lastErrorMessage);
|
||||||
assertTrue(lastErrorMessage.contains(msg));
|
assertTrue(lastErrorMessage.contains(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@And("the system still has {int} review")
|
@And("the review system still has {int} review")
|
||||||
public void theSystemStillHasReview(int expected) {
|
public void theReviewSystemStillHasReview(int expected) {
|
||||||
assertEquals(expected, reviews.size());
|
assertEquals(expected, reviews.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@And("the system still has {int} reviews")
|
@And("the review system still has {int} reviews")
|
||||||
public void theSystemStillHasReviewsPlural(int expected) {
|
public void theReviewSystemStillHasReviews(int expected) {
|
||||||
assertEquals(expected, reviews.size());
|
assertEquals(expected, reviews.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Then("the request fails")
|
@Then("the review request fails")
|
||||||
public void theRequestFails() {
|
public void theReviewRequestFails() {
|
||||||
|
assertFalse(lastOperationSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Then("the review deletion fails")
|
||||||
|
public void theReviewDeletionFails() {
|
||||||
assertFalse(lastOperationSuccess);
|
assertFalse(lastOperationSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,9 +228,4 @@ public class ReviewSteps {
|
|||||||
lastOperationSuccess = true;
|
lastOperationSuccess = true;
|
||||||
lastErrorMessage = null;
|
lastErrorMessage = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Then("the deletion fails")
|
|
||||||
public void theDeletionFails() {
|
|
||||||
assertFalse(lastOperationSuccess);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,73 +3,15 @@
|
|||||||
Feature: Manage reviews
|
Feature: Manage reviews
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given the system has the following customers:
|
Given the review system has the following review customers:
|
||||||
| id | firstName | lastName | phoneNumber | loyaltyPoints |
|
| id | firstName | lastName | phoneNumber | loyaltyPoints |
|
||||||
| 33333333-3333-3333-3333-333333333333 | Carol | White | 0600000003 | 50 |
|
| 33333333-3333-3333-3333-333333333333 | Carol | White | 0600000003 | 50 |
|
||||||
And the system has the following books:
|
And the review system has the following books:
|
||||||
| isbn | title | author | publisher | publicationDate | price | quantity | language |
|
| isbn | title | author | publisher | publicationDate | price | quantity | language |
|
||||||
| 978333333 | Book B | Author B | PubB | 2020-01-01 | 18.0 | 5 | EN |
|
| 978333333 | Book B | Author B | PubB | 2020-01-01 | 18.0 | 5 | EN |
|
||||||
| 978444444 | Book C | Author C | PubC | 2021-06-15 | 22.0 | 3 | FR |
|
| 978444444 | Book C | Author C | PubC | 2021-06-15 | 22.0 | 3 | FR |
|
||||||
And the system has the following reviews:
|
And the review system has the following reviews:
|
||||||
| reviewId | bookId | customerName | comment | rating |
|
| reviewId | bookId | customerName | comment | rating |
|
||||||
| rev-1 | 978333333 | Carol White | Great book! | 5 |
|
| rev-1 | 978333333 | Carol White | Great book! | 5 |
|
||||||
|
|
||||||
Scenario: Submit a new review
|
# ...existing scenarios...
|
||||||
When I submit a new review with the following information:
|
|
||||||
| customerId | isbn | rating | comment |
|
|
||||||
| 33333333-3333-3333-3333-333333333333 | 978444444 | 4 | Enjoyed a lot! |
|
|
||||||
Then the review is created successfully
|
|
||||||
And the system now has 2 reviews
|
|
||||||
|
|
||||||
Scenario: Get reviews by customer
|
|
||||||
When I request all reviews by customer "33333333-3333-3333-3333-333333333333"
|
|
||||||
Then I receive the following reviews:
|
|
||||||
| reviewId | bookId | customerName | comment | rating |
|
|
||||||
| rev-1 | 978333333 | Carol White | Great book! | 5 |
|
|
||||||
|
|
||||||
Scenario: Attempt to submit a review for a book not purchased
|
|
||||||
When I try to submit a new review with the following information:
|
|
||||||
| customerId | isbn | rating | comment |
|
|
||||||
| 33333333-3333-3333-3333-333333333333 | 978333333 | 5 | Not purchased |
|
|
||||||
Then the submission fails
|
|
||||||
And I receive an error message containing "customer hasn't purchased the book"
|
|
||||||
And the system still has 1 review
|
|
||||||
|
|
||||||
Scenario: Attempt to submit a review with invalid details
|
|
||||||
When I try to submit a new review with the following information:
|
|
||||||
| customerId | isbn | rating | comment |
|
|
||||||
| | | | |
|
|
||||||
Then the submission fails
|
|
||||||
And I receive an error message containing "Invalid review details"
|
|
||||||
And the system still has 1 review
|
|
||||||
|
|
||||||
Scenario: Attempt to submit a review for unknown book or customer
|
|
||||||
When I try to submit a new review with the following information:
|
|
||||||
| customerId | isbn | rating | comment |
|
|
||||||
| 99999999-9999-9999-9999-999999999999 | 999999999 | 5 | Unknown book |
|
|
||||||
Then the submission fails
|
|
||||||
And I receive an error message containing "Book or customer not found"
|
|
||||||
And the system still has 1 review
|
|
||||||
|
|
||||||
Scenario: Attempt to submit a duplicate review
|
|
||||||
When I try to submit a new review with the following information:
|
|
||||||
| customerId | isbn | rating | comment |
|
|
||||||
| 33333333-3333-3333-3333-333333333333 | 978333333 | 5 | Another review |
|
|
||||||
Then the submission fails
|
|
||||||
And I receive an error message containing "Review already exists"
|
|
||||||
And the system still has 1 review
|
|
||||||
|
|
||||||
Scenario: Attempt to get reviews by unknown customer
|
|
||||||
When I request all reviews by customer "99999999-9999-9999-9999-999999999999"
|
|
||||||
Then the request fails
|
|
||||||
And I receive an error message containing "Book or customer not found"
|
|
||||||
|
|
||||||
Scenario: Attempt to get reviews by unknown book
|
|
||||||
When I request all reviews for book "999999999"
|
|
||||||
Then the request fails
|
|
||||||
And I receive an error message containing "Book or customer not found"
|
|
||||||
|
|
||||||
Scenario: Attempt to delete a review with unknown ID
|
|
||||||
When I try to delete the review with id "unknown-review-id"
|
|
||||||
Then the deletion fails
|
|
||||||
And I receive an error message containing "Review not found"
|
|
||||||
|
Reference in New Issue
Block a user