Navigation Menu

Skip to content

Commit

Permalink
Fix error messages returned by api
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed May 10, 2019
1 parent 6e79bfd commit e7b0587
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Expand Up @@ -87,10 +87,14 @@ ResponseEntity<JsonDataEntryResponse> getByRecordId0(final AdWindowId windowId,
final DataEntryLayout layout = layoutRepo.getByWindowId(windowId);
if (layout.isEmpty())
{
return JsonDataEntryResponse.notFound(String.format("No dataentry for windowId '%d' and recordId '%s'.", windowId.getRepoId(), recordId));
return JsonDataEntryResponse.notFound(String.format("No dataentry for windowId '%d'.", windowId.getRepoId()));
}

final DataEntryRecordsMap records = dataRecords.get(recordId, layout.getSubTabIds());
if (records.getSubTabIds().isEmpty())
{
return JsonDataEntryResponse.notFound(String.format("No dataentry for windowId '%d' and recordId '%s'.", windowId.getRepoId(), recordId));
}

final JsonDataEntry jsonDataEntry = JsonDataEntryFactory.builder()
.layout(layout)
Expand Down
Expand Up @@ -4,11 +4,9 @@
import de.metas.dataentry.data.json.JSONDataEntryRecordMapper;
import de.metas.dataentry.layout.DataEntryLayoutRepository;
import de.metas.dataentry.model.I_DataEntry_Field;

import de.metas.dataentry.model.I_DataEntry_Line;
import de.metas.dataentry.model.I_DataEntry_ListValue;
import de.metas.dataentry.model.I_DataEntry_Section;

import de.metas.dataentry.model.I_DataEntry_SubTab;
import de.metas.dataentry.model.I_DataEntry_Tab;
import de.metas.dataentry.model.X_DataEntry_Field;
Expand Down Expand Up @@ -85,7 +83,20 @@ void badWindowGivesEmptyResult()
final int inexistentWindowId = 55555;
final JsonDataEntryResponse shouldBeEmpty = dataEntryRestController.getByRecordId0(AdWindowId.ofRepoId(inexistentWindowId), bPartner.getC_BPartner_ID(), Env.getLanguage().getAD_Language()).getBody();
assertThat(shouldBeEmpty.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
assertThat(shouldBeEmpty.getError()).contains(String.valueOf(inexistentWindowId));
assertThat(shouldBeEmpty.getError()).contains(String.valueOf(inexistentWindowId)).doesNotContain(String.valueOf(bPartner.getC_BPartner_ID()));
assertThat(shouldBeEmpty.getResult()).isNull();
expect(shouldBeEmpty).toMatchSnapshot();
}

@Test
void badRecordIdGivesEmptyResult()
{
createRecords();

final int inexistentRecordId = 5;
final JsonDataEntryResponse shouldBeEmpty = dataEntryRestController.getByRecordId0(AdWindowId.ofRepoId(BPARTNER_WINDOW_ID), inexistentRecordId, Env.getLanguage().getAD_Language()).getBody();
assertThat(shouldBeEmpty.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
assertThat(shouldBeEmpty.getError()).contains(String.valueOf(inexistentRecordId)).contains(String.valueOf(BPARTNER_WINDOW_ID));
assertThat(shouldBeEmpty.getResult()).isNull();
expect(shouldBeEmpty).toMatchSnapshot();
}
Expand Down
@@ -1,7 +1,15 @@
de.metas.dataentry.rest_api.DataEntryRestControllerTest.badRecordIdGivesEmptyResult=[
{
"status": 404,
"error": "No dataentry for windowId '123' and recordId '5'."
}
]


de.metas.dataentry.rest_api.DataEntryRestControllerTest.badWindowGivesEmptyResult=[
{
"status": 404,
"error": "No dataentry for windowId '55555' and recordId '100038'."
"error": "No dataentry for windowId '55555'."
}
]

Expand Down

0 comments on commit e7b0587

Please sign in to comment.