Commit e78e7408 authored by Artem Hrybeniuk's avatar Artem Hrybeniuk
Browse files

Merge branch 'fix_inventory_update' into 'main'

Fixed saving unchanged inventory

See merge request grin-global/grin-global-server!382
parents 0ccb23b1 81710452
......@@ -120,7 +120,7 @@ public abstract class CRUDController<E extends EmptyModel, S extends CRUDService
@PostMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@Operation(operationId = "create", description = "Create a record", summary = "Add")
public E create(@RequestBody @Valid @NotNull final E entity) {
return crudService.reload(crudService.create(entity));
return crudService.load(crudService.create(entity).getId());
}
/**
......@@ -144,7 +144,7 @@ public abstract class CRUDController<E extends EmptyModel, S extends CRUDService
@PutMapping(value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@Operation(operationId = "update", description = "Update an existing record", summary = "Update")
public E update(@RequestBody final E entity) {
return crudService.reload(crudService.update(entity));
return crudService.load(crudService.update(entity).getId());
}
/**
......
......@@ -1141,6 +1141,38 @@ public class InventoryControllerTest extends AbstractApiV1Test {
/*@formatter:on*/
}
@Test
public void testUpdateInventoryWithoutChanges() throws Exception {
Accession accession = makeAccession();
var inventory = addInventoryToDB(accession, "INV", 99L, null);
/*@formatter:off*/
mockMvc
.perform(put(InventoryController.API_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(inventory))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.id", is(greaterThan(0))))
.andExpect(jsonPath("$.createdBy", is(USER_CURATOR1)))
.andExpect(jsonPath("$.modifiedBy", is(USER_CURATOR1)))
.andExpect(jsonPath("$.ownedBy", is(USER_CURATOR1)))
.andExpect(jsonPath("$.formTypeCode", is(INVENTORY_FORM_TYPE_CODE_DEFAULT)))
.andExpect(jsonPath("$.site").exists()) // May be serialized as ID only
.andExpect(jsonPath("$.accession").isMap())
.andExpect(jsonPath("$.accession.id", is(accession.getId().intValue())))
.andExpect(jsonPath("$.availabilityStatusCode", is(CommunityCodeValues.INVENTORY_AVAILABILITY_AVAILABLE.value)))
.andExpect(jsonPath("$.isAutoDeducted", is(TRUE)))
.andExpect(jsonPath("$.isAvailable", is(TRUE)))
.andExpect(jsonPath("$.isDistributable", is(TRUE)))
.andExpect(jsonPath("$.inventoryMaintenancePolicy").isMap())
.andExpect(jsonPath("$.inventoryMaintenancePolicy.id", is(inventory.getInventoryMaintenancePolicy().getId().intValue())))
;
/*@formatter:on*/
}
@Test
public void testCreateInventory() throws Exception {
Accession accession = new Accession(makeAccession().getId());
......
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