Commit 07ba04b0 authored by Julien BOUYER's avatar Julien BOUYER
Browse files

Merge branch 'develop' into feature/expression_items

parents 151cd472 513600fb
......@@ -7,7 +7,7 @@
<groupId>com.unantes.orientactive</groupId>
<artifactId>orientactive</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Unantes Orientation Active</name>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -40,6 +40,16 @@ public class Expression implements IExpression {
*/
public static final String VARIABLE_PART_SEPARATOR = "__";
/**
* Le séparateur entre la référence de la question et sa valeur.
*/
private static final String QUESTION_VALUE_SEPARATOR = "__";
/**
* Le séparateur entre la référence du screen et la référence de la question.
*/
private static final String SCREEN_QUESTION_SEPARATOR = "_";
/**
* Lors du calcul des variables {@link #addVariables(List)}, une boucle infi peut se produire. Cette constante en est le seuil de détection.
*/
......@@ -335,7 +345,7 @@ public class Expression implements IExpression {
* @return
*/
protected String getAnswerReference(final String screenReference, final String questionReference, final String value) {
return getQuestionReference(screenReference, questionReference) + VARIABLE_PART_SEPARATOR + value;
return getQuestionReference(screenReference, questionReference) + QUESTION_VALUE_SEPARATOR + value;
}
/**
......@@ -345,7 +355,7 @@ public class Expression implements IExpression {
* @return
*/
protected String getQuestionReference(final String screenReference, final String questionReference) {
return screenReference + VARIABLE_PART_SEPARATOR + questionReference;
return screenReference + SCREEN_QUESTION_SEPARATOR + questionReference;
}
/**
......
-- UNOTOPLYS-267 : migration des items de type image et des conditions "not hasAnswer"
update screen set items = replace(items::TEXT, '"type": "image"', '"type": "picture"')::jsonb;
update screen set items = replace(items::TEXT, 'not hasAnswer', 'hasNoAnswer')::jsonb;
......@@ -44,6 +44,7 @@
<include file="config/liquibase/changelog/20210428172600_migration_droit.sql" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20210603140000_ajout_type_variable.sql" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20210621104900_migration_conditions.sql" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20210621152400_migration_screen_items.sql" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
</databaseChangeLog>
......@@ -11,7 +11,7 @@
"actions": {
"nouveau": "Ajouter un utilisateur",
"addUser": "Ajouter",
"addContrib": "Ajouter un responsable"
"addContrib": "Ajouter un utilisateur"
},
"edit": {
"title": "Édition d'un utilisateur",
......@@ -33,7 +33,7 @@
},
"admin": {
"confirm": {
"delete": "Voulez-vous vraiment supprimer ce responsable ?"
"delete": "Voulez-vous vraiment supprimer cet utilisateur ?"
}
}
}
......
......@@ -6,6 +6,7 @@ import com.unantes.orientactive.converter.bean.AnswerElements;
import com.unantes.orientactive.converter.bean.Item;
import com.unantes.orientactive.service.dto.AnswerDTO;
import com.unantes.orientactive.service.dto.VariableDTO;
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
......@@ -90,55 +91,6 @@ class ExpressionTest extends AbstractTest {
assertTrue(expression.evaluate("answers[Q2_R1] && variables[moy_spe_scient] >= 0 && variables[moy_spe_scient] < 6", Boolean.class));
}
@Test
public void addAnswers() {
final Expression expression = initializeExpression("answersItem.json", "answersElement.json");
//première question
assertTrue(expression.evaluate("answers[S01_souhait_parcours_staps]", Boolean.class));
assertFalse(expression.evaluate("answers[S01_souhait_parcours_las]", Boolean.class));
assertFalse(expression.evaluate("answers[S01_souhait_parcours_both]", Boolean.class));
//deuxième question
assertFalse(expression.evaluate("answers[S01_projet_pro_1]", Boolean.class));
assertTrue(expression.evaluate("answers[S01_projet_pro_2]", Boolean.class));
assertFalse(expression.evaluate("answers[S01_projet_pro_0]", Boolean.class));
//troisème question
assertFalse(expression.evaluate("answers[S01_connaissance_filiere_0]", Boolean.class));
assertTrue(expression.evaluate("answers[S01_connaissance_filiere_1]", Boolean.class));
assertFalse(expression.evaluate("answers[S01_connaissance_filiere_2]", Boolean.class));
assertEquals(5d, expression.evaluate("scores[S01_projet_pro]", Double.class));
}
private Expression initializeExpression(final String screenItemsResource, final String answerElementsResource) {
final Expression expression = new Expression();
List<AnswerDTO> answers = new ArrayList<>();
AnswerDTO answserS01 = new AnswerDTO();
answers.add(answserS01);
List<Item> items = serviceConverter.deserializeScreenItems(readTestResource(screenItemsResource));
answserS01.setScreenItems(items);
answserS01.setScreenReference("S01");
List<AnswerElements> answerElements = serviceConverter.deserializeAnswersItems(readTestResource(answerElementsResource));
answserS01.setAnswerElements(answerElements);
expression.addAnswers(answers);
return expression;
}
@Test
public void addVariablesOK() {
final Expression expression = initializeExpression("answersItem.json", "answersElement.json");
VariableDTO variable1 = new VariableDTO();
variable1.setReference("variable1");
variable1.setExpression("answers[S01_connaissance_filiere_1] ? scores[S01_projet_pro] : 0");
VariableDTO variable2 = new VariableDTO();
variable2.setReference("variable2");
variable2.setExpression("answers[S01_souhait_parcours_staps] ? variables[variable1] + 20 : 0d");
variable2.setPreviousVariables(Collections.singleton(variable1));
List<VariableDTO> variables = new ArrayList<>();
variables.add(variable2);
variables.add(variable1);
expression.addVariables(variables);
assertEquals(25d, expression.evaluate("variables[variable2]", Double.class));
}
@Test
public void exclusiveOr() {
final Expression expression = new Expression();
......
......@@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.junit.Ignore;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -388,21 +389,6 @@ class NavigationServiceTest {
assertEquals(secondScreen.getId(), screen.getId());
}
/**
* Sauvegarde des réponses pour un écran d'un processus utilisateur sans avoir répondu à toutes les questions obligatoires.
* Doit lever une exception.
*/
@Test
void save_answer_process_error() {
// Initialisation.
firstScreen.setItems(("[ { \"reference\": \"souhait_parcours\", \"type\": \"radio\", \"required\": true, \"question\": \"Quel sera votre voeu d'orientation sur Parcoursup ?\", \"choices\": [ { \"label\": \"L1 STAPS\", \"value\": \"A1\" }, { \"label\": \"L1 STAPS Parcours Santé\", \"value\": \"A2\" }, { \"label\": \"Les 2 parcours\", \"value\": \"A3\" } ] } ]"));
screenRepository.save(firstScreen);
Answer answerScreen1 = new Answer().sessionId(SESSION_ID).answers("[]").screen(firstScreen);
answerRepository.save(answerScreen1);
// Fin initialisation.
assertThrows(RequiredAnswersMissingException.class, () -> navigationService.saveAnswerProcess(SESSION_ID, screenMapper.toDto(firstScreen), new LinkedList<>()));
}
/**ScreenNavigationServiceTest
* Sauvegarde des réponses pour un écran d'un processus utilisateur sans avoir répondu à toutes les questions obligatoires.
* Doit retourné l'écran suivant.
......
......@@ -4,6 +4,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.junit.Ignore;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -98,36 +99,13 @@ class ScreenNavigationServiceTest extends AbstractTest {
verify(screenService, times(2)).findScreenByIndexAndFormId(screen2.getIndex(), form.getId());
}
@Test
void getNextScreenWithNextScreenExpression() {
when(answerService.getSessionAnswers(DEFAULT_SESSION_ID, form.getId())).thenReturn(Collections.singletonList(answerMapper.toDto(answer)));
NextScreenExpression nextScreenExpression = new NextScreenExpression();
nextScreenExpression.setExpression("answers[S01_souhait_parcours_staps]");
nextScreenExpression.setNextScreenReference("S04");
screen2.setNextScreenExpressions(List.of(nextScreenExpression));
ScreenDTO screen4DTO = screenMapper.toDto(screen4);
when(screenService.findOneByReference("S04")).thenReturn(Optional.of(screen4DTO));
when(screenService.findScreenByIndexAndFormId(screen3.getIndex(), form.getId())).thenReturn(Optional.of(screenMapper.toDto(screen3)));
ScreenDTO nextScreen = screenNavigationService.getNextScreen(DEFAULT_SESSION_ID, screenMapper.toDto(screen2));
assertEquals("S04", nextScreen.getReference());
assertEquals(2, nextScreen.getItemsList().size());
Item expectedVarItem = nextScreen.getItemsList().get(0);
assertEquals("message", expectedVarItem.getType());
assertTrue(ReadOnlyTextItem.class.isInstance(expectedVarItem));
assertEquals("answers[S01_souhait_parcours_staps] && answers[S01_projet_pro_1] : false", ReadOnlyTextItem.class.cast(expectedVarItem).getContent());
assertEquals("moy_gen", nextScreen.getItemsList().get(1).getReference());
verify(screenService).findOneByReference("S04");
verify(answerService).getSessionAnswers(DEFAULT_SESSION_ID, form.getId());
verify(screenService).findScreenByIndexAndFormId(screen3.getIndex(), form.getId());
}
@Test
void getNextScreenWithDefaultNextScreenReference() {
when(answerService.getSessionAnswers(DEFAULT_SESSION_ID, form.getId())).thenReturn(Collections.singletonList(answerMapper.toDto(answer)));
screen2.setDefaultNextScreenReference("S04");
ScreenDTO screen4DTO = screenMapper.toDto(screen4);
when(screenService.findOneByReference("S04")).thenReturn(Optional.of(screen4DTO));
when(screenService.findScreenByIndexAndFormId(screen3.getIndex(),form.getId())).thenReturn(Optional.of(screenMapper.toDto(screen3)));
when(screenService.findScreenByIndexAndFormId(screen3.getIndex(), form.getId())).thenReturn(Optional.of(screenMapper.toDto(screen3)));
ScreenDTO nextScreen = screenNavigationService.getNextScreen(DEFAULT_SESSION_ID, screenMapper.toDto(screen2));
assertEquals("S04", nextScreen.getReference());
assertEquals(2, nextScreen.getItemsList().size());
......
......@@ -337,25 +337,6 @@ public class FormApiDelegateImplIT {
// @formatter:on
}
/**
* Simulation de la soumission d'un écran contenant des réponses non saisies pour des questions obligatoires.
* Doit retourner une erreur 403.
*
* @throws Exception Erreur lors de l'execution du test.
*/
@Test
@Transactional
public void next_lack_required_field() throws Exception {
firstScreen.setItems("[ { \"reference\": \"souhait_parcours\", \"type\": \"radio\", \"required\": true, \"question\": \"Quel sera votre voeu d'orientation sur Parcoursup ?\", \"choices\": [ { \"label\": \"L1 STAPS\", \"value\": \"A1\" }, { \"label\": \"L1 STAPS Parcours Santé\", \"value\": \"A2\" }, { \"label\": \"Les 2 parcours\", \"value\": \"A3\" } ] } ]");
Answer answerScreen1 = new Answer().sessionId(session.getId()).answers("[]").screen(firstScreen);
answerRepository.save(answerScreen1);
// @formatter:off
restFormMockMvc.perform(post("/api/form/form/" + session.getId() + "/first/next").contentType(MediaType.APPLICATION_JSON).content("[]"))
.andExpect(status().is(403))
.andExpect(jsonPath("$.message", is(new RequiredAnswersMissingException(new HashSet<>()).getUserMessage())));
// @formatter:on
}
/**
* Simulation de la soumission d'un écran contenant des réponses pour toutes les questions obligatoires.
* Doit retourner la page suivante.
......
......@@ -244,92 +244,6 @@ public class ScreenResourceIT {
.andExpect(status().isForbidden());
}
@Test
@Transactional
public void getScreen() throws Exception {
// Initialize the database
screenRepository.saveAndFlush(screen);
// Get the screen
restScreenMockMvc.perform(get("/api/screens/{id}", screen.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id").value(screen.getId().intValue()))
.andExpect(jsonPath("$.name").value(DEFAULT_NAME))
.andExpect(jsonPath("$.reference").value(DEFAULT_REFERENCE))
.andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()))
.andExpect(jsonPath("$.defaultNextScreenReference").value(DEFAULT_NEXT_SCREEN_REFERENCE.toString()))
.andExpect(jsonPath("$.items").value(DEFAULT_ITEMS.toString()));
}
@Test
@Transactional
public void getNonExistingScreen() throws Exception {
// Get the screen
restScreenMockMvc.perform(get("/api/screens/{id}", Long.MAX_VALUE))
.andExpect(status().isNotFound());
}
@Test
@Transactional
public void updateScreen() throws Exception {
// Initialize the database
screenRepository.saveAndFlush(screen);
int databaseSizeBeforeUpdate = screenRepository.findAll().size();
// Update the screen
Screen updatedScreen = screenRepository.findById(screen.getId()).get();
// Disconnect from session so that the updates on updatedScreen are not directly saved in db
em.detach(updatedScreen);
updatedScreen
.name(UPDATED_NAME)
.reference(UPDATED_REFERENCE)
.description(UPDATED_DESCRIPTION)
.defaultNextScreenReference(UPDATED_DEFAULT_NEXT_SCREEN_REFERENCE)
.items(UPDATED_ITEMS);
NextScreenExpression nextScreenExpression2 = updatedScreen.getNextScreenExpressions().get(1);
nextScreenExpression2.setExpression(UPDATED_NEXT_SCREEN_EXPRESSION_02);
nextScreenExpression2.setNextScreenReference(UPDATED_NEXT_SCREEN_REFERENCE_02);
NextScreenExpression nextScreenExpression3 = new NextScreenExpression();
nextScreenExpression3.setNextScreenReference(NEW_NEXT_SCREEN_REFERENCE_03);
nextScreenExpression3.setExpression(NEW_NEXT_SCREEN_EXPRESSION_03);
updatedScreen.addNextScreenExpression(nextScreenExpression3);
ScreenDTO screenDTO = screenMapper.toDto(updatedScreen);
restScreenMockMvc.perform(put("/api/screens")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(screenDTO)))
.andExpect(status().isOk());
// Validate the Screen in the database
List<Screen> screenList = screenRepository.findAll();
assertThat(screenList).hasSize(databaseSizeBeforeUpdate);
Screen testScreen = screenList.get(screenList.size() - 1);
assertThat(testScreen.getName()).isEqualTo(UPDATED_NAME);
assertThat(testScreen.getReference()).isEqualTo(UPDATED_REFERENCE);
assertThat(testScreen.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
assertThat(testScreen.getDefaultNextScreenReference()).isEqualTo(UPDATED_DEFAULT_NEXT_SCREEN_REFERENCE);
assertThat(testScreen.getItems()).isEqualTo(UPDATED_ITEMS);
List<NextScreenExpression> actualNextScreenExpressions = testScreen.getNextScreenExpressions();
Assert.assertEquals(3, actualNextScreenExpressions.size());
NextScreenExpression nextScreenExpression01 = actualNextScreenExpressions.get(0);
NextScreenExpression nextScreenExpression02 = actualNextScreenExpressions.get(1);
NextScreenExpression nextScreenExpression03 = actualNextScreenExpressions.get(2);
Assert.assertEquals(DEFAULT_NEXT_SCREEN_EXPRESSION_01, nextScreenExpression01.getExpression());
Assert.assertEquals(DEFAULT_NEXT_SCREEN_REFERENCE_01, nextScreenExpression01.getNextScreenReference());
Assert.assertEquals(UPDATED_NEXT_SCREEN_EXPRESSION_02, nextScreenExpression02.getExpression());
Assert.assertEquals(UPDATED_NEXT_SCREEN_REFERENCE_02, nextScreenExpression02.getNextScreenReference());
Assert.assertEquals(NEW_NEXT_SCREEN_EXPRESSION_03, nextScreenExpression03.getExpression());
Assert.assertEquals(NEW_NEXT_SCREEN_REFERENCE_03, nextScreenExpression03.getNextScreenReference());
Assert.assertNotNull(nextScreenExpression01.getId());
Assert.assertNotNull(nextScreenExpression02.getId());
Assert.assertNotNull(nextScreenExpression03.getId());
}
@Test
@Transactional
public void updateNonExistingScreen() throws Exception {
......@@ -390,32 +304,6 @@ public class ScreenResourceIT {
.andExpect(jsonPath("$.message").value("L'entité avec l'ID : '1' n'existe pas en base"));
}
@Test
@Transactional
public void deleteNextScreenExpression() throws Exception {
// Initialize the database
screenRepository.saveAndFlush(screen);
// Update the screen
Screen updatedScreen = screenRepository.findById(screen.getId()).get();
// Disconnect from session so that the updates on updatedScreen are not directly saved in db
em.detach(updatedScreen);
ScreenDTO screenDTO = screenMapper.toDto(updatedScreen);
screenDTO.getNextScreenExpressions().remove(0);
restScreenMockMvc.perform(put("/api/screens")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(screenDTO)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.nextScreenExpressions[0].nextScreenReference").value("S03"));
// est ce que l'autre élément a bien été supprimé
Assert.assertEquals(1, em.createNativeQuery("select * from next_screen_expression").getResultList().size());
}
@Test
@Transactional
public void moveDownScreenTest() throws Exception {
......
package com.unantes.orientactive.web.rest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import com.unantes.orientactive.IntegrationTest;
import com.unantes.orientactive.domain.Variable;
import com.unantes.orientactive.repository.VariableRepository;
import com.unantes.orientactive.service.VariableService;
import com.unantes.orientactive.service.dto.VariableDTO;
import com.unantes.orientactive.service.mapper.VariableMapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -25,12 +14,22 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Integration tests for the {@link VariableResource} REST controller.
......@@ -81,7 +80,7 @@ class VariableResourceIT {
/**
* Create an entity for this test.
*
* <p>
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
......@@ -96,7 +95,7 @@ class VariableResourceIT {
/**
* Create an updated entity for this test.
*
* <p>
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
......@@ -207,7 +206,7 @@ class VariableResourceIT {
.andExpect(jsonPath("$.[*].expression").value(hasItem(DEFAULT_EXPRESSION.toString())));
}
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({"unchecked"})
void getAllVariablesWithEagerRelationshipsIsEnabled() throws Exception {
when(variableServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>()));
......@@ -216,7 +215,7 @@ class VariableResourceIT {
verify(variableServiceMock, times(1)).findAllWithEagerRelationships(any());
}
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({"unchecked"})
void getAllVariablesWithEagerRelationshipsIsNotEnabled() throws Exception {
when(variableServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>()));
......@@ -243,46 +242,6 @@ class VariableResourceIT {
.andExpect(jsonPath("$.expression").value(DEFAULT_EXPRESSION.toString()));
}
@Test
@Transactional
void getNonExistingVariable() throws Exception {
// Get the variable
restVariableMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
}
@Test
@Transactional
void putNewVariable() throws Exception {
// Initialize the database
variableRepository.saveAndFlush(variable);
int databaseSizeBeforeUpdate = variableRepository.findAll().size();
// Update the variable
Variable updatedVariable = variableRepository.findById(variable.getId()).get();
// Disconnect from session so that the updates on updatedVariable are not directly saved in db
em.detach(updatedVariable);
updatedVariable.name(UPDATED_NAME).reference(UPDATED_REFERENCE).description(UPDATED_DESCRIPTION).expression(UPDATED_EXPRESSION);
VariableDTO variableDTO = variableMapper.toDto(updatedVariable);
restVariableMockMvc
.perform(
put(ENTITY_API_URL_ID, variableDTO.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(variableDTO))
)
.andExpect(status().isOk());
// Validate the Variable in the database
List<Variable> variableList = variableRepository.findAll();
assertThat(variableList).hasSize(databaseSizeBeforeUpdate);
Variable testVariable = variableList.get(variableList.size() - 1);
assertThat(testVariable.getName()).isEqualTo(UPDATED_NAME);
assertThat(testVariable.getReference()).isEqualTo(UPDATED_REFERENCE);
assertThat(testVariable.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
assertThat(testVariable.getExpression()).isEqualTo(UPDATED_EXPRESSION);
}
@Test
@Transactional
void putNonExistingVariable() throws Exception {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment