Skip to content

Commit

Permalink
Merge pull request #88 from UdL-EPS-SoftArch/83-feature-getadvertisment
Browse files Browse the repository at this point in the history
83 feature getadvertisment
  • Loading branch information
rogargon authored Nov 5, 2024
2 parents 790b18c + e723f25 commit de69b23
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cat.udl.eps.softarch.demo.steps;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

import cat.udl.eps.softarch.demo.repository.ApartmentRepository;
import io.cucumber.java.en.And;
import org.springframework.http.MediaType;
import cat.udl.eps.softarch.demo.domain.*;
import cat.udl.eps.softarch.demo.repository.AdvertisementRepository;
import cat.udl.eps.softarch.demo.repository.AdvertisementStatusRepository;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

import java.math.BigDecimal;
import java.time.ZonedDateTime;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class GetAdvertismentStepDefs {

@Autowired
private AdvertisementRepository advertisementRepository;

@Autowired
private ApartmentRepository apartmentRepository;
@Autowired
private AdvertisementStatusRepository advertisementStatusRepository;
private AdvertisementStatus status;
private ResponseEntity<String> response;
@Autowired
private StepDefs stepDefs;

@When("I get the apartment advertisement with title {string}")
public void iGetTheApartmentAdvertisement(String title) throws Exception {
Advertisement ad = advertisementRepository.findByTitle(title).stream().findFirst().orElse(null);

if (ad == null) {
stepDefs.result = stepDefs.mockMvc.perform(
get("/advertisements/{id}", 9999)
.accept(MediaType.APPLICATION_JSON)
).andDo(print());
} else {
stepDefs.result = stepDefs.mockMvc.perform(
get("/advertisements/{id}", ad.getId())
.accept(MediaType.APPLICATION_JSON)
).andDo(print());
}
}

}
28 changes: 28 additions & 0 deletions src/test/resources/features/GetAdvertisment.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Get Advertisement
In order to use the app
users can retrieve advertisement details for existing apartments

Scenario: Get an existing apartment advertisement by title
Given There is an existing apartment with id "1" named "Cozy Apartment"
And I login as "owner" with password "password"
And There is an existing advertisement status "Available"
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment"
When I get the apartment advertisement with title "Apartment for rent"
Then The response code is 200

Scenario: Get a non-existing apartment advertisement by title
Given There is an existing apartment with id "1" named "Cozy Apartment"
And I login as "owner" with password "password"
And There is an existing advertisement status "Available"
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment"
When I get the apartment advertisement with title "non existing title"
Then The response code is 404


Scenario: Get apartment advertisement when not authenticated
Given There is an existing apartment with id "1" named "Cozy Apartment"
And There is an existing advertisement status "Available"
And There is an advertisement with title "Apartment for rent", description "A beautiful apartment", price "1200", zipCode "12345", address "456 Elm St", country "Spain", status "Available", apartment title "Cozy Apartment"
Given I'm not logged in
When I get the apartment advertisement with title "Apartment for rent"
Then The response code is 200

0 comments on commit de69b23

Please sign in to comment.