-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix delete draft removing original questions (#1205)
* Fix delete draft removing original questions * test --------- Co-authored-by: Michael Peels <[email protected]>
- Loading branch information
Showing
3 changed files
with
132 additions
and
65 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
59 changes: 59 additions & 0 deletions
59
apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/page/PageStateChangerTest.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,59 @@ | ||
package gov.cdc.nbs.questionbank.page; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
import java.util.Arrays; | ||
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.junit.jupiter.MockitoExtension; | ||
import gov.cdc.nbs.questionbank.entity.WaTemplate; | ||
import gov.cdc.nbs.questionbank.entity.pagerule.WaRuleMetadata; | ||
import gov.cdc.nbs.questionbank.entity.repository.PageCondMappingRepository; | ||
import gov.cdc.nbs.questionbank.entity.repository.WaTemplateRepository; | ||
import gov.cdc.nbs.questionbank.entity.repository.WaUiMetadataRepository; | ||
import gov.cdc.nbs.questionbank.page.exception.PageUpdateException; | ||
import gov.cdc.nbs.questionbank.pagerules.repository.WaRuleMetaDataRepository; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class PageStateChangerTest { | ||
|
||
@Mock | ||
private WaTemplateRepository templateRepository; | ||
@Mock | ||
private WaUiMetadataRepository waUiMetadataRepository; | ||
@Mock | ||
private PageCondMappingRepository pageConMappingRepository; | ||
@Mock | ||
private WaRuleMetaDataRepository waRuleMetaDataRepository; | ||
@InjectMocks | ||
private PageStateChanger changer; | ||
|
||
|
||
@Test | ||
void should_copy_rules() { | ||
when(waRuleMetaDataRepository.findByWaTemplateUid(1l)).thenReturn(rules()); | ||
List<WaRuleMetadata> newRules = changer.copyRules(1l, 2l); | ||
assertThat(newRules).hasSize(2).allSatisfy(c -> assertThat(c.getWaTemplateUid()).isEqualTo(2)); | ||
} | ||
|
||
@Test | ||
void should_throw_exception() { | ||
WaTemplate page = new WaTemplate(); | ||
page.setTemplateType("Published With Draft"); | ||
when(templateRepository.findById(1l)).thenReturn(Optional.of(page)); | ||
assertThrows(PageUpdateException.class, () -> changer.savePageAsDraft(1l)); | ||
} | ||
|
||
List<WaRuleMetadata> rules() { | ||
WaRuleMetadata rule1 = new WaRuleMetadata(); | ||
rule1.setId(1l); | ||
WaRuleMetadata rule2 = new WaRuleMetadata(); | ||
rule2.setId(2l); | ||
return Arrays.asList(rule1, rule2); | ||
} | ||
} |