Skip to content

Commit 0e0a3c6

Browse files
committed
test: calculate LTFT short notice by submission date in PDF
1 parent 655b257 commit 0e0a3c6

File tree

4 files changed

+177
-16
lines changed

4 files changed

+177
-16
lines changed

src/integrationTest/java/uk/nhs/hee/tis/trainee/forms/api/LtftResourceIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,11 @@ void shouldGetDetailPdfDeclarationDetails() throws Exception {
18511851

18521852
assertThat("Unexpected section header.", pdfText,
18531853
containsString("Declarations" + System.lineSeparator()));
1854-
assertThat("Unexpected declaration.", pdfText.replaceAll("[\r\n]+", ""),
1854+
assertThat("Unexpected declaration.", removeLineBreak(pdfText),
18551855
containsString(
1856-
"I confirm that the information I have provided is correct and accurate to the best of my knowledge.true"));
1857-
assertThat("Unexpected declaration.", pdfText.replaceAll("[\r\n]+", ""),
1858-
containsString("I understand that approval of my application is not guaranteed.true"));
1856+
"I confirm that the information I have provided is correct and accurate to the best of my knowledge. true"));
1857+
assertThat("Unexpected declaration.", removeLineBreak(pdfText),
1858+
containsString("I understand that approval of my application is not guaranteed. true"));
18591859
}
18601860

