feat(pages): admin and public landing page APIs in mobile-api
Admin pages and images scoped by company, counter refusals relayed as code plus field; public page read, image passthrough and form sign-up through the QR registration rules with source WEB; company branding save checks the logo's company; lead detail and export show the web page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
bf6f2c8696
commit
98a77fa17d
17 files changed
+904
-3
No files matched your search
+75
@@ -0,0 +1,75 @@
|
||||
package com.solvway.mobile.api.service;
|
||||
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Company logo and accent colour: the logo must be one of that company's own page images. */
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class AdminCompanyBrandingTest {
|
||||
private static final String BRANDING = "/company/2/branding";
|
||||
private static final String IMAGE_COMPANY = "/counter/pageImage/findCompany/{id}";
|
||||
|
||||
private RestTemplateCustomUtil rest;
|
||||
private AdminCompanyService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
rest = mock(RestTemplateCustomUtil.class);
|
||||
service = new AdminCompanyService(rest);
|
||||
when(rest.getURLforApiService(any())).thenAnswer(i -> i.getArgument(0));
|
||||
when(rest.getForEntity(eq(IMAGE_COMPANY), eq(Long.class), eq(44L))).thenReturn(ResponseEntity.ok(2L));
|
||||
when(rest.postForEntity(eq(BRANDING), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void savesTheOwnLogoAndColour() {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("logoImageId", 44);
|
||||
body.put("accentColor", "#ff6600");
|
||||
service.saveBranding(2L, body);
|
||||
ArgumentCaptor<Object> sent = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(BRANDING), any(ParameterizedTypeReference.class), sent.capture());
|
||||
assertThat((Map<String, Object>) sent.getValue()).containsEntry("logoImageId", 44L).containsEntry("accentColor", "#ff6600");
|
||||
}
|
||||
|
||||
@Test
|
||||
void refusesAnotherCompanysImageAsLogo() {
|
||||
assertThatThrownBy(() -> service.saveBranding(3L, Map.of("logoImageId", 44))).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
assertThat(e.getCode()).isEqualTo("CompanyBadLogo");
|
||||
});
|
||||
verify(rest, never()).postForEntity(any(String.class), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void relaysABadColour() {
|
||||
byte[] problem = "{\"status\":422,\"detail\":\"accentColor|CompanyBadAccent\"}".getBytes(StandardCharsets.UTF_8);
|
||||
when(rest.postForEntity(eq(BRANDING), any(ParameterizedTypeReference.class), any())).thenThrow(
|
||||
HttpClientErrorException.create(HttpStatus.UNPROCESSABLE_ENTITY, "x", HttpHeaders.EMPTY, problem, StandardCharsets.UTF_8));
|
||||
assertThatThrownBy(() -> service.saveBranding(2L, Map.of("accentColor", "red"))).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
assertThat(e.getCode()).isEqualTo("CompanyBadAccent");
|
||||
});
|
||||
}
|
||||
}
|
||||
+9
@@ -171,6 +171,15 @@ class AdminEventLeadExportTest {
|
||||
assertThat(s.getRow(2).getCell(10).getStringCellValue()).isEqualTo("Invite");
|
||||
}
|
||||
|
||||
@Test
|
||||
void webPageSourceIsLabelled() throws Exception {
|
||||
Map<String, Object> web = row(0);
|
||||
web.put("source", "WEB");
|
||||
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
|
||||
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(web), "totalElements", 1)));
|
||||
assertThat(sheet(export()).getRow(1).getCell(10).getStringCellValue()).isEqualTo("Web page");
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullOptionalFieldsAreBlank() throws Exception {
|
||||
Map<String, Object> r = row(0);
|
||||
|
||||
+17
@@ -37,6 +37,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class AdminEventLeadServiceTest {
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> MAP_TYPE = new ParameterizedTypeReference<>() {};
|
||||
|
||||
private static final String EVENTS = "/counter/event/findByPropertyAndPageable";
|
||||
private static final String EVENT = "/counter/event/findByUuid/{uuid}";
|
||||
@@ -548,6 +549,22 @@ class AdminEventLeadServiceTest {
|
||||
assertThat(out).containsEntry("attended", false).containsEntry("source", "STAFF");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getShowsTheWebPageAndUtmTags() {
|
||||
stubStored(EV, 21L, List.of(4L));
|
||||
Map<String, Object> d = (Map<String, Object>) rest.getForEntity(FIND, MAP_TYPE, EL).getBody();
|
||||
d.put("source", "WEB");
|
||||
d.put("pagePath", "/p/INS/hotel-technology");
|
||||
d.put("utmSource", "fb");
|
||||
d.put("utmMedium", "cpc");
|
||||
d.put("utmCampaign", "jan");
|
||||
|
||||
Map<String, Object> out = service.get(String.valueOf(EV), String.valueOf(EL));
|
||||
|
||||
assertThat(out).containsEntry("source", "WEB").containsEntry("pagePath", "/p/INS/hotel-technology")
|
||||
.containsEntry("utmSource", "fb").containsEntry("utmMedium", "cpc").containsEntry("utmCampaign", "jan");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getShowsSalespersonAndInterestsByName() {
|
||||
stubStored(EV, 21L, List.of(4L));
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
package com.solvway.mobile.api.service;
|
||||
|
||||
import com.solvway.core.model.Role;
|
||||
import com.solvway.core.model.User;
|
||||
import com.solvway.core.utils.HttpReqRespUtils;
|
||||
import com.solvway.mobile.api.dto.admin.AdminPageRequest;
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Admin landing pages: company scoping and the counter's "path|Code" refusals relayed as code plus field. */
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class AdminPageServiceTest {
|
||||
private static final String SAVE = "/counter/cmsPage/save";
|
||||
private static final String BY_ID = "/counter/cmsPage/findById/{id}";
|
||||
private static final String SEARCH = "/counter/cmsPage/search";
|
||||
private static final String DELETE = "/counter/cmsPage/delete";
|
||||
private static final String UPLOAD = "/counter/pageImage/upload";
|
||||
|
||||
private RestTemplateCustomUtil rest;
|
||||
private AdminAuthenticationService auth;
|
||||
private AdminPageService service;
|
||||
private MockedStatic<HttpReqRespUtils> http;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
rest = mock(RestTemplateCustomUtil.class);
|
||||
auth = mock(AdminAuthenticationService.class);
|
||||
service = new AdminPageService(rest, auth, new AdminCompanyScope());
|
||||
when(rest.getURLforApiService(any())).thenAnswer(i -> i.getArgument(0));
|
||||
http = mockStatic(HttpReqRespUtils.class);
|
||||
http.when(HttpReqRespUtils::getJwtToken).thenReturn("tok");
|
||||
when(rest.postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any()))
|
||||
.thenAnswer(i -> ResponseEntity.ok(((Map<String, Object>) i.getArgument(2)).get("page")));
|
||||
when(rest.getForEntity(eq(BY_ID), any(ParameterizedTypeReference.class), eq(5L)))
|
||||
.thenReturn(ResponseEntity.ok(new HashMap<>(Map.of("id", 5, "companyId", 2, "slug", "a", "title", "A", "status", "DRAFT", "blocks", List.of()))));
|
||||
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
|
||||
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(), "totalElements", 0, "totalPages", 0, "number", 0, "size", 20)));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void close() { http.close(); }
|
||||
|
||||
private void caller(Long companyId, boolean superAdmin) {
|
||||
User u = new User();
|
||||
u.setUsername("boss");
|
||||
u.setCompanyId(companyId);
|
||||
if (superAdmin) {
|
||||
Role r = new Role("Super");
|
||||
r.setId(1L);
|
||||
u.setRoles(List.of(r));
|
||||
}
|
||||
when(auth.loadUserByToken("tok")).thenReturn(u);
|
||||
}
|
||||
|
||||
private static AdminPageRequest request(Long companyId) {
|
||||
return new AdminPageRequest(companyId, "hotel", "Hotel", null, "DRAFT", List.of(Map.of("type", "RICH_TEXT", "html", "<p>x</p>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void staffListSeesOnlyTheirCompanyWhateverTheyAskFor() {
|
||||
caller(3L, false);
|
||||
service.list("ho", 0, 20, 2L);
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), body.capture());
|
||||
assertThat((Map<String, Object>) body.getValue()).containsEntry("companyId", 3L).containsEntry("searchKey", "ho");
|
||||
}
|
||||
|
||||
@Test
|
||||
void staffCannotReadOrChangeAnotherCompanysPage() {
|
||||
caller(3L, false);
|
||||
for (Runnable r : List.<Runnable>of(() -> service.get(5L), () -> service.update(5L, request(null)), () -> service.delete(5L))) {
|
||||
assertThatThrownBy(r::run).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND");
|
||||
});
|
||||
}
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
verify(rest, never()).postForEntity(eq(DELETE), any(Class.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUsesTheStaffCompanyAndTheCallerAsUser() {
|
||||
caller(2L, false);
|
||||
service.create(request(9L));
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), body.capture());
|
||||
Map<String, Object> sent = (Map<String, Object>) body.getValue();
|
||||
assertThat(sent).containsEntry("user", "boss");
|
||||
assertThat((Map<String, Object>) sent.get("page")).containsEntry("companyId", 2L).containsEntry("slug", "hotel").containsEntry("id", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeepsTheIdAndStoredCompany() {
|
||||
caller(2L, false);
|
||||
service.update(5L, request(9L));
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), body.capture());
|
||||
assertThat((Map<String, Object>) ((Map<String, Object>) body.getValue()).get("page")).containsEntry("id", 5L).containsEntry("companyId", 2L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void counterRefusalBecomesCodeAndField() {
|
||||
caller(2L, false);
|
||||
byte[] problem = "{\"status\":422,\"detail\":\"blocks[2].heading|PagesRequired\"}".getBytes(StandardCharsets.UTF_8);
|
||||
when(rest.postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any())).thenThrow(
|
||||
HttpClientErrorException.create(HttpStatus.UNPROCESSABLE_ENTITY, "x", HttpHeaders.EMPTY, problem, StandardCharsets.UTF_8));
|
||||
assertThatThrownBy(() -> service.create(request(null))).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
assertThat(e.getCode()).isEqualTo("PagesRequired");
|
||||
assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("field", "blocks[2].heading"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageUploadIsScopedToTheCallersCompany() {
|
||||
caller(2L, false);
|
||||
when(rest.postForEntity(eq(UPLOAD), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 44)));
|
||||
assertThat(service.uploadImage(7L, "aGk=")).containsEntry("id", 44);
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(UPLOAD), any(ParameterizedTypeReference.class), body.capture());
|
||||
assertThat((Map<String, Object>) body.getValue()).containsEntry("companyId", 2L).containsEntry("data", "aGk=").containsEntry("user", "boss");
|
||||
}
|
||||
|
||||
@Test
|
||||
void superAdminMustPickACompanyToCreate() {
|
||||
caller(null, true);
|
||||
assertThatThrownBy(() -> service.create(request(null))).isInstanceOf(CodedResponseStatusException.class);
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
package com.solvway.mobile.api.service;
|
||||
|
||||
import com.solvway.core.enums.GeneralEnum;
|
||||
import com.solvway.core.utils.HttpReqRespUtils;
|
||||
import com.solvway.mobile.api.dto.PublicPageFormRequest;
|
||||
import com.solvway.mobile.api.dto.admin.CompanyEvent;
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
|
||||
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Spec landing-pages: the public page, its form block's event and the web sign-up, under the QR registration rules. */
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class PublicPageServiceTest {
|
||||
private static final String BRANDING = "/company/branding/{code}";
|
||||
private static final String PUBLISHED = "/counter/cmsPage/findPublished/{companyId}/{slug}";
|
||||
private static final String EVENT = "/counter/event/findByUuid/{uuid}";
|
||||
private static final String COMPANY_URL = "/company/findById/{id}";
|
||||
private static final String NOTICE = "/company/{id}/privacyNotice";
|
||||
private static final String INTERESTS = "/counter/interest/findByCompany/{companyId}";
|
||||
private static final String REGISTER = "/counter/registration/register";
|
||||
private static final long EV = 3312726793093644288L;
|
||||
private static final long COMPANY = 1L;
|
||||
|
||||
private RestTemplateCustomUtil rest;
|
||||
private MockedStatic<HttpReqRespUtils> http;
|
||||
private PublicPageService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
rest = mock(RestTemplateCustomUtil.class);
|
||||
RedisTemplate<String, Object> redis = mock(RedisTemplate.class);
|
||||
ValueOperations<String, Object> ops = mock(ValueOperations.class);
|
||||
when(redis.opsForValue()).thenReturn(ops);
|
||||
when(ops.increment(any())).thenReturn(1L);
|
||||
when(rest.getURLforApiService(any())).thenAnswer(i -> i.getArgument(0));
|
||||
http = mockStatic(HttpReqRespUtils.class);
|
||||
http.when(HttpReqRespUtils::getClientIpAddressIfServletRequestExist).thenReturn("1.2.3.4");
|
||||
AdminEventLeadService leads = new AdminEventLeadService(rest, mock(AdminAuthenticationService.class), new AdminCompanyScope());
|
||||
PublicRegistrationService registration = new PublicRegistrationService(rest, leads, redis,
|
||||
Clock.fixed(Instant.parse("2027-01-16T04:00:00Z"), ZoneOffset.UTC));
|
||||
service = new PublicPageService(rest, registration);
|
||||
|
||||
Map<String, Object> brand = new HashMap<>(Map.of("id", COMPANY, "code", "INS", "name", "INS", "accentColor", "#0B5FFF"));
|
||||
brand.put("logoImageId", 4L);
|
||||
stub(BRANDING, "INS", brand);
|
||||
when(rest.getForEntity(eq(PUBLISHED), any(ParameterizedTypeReference.class), eq(COMPANY), eq("hotel-technology")))
|
||||
.thenReturn(ResponseEntity.ok(page()));
|
||||
stubEvent(LocalDateTime.of(2027, 12, 31, 23, 59));
|
||||
stub(COMPANY_URL, COMPANY, Map.of("id", COMPANY, "name", "INS", "status", "A"));
|
||||
stub(NOTICE, COMPANY, Map.of("id", 9L, "textEn", "English notice", "textMs", "Notis"));
|
||||
stub(INTERESTS, COMPANY, List.of(Map.of("id", 3L, "companyId", COMPANY, "name", "Smart rooms", "active", true, "sortOrder", 0)));
|
||||
when(rest.postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of()));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void close() {
|
||||
http.close();
|
||||
}
|
||||
|
||||
private static Map<String, Object> page() {
|
||||
Map<String, Object> form = new HashMap<>(Map.of("type", "FORM", "heading", "Talk to us", "eventUuid", EV));
|
||||
return new HashMap<>(Map.of("id", 12L, "companyId", COMPANY, "slug", "hotel-technology", "title", "Hotel technology",
|
||||
"status", "PUBLISHED", "blocks", List.of(Map.of("type", "RICH_TEXT", "html", "<p>Hi</p>"), form)));
|
||||
}
|
||||
|
||||
private void stub(String url, Object var, Object body) {
|
||||
when(rest.getForEntity(eq(url), any(ParameterizedTypeReference.class), eq(var))).thenReturn(ResponseEntity.ok(body));
|
||||
}
|
||||
|
||||
private void stubEvent(LocalDateTime end) {
|
||||
CompanyEvent e = new CompanyEvent();
|
||||
e.setCompanyId(COMPANY);
|
||||
e.setUuid(EV);
|
||||
e.setName("INS website enquiries");
|
||||
e.setDateStart(LocalDateTime.of(2027, 1, 1, 0, 0));
|
||||
e.setDateEnd(end);
|
||||
e.setEnabled(GeneralEnum.FlagYesNo.Y);
|
||||
stub(EVENT, EV, e);
|
||||
}
|
||||
|
||||
private static PublicPageFormRequest visitor(String website) {
|
||||
return new PublicPageFormRequest("Tan", "0125550101", null, null, null, List.of(3L), true, website, "facebook", "cpc", "jan-launch");
|
||||
}
|
||||
|
||||
@Test
|
||||
void thePageCarriesBrandingAndItsOpenFormsEvent() {
|
||||
Map<String, Object> out = service.page("ins", "Hotel-Technology");
|
||||
|
||||
assertThat((Map<String, Object>) out.get("company")).containsEntry("code", "INS").containsEntry("logoImageId", 4L).containsEntry("accentColor", "#0B5FFF");
|
||||
List<Map<String, Object>> blocks = (List<Map<String, Object>>) ((Map<String, Object>) out.get("page")).get("blocks");
|
||||
assertThat(blocks).hasSize(2);
|
||||
Map<String, Object> form = (Map<String, Object>) blocks.get(1).get("form");
|
||||
assertThat(form).containsEntry("eventName", "INS website enquiries").containsKey("notice").containsKey("interests");
|
||||
assertThat(blocks.get(1)).doesNotContainKey("closed");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFormWhoseEventEndedIsClosedButThePageStillShows() {
|
||||
stubEvent(LocalDateTime.of(2027, 1, 15, 23, 59));
|
||||
List<Map<String, Object>> blocks = (List<Map<String, Object>>) ((Map<String, Object>) service.page("INS", "hotel-technology").get("page")).get("blocks");
|
||||
assertThat(blocks.get(0)).containsEntry("type", "RICH_TEXT");
|
||||
assertThat(blocks.get(1)).containsEntry("closed", true).doesNotContainKey("form");
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownCompanySlugOrShapeAllLookTheSame() {
|
||||
when(rest.getForEntity(eq(BRANDING), any(ParameterizedTypeReference.class), eq("XX"))).thenThrow(HttpClientErrorException.NotFound.class);
|
||||
when(rest.getForEntity(eq(PUBLISHED), any(ParameterizedTypeReference.class), eq(COMPANY), eq("launch"))).thenThrow(HttpClientErrorException.NotFound.class);
|
||||
for (String[] c : new String[][]{{"XX", "hotel-technology"}, {"INS", "launch"}, {"INS", "../etc"}, {"I N S", "x"}}) {
|
||||
assertThatThrownBy(() -> service.page(c[0], c[1])).as(c[0] + "/" + c[1])
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSubmitRegistersAWebSignUpWithThePageAndUtmTags() {
|
||||
service.submit("ins", "hotel-technology", 1, visitor(null));
|
||||
|
||||
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||
verify(rest).postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), body.capture());
|
||||
Map<String, Object> sent = (Map<String, Object>) body.getValue();
|
||||
assertThat(sent).containsEntry("eventUuid", EV).containsEntry("companyId", COMPANY).containsEntry("source", "WEB")
|
||||
.containsEntry("pagePath", "/p/INS/hotel-technology").containsEntry("utmSource", "facebook")
|
||||
.containsEntry("utmMedium", "cpc").containsEntry("utmCampaign", "jan-launch").containsEntry("mobileE164", "+60125550101")
|
||||
.containsEntry("consentNoticeId", 9L);
|
||||
assertThat(sent.get("salespersonUserId")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSubmitToAClosedFormOrANonFormBlockIsRefused() {
|
||||
assertThatThrownBy(() -> service.submit("INS", "hotel-technology", 0, visitor(null)))
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND"));
|
||||
assertThatThrownBy(() -> service.submit("INS", "hotel-technology", 7, visitor(null)))
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND"));
|
||||
stubEvent(LocalDateTime.of(2027, 1, 15, 23, 59));
|
||||
assertThatThrownBy(() -> service.submit("INS", "hotel-technology", 1, visitor(null)))
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("FORM_CLOSED"));
|
||||
verify(rest, never()).postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theHoneypotLooksLikeSuccessAndStoresNothing() {
|
||||
assertThat(service.submit("INS", "hotel-technology", 1, visitor("http://spam"))).containsKey("eventName");
|
||||
verify(rest, never()).postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), any());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user