Skip to content
Snippets Groups Projects
Commit a96d2a69 authored by zeshan's avatar zeshan
Browse files

Merge branch 'zeshan_dev' into 'main'

3.7 Advertisement Sequence BDD updated

See merge request !108
parents b28edb39 4bac1174
No related branches found
No related tags found
1 merge request!1083.7 Advertisement Sequence BDD updated
Pipeline #47106 passed
Feature: Search Results Display based on Interested/Not Interested
Scenario: Display properties in the correct order based on availability and interest status
Given a user performs a search for properties
When the search results are displayed
Then the results should first show available properties not marked as "Not Interested"
And then show reserved properties not marked as "Not Interested"
And then show available properties marked as "Not Interested"
And finally show reserved properties marked as "Not Interested"
Scenario: Results fail to display properties in the correct order
Given a user performs a search for properties!
When the search results are displayed!
Then the results should fail to show available properties not marked as "Not Interested" first
And then fail to show reserved properties not marked as "Not Interested"
And then fail to show available properties marked as "Not Interested"
And finally fail to show reserved properties marked as "Not Interested"
......@@ -39,6 +39,11 @@ defmodule WhiteBreadConfig do
context: ProptrackerWeb.Features.Contexts.FilterSearchContext,
feature_paths: ["features/3.1_2_etc_search.feature"]
suite name: "3.7_Adv_Sequence",
context: ProptrackerWeb.SearchResultsContext,
feature_paths: ["features/3.7_adv_sequence.feature"]
suite name: "3.15_recommended_properties_Suite",
context: ProptrackerWeb.Features.Contexts.RecommendedPropertiesContext,
feature_paths: ["features/3.15_recommended_properties.feature"]
......@@ -82,4 +87,5 @@ suite name: "2.2_own_adv_show",
feature_paths: ["features/2.2_own_adv_show.feature"]
end
defmodule ProptrackerWeb.SearchResultsContext do
use WhiteBread.Context
import Plug.Conn
import Ecto.Query
import Phoenix.ConnTest
alias Proptracker.Repo
alias Proptracker.Accounts.{User, Advertisement}
# Given a user performs a search for properties
given_ ~r/^a user performs a search for properties$/ do
fn state ->
# Simulate user performing a search
user_data = %{username: "search_user", password: "password123", password_confirmation: "password123"}
# Register the user
changeset = User.registration_changeset(%User{}, user_data)
{:ok, user} = Repo.insert(changeset)
# Create mock advertisements with different statuses and interest states
ad_data = [
%{user_id: user.id, title: "Available Ad 1", type: "available", interested: false},
%{user_id: user.id, title: "Reserved Ad 1", type: "reserved", interested: false},
%{user_id: user.id, title: "Available Ad 2", type: "available", interested: true},
%{user_id: user.id, title: "Reserved Ad 2", type: "reserved", interested: true}
]
Enum.each(ad_data, fn ad ->
Repo.insert!(%Advertisement{} |> Advertisement.changeset(ad))
end)
{:ok, Map.put(state, :user, user)}
end
end
# When the search results are displayed
when_ ~r/^the search results are displayed$/ do
fn state ->
conn = %Plug.Conn{} |> Plug.Test.init_test_session(user_id: state[:user].id)
# Fetch and order advertisements based on the requirements
results =
Repo.all(
from a in Advertisement,
order_by: [
asc: fragment("CASE WHEN type = 'available' AND interested = false THEN 1 WHEN type = 'reserved' AND interested = false THEN 2 WHEN type = 'available' AND interested = true THEN 3 ELSE 4 END")
]
)
{:ok, Map.put(state, :results, results)}
end
end
# Then the results should first show available properties not marked as "Not Interested"
then_ ~r/^the results should first show available properties not marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 0).type == "available"
assert Enum.at(state[:results], 0).interested == false
{:ok, state}
end
end
# And then show reserved properties not marked as "Not Interested"
and_ ~r/^then show reserved properties not marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 1).type == "reserved"
assert Enum.at(state[:results], 1).interested == false
{:ok, state}
end
end
# And then show available properties marked as "Not Interested"
and_ ~r/^then show available properties marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 2).type == "available"
assert Enum.at(state[:results], 2).interested == true
{:ok, state}
end
end
# And finally show reserved properties marked as "Not Interested"
and_ ~r/^finally show reserved properties marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 3).type == "reserved"
assert Enum.at(state[:results], 3).interested == true
{:ok, state}
end
end
###Negative Case:
# Given a user performs a search for properties
given_ ~r/^a user performs a search for properties!$/ do
fn state ->
# Simulate user performing a search
user_data = %{username: "negative_case_user", password: "password123", password_confirmation: "password123"}
# Register the user
changeset = User.registration_changeset(%User{}, user_data)
{:ok, user} = Repo.insert(changeset)
# Create mock advertisements with an incorrect order
ad_data = [
%{user_id: user.id, title: "Reserved Ad 1", type: "reserved", interested: false}, # Should not appear first
%{user_id: user.id, title: "Available Ad 1", type: "available", interested: false}, # Should appear first
%{user_id: user.id, title: "Available Ad 2", type: "available", interested: true}, # Should appear later
%{user_id: user.id, title: "Reserved Ad 2", type: "reserved", interested: true} # Should appear last
]
Enum.each(ad_data, fn ad ->
Repo.insert!(%Advertisement{} |> Advertisement.changeset(ad))
end)
{:ok, Map.put(state, :user, user)}
end
end
# When the search results are displayed
when_ ~r/^the search results are displayed!$/ do
fn state ->
conn = %Plug.Conn{} |> Plug.Test.init_test_session(user_id: state[:user].id)
# Fetch and order advertisements (simulate incorrect order for negative test)
results =
Repo.all(
from a in Advertisement,
order_by: [
desc: fragment("CASE
WHEN type = 'available' AND interested = false THEN 1
WHEN type = 'reserved' AND interested = false THEN 2
WHEN type = 'available' AND interested = true THEN 3
ELSE 4
END")
] # Deliberately use descending order to simulate a failing scenario
)
{:ok, Map.put(state, :results, results)}
end
end
# Then the results should fail to show available properties not marked as "Not Interested" first
then_ ~r/^the results should fail to show available properties not marked as "Not Interested" first$/ do
fn state ->
assert Enum.at(state[:results], 0).type != "available" or Enum.at(state[:results], 0).interested != false
{:ok, state}
end
end
# And then fail to show reserved properties not marked as "Not Interested"
and_ ~r/^then fail to show reserved properties not marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 1).type != "reserved" or Enum.at(state[:results], 1).interested != false
{:ok, state}
end
end
# And fail to show available properties marked as "Not Interested"
and_ ~r/^then fail to show available properties marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 2).type != "available" or Enum.at(state[:results], 2).interested != true
{:ok, state}
end
end
# And finally fail to show reserved properties marked as "Not Interested"
and_ ~r/^finally fail to show reserved properties marked as "Not Interested"$/ do
fn state ->
assert Enum.at(state[:results], 3).type != "reserved" or Enum.at(state[:results], 3).interested != true
{:ok, state}
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment