package com.talentcard.server.business.portal;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.Mockito.when;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.mockito.InjectMocks;
|
import org.mockito.Mock;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
@ExtendWith(MockitoExtension.class)
|
class ShoppingMerchantPortalServiceTests {
|
@Mock
|
private JdbcTemplate jdbc;
|
|
@Mock
|
private PortalService portalService;
|
|
@Mock
|
private TalentCardPortalService talentCardPortalService;
|
|
@InjectMocks
|
private ShoppingMerchantPortalService service;
|
|
@Test
|
void usesCardLevelRightTagAndDetailConfiguredForTalent() {
|
Long merchantId = 102L;
|
Long talentId = 1015L;
|
when(jdbc.queryForList(anyString(), eq(merchantId))).thenReturn(List.of(Map.ofEntries(
|
Map.entry("id", merchantId),
|
Map.entry("merchant_name", "喜望数码服务"),
|
Map.entry("merchant_status", 1),
|
Map.entry("category_key", "digital"),
|
Map.entry("service_label", ""),
|
Map.entry("talent_levels", "请咨询服务专员"),
|
Map.entry("address", "成都市天府新谷"),
|
Map.entry("contact_mobile", "13540211247"),
|
Map.entry("rights_text", "旧权益说明"))));
|
when(portalService.merchantDetail(merchantId, talentId)).thenReturn(Map.of(
|
"rightsStatus", "AVAILABLE",
|
"rightsTag", "后台配置的购车权益标签",
|
"applicableCards", "后台配置的购车权益标签",
|
"rightsText", "后台配置的数码服务权益详情"));
|
when(talentCardPortalService.profile(talentId)).thenReturn(Map.of(
|
"advisor", Map.of(
|
"name", "账号服务专员",
|
"mobile", "13911112222")));
|
|
Map<String, Object> detail = service.detail(merchantId, talentId);
|
|
assertThat(detail)
|
.containsEntry("applicableCards", "后台配置的购车权益标签")
|
.containsEntry("benefitDetail", "后台配置的数码服务权益详情")
|
.containsEntry("discountText", "")
|
.containsEntry("address", "成都市天府新谷")
|
.containsEntry("available", true);
|
assertThat(detail.get("advisor")).isInstanceOfSatisfying(Map.class, advisor -> assertThat(advisor)
|
.containsEntry("name", "账号服务专员")
|
.containsEntry("mobile", "13911112222")
|
.containsEntry("available", true)
|
.doesNotContainValue("13540211247"));
|
}
|
|
@Test
|
void doesNotFallbackToMerchantPhoneWhenTalentHasNoAdvisor() {
|
Long merchantId = 102L;
|
Long talentId = 1015L;
|
when(jdbc.queryForList(anyString(), eq(merchantId))).thenReturn(List.of(Map.ofEntries(
|
Map.entry("id", merchantId),
|
Map.entry("merchant_name", "购房优惠商家"),
|
Map.entry("merchant_status", 1),
|
Map.entry("category_key", "housing"),
|
Map.entry("contact_mobile", "13540211247"))));
|
when(portalService.merchantDetail(merchantId, talentId)).thenReturn(Map.of(
|
"rightsStatus", "AVAILABLE"));
|
when(talentCardPortalService.profile(talentId)).thenReturn(Map.of());
|
|
Map<String, Object> detail = service.detail(merchantId, talentId);
|
|
assertThat(detail.get("advisor")).isEqualTo(Map.of("available", false));
|
}
|
}
|