Merge branch '37-verifier-les-conflits-de-produits-mixtype-lors-de-la-creation-de-melanges' into 'master'

Resolve "Vérifier les conflits de produits (MixType) lors de la création de mélanges"

Closes #37

See merge request color-recipes-explorer/backend!1
This commit is contained in:
William Nolin 2021-02-14 17:06:45 +00:00
commit d2525fa991
5 changed files with 9 additions and 5 deletions

View File

@ -30,8 +30,8 @@ test:
TEST_CONTAINER_NAME: "cre_backend_gradle_tests-$CI_COMMIT_REF_NAME"
script:
- docker run --name $TEST_CONTAINER_NAME $CI_REGISTRY_IMAGE_GRADLE gradle test
- mkdir test-results && docker cp $TEST_CONTAINER_NAME:/usr/src/cre/build/test-results/test/ test-results
after_script:
- mkdir test-results && docker cp $TEST_CONTAINER_NAME:/usr/src/cre/build/test-results/test/ test-results
- docker rm $TEST_CONTAINER_NAME
artifacts:
when: always

View File

@ -26,7 +26,7 @@ data class Mix(
@ManyToOne
val recipe: Recipe,
@ManyToOne(cascade = [CascadeType.PERSIST])
@ManyToOne
var mixType: MixType,
@OneToMany(cascade = [CascadeType.ALL])

View File

@ -33,7 +33,7 @@ class MixServiceImpl(
override fun save(entity: MixSaveDto): Mix {
val recipe = recipeService.getById(entity.recipeId)
val materialType = materialTypeService.getById(entity.materialTypeId)
val mixType = MixType(entity.name, materialType)
val mixType = mixTypeService.createForNameAndMaterialType(entity.name, materialType)
var mix = save(mix(recipe = recipe, mixType = mixType))
val mixMaterials =

View File

@ -1,5 +1,5 @@
#spring.datasource.url=jdbc:h2:mem:cre
spring.datasource.url=jdbc:h2:file:./workdir/recipes
spring.datasource.url=jdbc:h2:mem:cre
#spring.datasource.url=jdbc:h2:file:./workdir/recipes
spring.datasource.username=sa
spring.datasource.password=LWK4Y7TvEbNyhu1yCoG3
spring.h2.console.path=/dbconsole

View File

@ -56,6 +56,7 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
whenever(recipeService.getById(recipe.id!!)).doReturn(recipe)
whenever(materialTypeService.getById(materialType.id!!)).doReturn(materialType)
whenever(mixMaterialService.createFromMap(mixWithId, entitySaveDto.mixMaterials!!)).doReturn(mixMaterials)
whenever(mixTypeService.createForNameAndMaterialType(mixType.name, mixType.material.materialType!!)).doReturn(mixType)
doReturn(true).whenever(service).existsById(mixWithId.id!!)
doReturn(mixWithId).whenever(service).save(mix)
doReturn(mixWithMaterials).whenever(service).update(mixWithMaterials)
@ -66,6 +67,9 @@ class MixServiceTest : AbstractExternalModelServiceTest<Mix, MixSaveDto, MixUpda
verify(service).update(mixWithMaterials)
verify(recipeService).addMix(recipe, mix)
// Verify if this method is called instead of the MixType's constructor, which does not check if the name is already taken by a material.
verify(mixTypeService).createForNameAndMaterialType(mixType.name, mixType.material.materialType!!)
assertEquals(mixWithMaterials, found)
}
}