-
Notifications
You must be signed in to change notification settings - Fork 0
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 #56 from Chat-Your-Way/CHAT-203--handling-complain…
…ts-about-topics Chat 203 handling complaints about topics
- Loading branch information
Showing
10 changed files
with
192 additions
and
19 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
6 changes: 6 additions & 0 deletions
6
...main/resources/db/migration/V0026__add_has_complaint_column_in_table_topic_subscriber.sql
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,6 @@ | ||
ALTER TABLE chat.topic_subscriber | ||
ADD has_complaint boolean DEFAULT false; | ||
|
||
UPDATE chat.topic_subscriber | ||
SET has_complaint = false | ||
where contact_id > 0; |
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 |
---|---|---|
|
@@ -187,4 +187,75 @@ public void shouldThrowTopicNotFoundException_whenUserMarkTopicAsFavouriteAndTop | |
() -> topicSubscriberService.removeTopicFromFavourite(topicId, contact)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.INSERT) | ||
@DatabaseTearDown( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.DELETE) | ||
@DisplayName( | ||
"should successfully complain topic when user complain topic") | ||
public void shouldSuccessfullyComplainTopic_whenUserComplainTopic() { | ||
// Given | ||
var contactEmail = "[email protected]"; | ||
var contact = contactService.findByEmail(contactEmail); | ||
var topicId = 111123; | ||
|
||
// When | ||
topicSubscriberService.complainTopic(topicId, contact); | ||
|
||
// Then | ||
var result = topicService.findById(topicId).getTopicSubscribers().stream() | ||
.filter(topicSubscriber -> topicSubscriber.getContact().getEmail().equals(contactEmail)) | ||
.anyMatch(TopicSubscriberResponseDto::isHasComplaint); | ||
|
||
assertThat(result) | ||
.withFailMessage("Expecting containing complaint to topic by user") | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.INSERT) | ||
@DatabaseTearDown( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.DELETE) | ||
@DisplayName( | ||
"should throw TopicNotFoundException when user complain topic") | ||
public void shouldThrowTopicNotFoundException_whenUserComplainTopic() { | ||
// Given | ||
var contactEmail = "[email protected]"; | ||
var contact = contactService.findByEmail(contactEmail); | ||
var topicId = 1; | ||
|
||
// When | ||
// Then | ||
assertThrows( | ||
TopicNotFoundException.class, | ||
() -> topicSubscriberService.complainTopic(topicId, contact)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.INSERT) | ||
@DatabaseTearDown( | ||
value = "/dataset/complain-topic-dataset.xml", | ||
type = DatabaseOperation.DELETE) | ||
@DisplayName( | ||
"should throw NotSubscribedTopicException when user complain topic") | ||
public void shouldThrowNotSubscribedTopicException_whenUserComplainTopic() { | ||
// Given | ||
var contactEmail = "[email protected]"; | ||
var contact = contactService.findByEmail(contactEmail); | ||
var topicId = 111124; | ||
|
||
// When | ||
// Then | ||
assertThrows( | ||
NotSubscribedTopicException.class, | ||
() -> topicSubscriberService.complainTopic(topicId, contact)); | ||
} | ||
} |
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<dataset> | ||
<contact | ||
id="312199" | ||
nickname="Vasil" | ||
password="$2a$10$b9SjqPefZMJRK8WPQEbmP.BBcsqSXey2dCRa0dsRnydFY.GiPjWty" | ||
is_active="true" | ||
is_private="true" | ||
email="[email protected]" | ||
role="USER" | ||
avatar_id="1" | ||
is_permitted_sending_private_message="true" | ||
/> | ||
|
||
<topic | ||
id="111123" | ||
topic_name="Programming topic1" | ||
created_by="[email protected]" | ||
created_at="2023-09-19 23:43:51.236336" | ||
is_public="true" | ||
/> | ||
<topic | ||
id="111124" | ||
topic_name="Another topic1" | ||
created_by="[email protected]" | ||
created_at="2023-10-01 16:31:35.344509" | ||
is_public="true" | ||
/> | ||
|
||
<topic_subscriber | ||
id="90911" | ||
contact_id="312199" | ||
topic_id="111123" | ||
subscribe_at="2023-09-21 22:53:12.818683" | ||
is_favourite_topic="true" | ||
/> | ||
|
||
</dataset> |