generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature to add chat link to user (#1566)
- Loading branch information
1 parent
0093b1b
commit 98ee056
Showing
15 changed files
with
232 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ jobs: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
git fetch --unshallow | ||
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=ita-social-projects-green-ubs -Dsonar.organization=ita-social-projects -Dsonar.host.url=https://sonarcloud.io -Dsonar.binaries=target/classes -Dsonar.dynamicAnalysis=reuseReports -Dsonar.exclusions=**/EncryptionUtil.java -Dsonar.coverage.exclusions=**/configuration/*,**/entity/*,**/exceptions/*,**/exceptions/**,**/enums/NotificationType.java,**/BigOrderTableRepository.java | ||
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=ita-social-projects-green-ubs -Dsonar.organization=ita-social-projects -Dsonar.host.url=https://sonarcloud.io -Dsonar.binaries=target/classes -Dsonar.dynamicAnalysis=reuseReports -Dsonar.exclusions=**/EncryptionUtil.java -Dsonar.coverage.exclusions=**/configuration/*,**/entity/*,**/exceptions/*,**/exceptions/**,**/enums/NotificationType.java,**/BigOrderTableRepository.java,**/ChatLinkDto.java | ||
- name: Test Reporter | ||
uses: dorny/[email protected] | ||
|
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
14 changes: 14 additions & 0 deletions
14
dao/src/main/resources/db/changelog/logs/2024-12-18-add-new-column-to-user-table-Kizerov.xml
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<changeSet id="add-new-column-to-user" author="Kizerov Dmytro"> | ||
<addColumn tableName="users"> | ||
<column name="chat_link" type="VARCHAR(500)"> | ||
<constraints nullable="true"/> | ||
</column> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
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
12 changes: 12 additions & 0 deletions
12
service-api/src/main/java/greencity/dto/user/ChatLinkDto.java
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,12 @@ | ||
package greencity.dto.user; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import org.hibernate.validator.constraints.Length; | ||
|
||
public record ChatLinkDto( | ||
Long userId, | ||
@JsonProperty("link") @Length(max = 255) @NotBlank @Pattern(regexp = "^https://my\\.binotel\\.ua.*", | ||
message = "Link must start with 'https://my.binotel.ua'") String link) { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5675,4 +5675,31 @@ public static RequestToChangeOrdersDataDto getChangeRequest(String columnName) { | |
.newValue("Test comment") | ||
.build(); | ||
} | ||
|
||
public static User createTestUser(Long id, String firstName, String lastName, String email, String phone) { | ||
User user = new User(); | ||
user.setId(id); | ||
user.setRecipientName(firstName); | ||
user.setRecipientSurname(lastName); | ||
user.setRecipientEmail(email); | ||
user.setRecipientPhone(phone); | ||
user.setDateOfRegistration(LocalDate.now()); | ||
user.setOrders(List.of(createTestOrder())); | ||
user.setCurrentPoints(100); | ||
user.setViolations(1); | ||
return user; | ||
} | ||
|
||
public static Order createTestOrder() { | ||
Order order = new Order(); | ||
order.setOrderDate(LocalDateTime.now().minusDays(1)); | ||
return order; | ||
} | ||
|
||
public static Employee createTestEmployee(Long id) { | ||
Employee employee = new Employee(); | ||
employee.setId(id); | ||
employee.setEmail("[email protected]"); | ||
return employee; | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
service/src/test/java/greencity/service/ubs/ValuesForUserTableServiceImplTest.java
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,105 @@ | ||
package greencity.service.ubs; | ||
|
||
import greencity.ModelUtils; | ||
import greencity.dto.order.UserWithSomeOrderDetailDto; | ||
import greencity.dto.pageble.PageableDto; | ||
import greencity.entity.user.User; | ||
import greencity.enums.SortingOrder; | ||
import greencity.filters.CustomerPage; | ||
import greencity.filters.UserFilterCriteria; | ||
import greencity.repository.EmployeeRepository; | ||
import greencity.repository.UserRepository; | ||
import greencity.repository.UserTableRepo; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ValuesForUserTableServiceImplTest { | ||
@Mock | ||
private UserRepository userRepository; | ||
|
||
@Mock | ||
private UserTableRepo userTableRepo; | ||
|
||
@Mock | ||
private EmployeeRepository employeeRepository; | ||
|
||
@InjectMocks | ||
private ValuesForUserTableServiceImpl service; | ||
|
||
private static final String TEST_EMAIL = "[email protected]"; | ||
|
||
@Test | ||
void getAllFieldsShouldReturnPageableDtoWhenDataIsValidTest() { | ||
Long employeeId = 1L; | ||
List<Long> tariffsInfoIds = List.of(2L, 3L); | ||
List<Long> userIds = List.of(4L, 5L, 4L, 5L); | ||
User user1 = ModelUtils.createTestUser(4L, "John", "Doe", "[email protected]", "+380123456789"); | ||
User user2 = ModelUtils.createTestUser(5L, "Jane", "Smith", "[email protected]", "+380987654321"); | ||
Page<User> mockPage = new PageImpl<>(List.of(user1, user2), PageRequest.of(0, 2), 2); | ||
|
||
CustomerPage page = new CustomerPage(0, 2); | ||
String columnName = "name"; | ||
SortingOrder sortingOrder = SortingOrder.ASC; | ||
UserFilterCriteria filterCriteria = new UserFilterCriteria(); | ||
|
||
Mockito.when(employeeRepository.findByEmail(TEST_EMAIL)) | ||
.thenReturn(Optional.of(ModelUtils.createTestEmployee(employeeId))); | ||
Mockito.when(employeeRepository.findTariffsInfoForEmployee(employeeId)) | ||
.thenReturn(tariffsInfoIds); | ||
Mockito.when(userRepository.getAllUsersByTariffsInfoId(Mockito.anyLong())) | ||
.thenReturn(List.of(4L, 5L)); | ||
Mockito.when(userTableRepo.findAll( | ||
Mockito.eq(filterCriteria), | ||
Mockito.eq(columnName), | ||
Mockito.eq(sortingOrder), | ||
Mockito.eq(page), | ||
Mockito.anyList())) | ||
.thenReturn(mockPage); | ||
|
||
PageableDto<UserWithSomeOrderDetailDto> result = | ||
service.getAllFields(page, columnName, sortingOrder, filterCriteria, TEST_EMAIL); | ||
|
||
assertThat(result).isNotNull(); | ||
assertThat(result.getPage()).hasSize(2); | ||
assertThat(result.getPage()) | ||
.extracting("clientName") | ||
.containsExactly("John Doe", "Jane Smith"); | ||
Mockito.verify(employeeRepository).findByEmail(TEST_EMAIL); | ||
Mockito.verify(employeeRepository).findTariffsInfoForEmployee(employeeId); | ||
Mockito.verify(userRepository, Mockito.times(tariffsInfoIds.size())) | ||
.getAllUsersByTariffsInfoId(Mockito.anyLong()); | ||
Mockito.verify(userTableRepo).findAll(filterCriteria, columnName, sortingOrder, page, userIds); | ||
} | ||
|
||
@Test | ||
void getAllFieldsShouldThrowExceptionWhenEmployeeNotFoundTest() { | ||
Mockito.when(employeeRepository.findByEmail(TEST_EMAIL)) | ||
.thenReturn(Optional.empty()); | ||
|
||
CustomerPage page = new CustomerPage(0, 2); | ||
String columnName = "name"; | ||
SortingOrder sortingOrder = SortingOrder.ASC; | ||
UserFilterCriteria filterCriteria = new UserFilterCriteria(); | ||
|
||
assertThatThrownBy(() -> service.getAllFields(page, columnName, sortingOrder, filterCriteria, TEST_EMAIL)) | ||
.isInstanceOf(EntityNotFoundException.class) | ||
.hasMessage("Employee with current id doesn't exist: "); | ||
|
||
Mockito.verify(employeeRepository).findByEmail(TEST_EMAIL); | ||
Mockito.verifyNoInteractions(userRepository, userTableRepo); | ||
} | ||
} |