18611861
private String removeLineBreak(String text) {

src/main/java/uk/nhs/hee/tis/trainee/forms/mapper/LtftMapper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Boolean isShortNoticeAdmin(LtftForm entity) {
254254
@Named("IsShortNoticeTrainee")
255255
@Nullable
256256
Boolean isShortNoticeTrainee(LtftForm entity) {
257-
if (entity.getStatus() == null) {
257+
if (entity.getStatus() == null || entity.getStatus().current() == null) {
258258
return null;
259259
}
260260

@@ -292,9 +292,6 @@ public EmailValidityType toEmailValidity(@Nullable String emailStatus) {
292292
* @return Whether the application is short notice.
293293
*/
294294
private Boolean isShortNotice(LtftForm entity, Instant referenceInstant) {
295-
if (referenceInstant == null) {
296-
return false;
297-
}
298295
LocalDate referenceDate = getTemporalMapper().toLocalDate(referenceInstant);
299296

300297
return Optional.ofNullable(entity.getContent())

src/test/java/uk/nhs/hee/tis/trainee/forms/mapper/LtftMapperTest.java

Lines changed: 167 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.hamcrest.MatcherAssert.assertThat;
2525
import static org.hamcrest.Matchers.is;
2626
import static org.hamcrest.Matchers.nullValue;
27+
import static org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE;
2728
import static uk.nhs.hee.tis.trainee.forms.dto.enumeration.EmailValidityType.INVALID;
2829

2930
import java.time.Duration;
@@ -34,6 +35,7 @@
3435
import org.junit.jupiter.api.BeforeEach;
3536
import org.junit.jupiter.api.Test;
3637
import org.junit.jupiter.params.ParameterizedTest;
38+
import org.junit.jupiter.params.provider.EnumSource;
3739
import org.junit.jupiter.params.provider.ValueSource;
3840
import uk.nhs.hee.tis.trainee.forms.dto.enumeration.EmailValidityType;
3941
import uk.nhs.hee.tis.trainee.forms.dto.enumeration.LifecycleState;
@@ -87,7 +89,7 @@ void shouldReturnSortedJoinedStringWhenListHasMultipleStrings() {
8789
}
8890

8991
@Test
90-
void shouldReturnNullShortNoticeWhenStatusNull() {
92+
void shouldReturnNullShortNoticeAdminWhenStatusNull() {
9193
LtftForm entity = new LtftForm();
9294
entity.setStatus(null);
9395

@@ -97,7 +99,7 @@ void shouldReturnNullShortNoticeWhenStatusNull() {
9799
}
98100

99101
@Test
100-
void shouldReturnNullShortNoticeWhenSubmittedNull() {
102+
void shouldReturnNullShortNoticeAdminWhenSubmittedNull() {
101103
LtftForm entity = new LtftForm();
102104
entity.setStatus(Status.builder()
103105
.submitted(null)
@@ -109,7 +111,7 @@ void shouldReturnNullShortNoticeWhenSubmittedNull() {
109111
}
110112

111113
@Test
112-
void shouldReturnNullShortNoticeWhenContentNull() {
114+
void shouldReturnNullShortNoticeAdminWhenContentNull() {
113115
LtftForm entity = new LtftForm();
114116
entity.setStatus(Status.builder()
115117
.current(StatusInfo.builder().build())
@@ -124,7 +126,7 @@ void shouldReturnNullShortNoticeWhenContentNull() {
124126
}
125127

126128
@Test
127-
void shouldReturnNullShortNoticeWhenChangeNull() {
129+
void shouldReturnNullShortNoticeAdminWhenChangeNull() {
128130
LtftForm entity = new LtftForm();
129131
entity.setStatus(Status.builder()
130132
.current(StatusInfo.builder().build())
@@ -141,7 +143,7 @@ void shouldReturnNullShortNoticeWhenChangeNull() {
141143
}
142144

143145
@Test
144-
void shouldReturnNullShortNoticeWhenStartDateNull() {
146+
void shouldReturnNullShortNoticeAdminWhenStartDateNull() {
145147
LtftForm entity = new LtftForm();
146148
entity.setStatus(Status.builder()
147149
.current(StatusInfo.builder().build())
@@ -161,7 +163,7 @@ void shouldReturnNullShortNoticeWhenStartDateNull() {
161163

162164
@ParameterizedTest
163165
@ValueSource(ints = {0, 111})
164-
void shouldReturnTrueShortNoticeWhenSubmissionWithinNoticePeriod(int days) {
166+
void shouldReturnTrueShortNoticeAdminWhenSubmissionWithinNoticePeriod(int days) {
165167
LtftForm entity = new LtftForm();
166168
entity.setStatus(Status.builder()
167169
.current(StatusInfo.builder().build())
@@ -181,7 +183,7 @@ void shouldReturnTrueShortNoticeWhenSubmissionWithinNoticePeriod(int days) {
181183

182184
@ParameterizedTest
183185
@ValueSource(ints = {112, 113})
184-
void shouldReturnFalseShortNoticeWhenSubmissionOutsideOrEqualToNoticePeriod(int days) {
186+
void shouldReturnFalseShortNoticeAdminWhenSubmissionOutsideOrEqualToNoticePeriod(int days) {
185187
LtftForm entity = new LtftForm();
186188
entity.setStatus(Status.builder()
187189
.current(StatusInfo.builder().build())
@@ -201,7 +203,7 @@ void shouldReturnFalseShortNoticeWhenSubmissionOutsideOrEqualToNoticePeriod(int
201203

202204
@ParameterizedTest
203205
@ValueSource(ints = {0, 111})
204-
void shouldReturnUseCurrentDateForShortNoticeWhenCurrentStatusUnsubmitted(int days) {
206+
void shouldReturnUseCurrentDateForShortNoticeAdminWhenCurrentStatusUnsubmitted(int days) {
205207
LtftForm entity = new LtftForm();
206208
entity.setStatus(Status.builder()
207209
.current(StatusInfo.builder()
@@ -255,4 +257,161 @@ void shouldReturnEmailInvalidWhenStatusNotMapped() {
255257

256258
assertThat("Unexpected email validity.", emailValidity, is(INVALID));
257259
}
260+
261+
@Test
262+
void shouldReturnNullShortNoticeTraineeWhenStatusNull() {
263+
LtftForm entity = new LtftForm();
264+
entity.setStatus(null);
265+
266+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
267+
268+
assertThat("Unexpected short notice value.", isShortNotice, nullValue());
269+
}
270+
271+
@Test
272+
void shouldReturnNullShortNoticeTraineeWhenCurrentNull() {
273+
LtftForm entity = new LtftForm();
274+
entity.setStatus(Status.builder()
275+
.current(null)
276+
.build());
277+
278+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
279+
280+
assertThat("Unexpected short notice value.", isShortNotice, nullValue());
281+
}
282+
283+
@Test
284+
void shouldReturnNullShortNoticeTraineeWhenContentNull() {
285+
LtftForm entity = new LtftForm();
286+
entity.setStatus(Status.builder()
287+
.current(StatusInfo.builder().build())
288+
.submitted(Instant.now())
289+
.build());
290+
291+
entity.setContent(null);
292+
293+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
294+
295+
assertThat("Unexpected short notice value.", isShortNotice, nullValue());
296+
}
297+
298+
@Test
299+
void shouldReturnNullShortNoticeTraineeWhenChangeNull() {
300+
LtftForm entity = new LtftForm();
301+
entity.setStatus(Status.builder()
302+
.current(StatusInfo.builder().build())
303+
.submitted(Instant.now())
304+
.build());
305+
306+
entity.setContent(LtftContent.builder()
307+
.change(null)
308+
.build());
309+
310+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
311+
312+
assertThat("Unexpected short notice value.", isShortNotice, nullValue());
313+
}
314+
315+
@Test
316+
void shouldReturnNullShortNoticeTraineeWhenStartDateNull() {
317+
LtftForm entity = new LtftForm();
318+
entity.setStatus(Status.builder()
319+
.current(StatusInfo.builder().build())
320+
.submitted(Instant.now())
321+
.build());
322+
323+
entity.setContent(LtftContent.builder()
324+
.change(CctChange.builder()
325+
.startDate(null)
326+
.build())
327+
.build());
328+
329+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
330+
331+
assertThat("Unexpected short notice value.", isShortNotice, nullValue());
332+
}
333+
334+
@ParameterizedTest
335+
@ValueSource(ints = {0, 111})
336+
void shouldReturnTrueShortNoticeTraineeWhenSubmissionWithinNoticePeriod(int days) {
337+
LtftForm entity = new LtftForm();
338+
entity.setStatus(Status.builder()
339+
.current(StatusInfo.builder().build())
340+
.submitted(Instant.now())
341+
.build());
342+
343+
entity.setContent(LtftContent.builder()
344+
.change(CctChange.builder()
345+
.startDate(LocalDate.now().plusDays(days))
346+
.build())
347+
.build());
348+
349+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
350+
351+
assertThat("Unexpected short notice value.", isShortNotice, is(true));
352+
}
353+
354+
@ParameterizedTest
355+
@ValueSource(ints = {112, 113})
356+
void shouldReturnFalseShortNoticeTraineeWhenSubmissionOutsideOrEqualToNoticePeriod(int days) {
357+
LtftForm entity = new LtftForm();
358+
entity.setStatus(Status.builder()
359+
.current(StatusInfo.builder().build())
360+
.submitted(Instant.now())
361+
.build());
362+
363+
entity.setContent(LtftContent.builder()
364+
.change(CctChange.builder()
365+
.startDate(LocalDate.now().plusDays(days))
366+
.build())
367+
.build());
368+
369+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
370+
371+
assertThat("Unexpected short notice value.", isShortNotice, is(false));
372+
}
373+
374+
@ParameterizedTest
375+
@EnumSource(value = LifecycleState.class, names = {"DRAFT", "UNSUBMITTED"})
376+
void shouldReturnUseCurrentDateForShortNoticeTraineeWhenDraftUnsubmitted(LifecycleState state) {
377+
LtftForm entity = new LtftForm();
378+
entity.setStatus(Status.builder()
379+
.current(StatusInfo.builder()
380+
.state(state)
381+
.build())
382+
.submitted(Instant.now().minus(Duration.ofDays(120)))
383+
.build());
384+
385+
entity.setContent(LtftContent.builder()
386+
.change(CctChange.builder()
387+
.startDate(LocalDate.now().plusDays(100))
388+
.build())
389+
.build());
390+
391+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
392+
393+
assertThat("Unexpected short notice value.", isShortNotice, is(true));
394+
}
395+
396+
@ParameterizedTest
397+
@EnumSource(value = LifecycleState.class, mode = EXCLUDE, names = {"DRAFT", "UNSUBMITTED"})
398+
void shouldReturnUseSubmissionDateForShortNoticeTraineeWhenSubmitted(LifecycleState state) {
399+
LtftForm entity = new LtftForm();
400+
entity.setStatus(Status.builder()
401+
.current(StatusInfo.builder()
402+
.state(state)
403+
.build())
404+
.submitted(Instant.now().minus(Duration.ofDays(120)))
405+
.build());
406+
407+
entity.setContent(LtftContent.builder()
408+
.change(CctChange.builder()
409+
.startDate(LocalDate.now().plusDays(100))
410+
.build())
411+
.build());
412+
413+
Boolean isShortNotice = mapper.isShortNoticeTrainee(entity);
414+
415+
assertThat("Unexpected short notice value.", isShortNotice, is(false));
416+
}
258417
}

src/test/java/uk/nhs/hee/tis/trainee/forms/service/LtftServiceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
import uk.nhs.hee.tis.trainee.forms.dto.identity.TraineeIdentity;
125125
import uk.nhs.hee.tis.trainee.forms.mapper.LtftMapper;
126126
import uk.nhs.hee.tis.trainee.forms.mapper.LtftMapperImpl;
127+
import uk.nhs.hee.tis.trainee.forms.mapper.TemporalMapper;
127128
import uk.nhs.hee.tis.trainee.forms.mapper.TemporalMapperImpl;
128129
import uk.nhs.hee.tis.trainee.forms.model.AbstractAuditedForm;
129130
import uk.nhs.hee.tis.trainee.forms.model.AbstractAuditedForm.Status;
@@ -164,6 +165,7 @@ class LtftServiceTest {
164165
private MongoTemplate mongoTemplate;
165166
private JsonMapper jsonMapper;
166167
private LtftMapper mapper;
168+
private TemporalMapper temporalMapper;
167169
private Validator validator;
168170
private EventBroadcastService eventBroadcastService;
169171
private LtftSubmissionHistoryService ltftSubmissionHistoryService;
@@ -194,7 +196,9 @@ void setUp() {
194196
ltftSubmissionHistoryService = mock(LtftSubmissionHistoryService.class);
195197

196198
jsonMapper = (JsonMapper) new JsonMapper().registerModule(new JavaTimeModule());
199+
temporalMapper = mock(TemporalMapper.class);
197200
mapper = new LtftMapperImpl(new TemporalMapperImpl());
201+
mapper.setTemporalMapper(temporalMapper);
198202
validator = mock(Validator.class);
199203
service = new LtftService(adminIdentity, traineeIdentity, repository, mongoTemplate, jsonMapper,
200204
mapper, validator, eventBroadcastService, LTFT_ASSIGNMENT_UPDATE_TOPIC,
@@ -2884,6 +2888,7 @@ void shouldUpdateChangeWhenUpdatingLtftFormForTrainee(LifecycleState state) {
28842888
.build())
28852889
.build());
28862890

2891+
when(temporalMapper.toLocalDate(any())).thenReturn(LocalDate.now());
28872892
when(repository.findByTraineeTisIdAndId(TRAINEE_ID, ID)).thenReturn(Optional.of(existingForm));
28882893
when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0));
28892894

0 commit comments

Comments
 (0)