mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 12:08:36 +02:00
Remove contacts with empty type from console GET /contacts response (#2052)
This commit is contained in:
parent
b319eff7cd
commit
a9aaa11801
2 changed files with 33 additions and 11 deletions
|
@ -92,9 +92,12 @@ public class ContactAction implements JsonGetAction {
|
||||||
ImmutableList<RegistrarPoc> am =
|
ImmutableList<RegistrarPoc> am =
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
tm().createQueryComposer(RegistrarPoc.class)
|
tm()
|
||||||
|
.createQueryComposer(RegistrarPoc.class)
|
||||||
.where("registrarId", Comparator.EQ, registrarId)
|
.where("registrarId", Comparator.EQ, registrarId)
|
||||||
.list());
|
.stream()
|
||||||
|
.filter(r -> !r.getTypes().isEmpty())
|
||||||
|
.collect(toImmutableList()));
|
||||||
|
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
response.setPayload(gson.toJson(am));
|
response.setPayload(gson.toJson(am));
|
||||||
|
|
|
@ -74,7 +74,7 @@ class ContactActionTest {
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
private RegistrarPoc testRegistrarPoc;
|
private RegistrarPoc testRegistrarPoc;
|
||||||
private static final Gson GSON = UtilsModule.provideGson();
|
private static final Gson GSON = UtilsModule.provideGson();
|
||||||
private static final FakeResponse RESPONSE = new FakeResponse();
|
private FakeResponse response;
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
||||||
|
@ -82,6 +82,7 @@ class ContactActionTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach() {
|
void beforeEach() {
|
||||||
|
response = new FakeResponse();
|
||||||
testRegistrar = saveRegistrar("registrarId");
|
testRegistrar = saveRegistrar("registrarId");
|
||||||
testRegistrarPoc =
|
testRegistrarPoc =
|
||||||
new RegistrarPoc.Builder()
|
new RegistrarPoc.Builder()
|
||||||
|
@ -110,8 +111,26 @@ class ContactActionTest {
|
||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
null);
|
null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
assertThat(RESPONSE.getPayload()).isEqualTo("[" + jsonRegistrar1 + "]");
|
assertThat(response.getPayload()).isEqualTo("[" + jsonRegistrar1 + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSuccess_onlyContactsWithNonEmptyType() throws IOException {
|
||||||
|
testRegistrarPoc = testRegistrarPoc.asBuilder().setTypes(ImmutableSet.of()).build();
|
||||||
|
insertInDb(testRegistrarPoc);
|
||||||
|
ContactAction action =
|
||||||
|
createAction(
|
||||||
|
Action.Method.GET,
|
||||||
|
AuthResult.create(
|
||||||
|
AuthLevel.USER,
|
||||||
|
UserAuthInfo.create(
|
||||||
|
createUser(new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).build()))),
|
||||||
|
testRegistrar.getRegistrarId(),
|
||||||
|
null);
|
||||||
|
action.run();
|
||||||
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
assertThat(response.getPayload()).isEqualTo("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,7 +145,7 @@ class ContactActionTest {
|
||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
assertThat(
|
assertThat(
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
|
@ -149,7 +168,7 @@ class ContactActionTest {
|
||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
HashMap<String, String> testResult = new HashMap<>();
|
HashMap<String, String> testResult = new HashMap<>();
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
|
@ -175,7 +194,7 @@ class ContactActionTest {
|
||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
assertThat(
|
assertThat(
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
|
@ -202,7 +221,7 @@ class ContactActionTest {
|
||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private User createUser(UserRoles userRoles) {
|
private User createUser(UserRoles userRoles) {
|
||||||
|
@ -218,14 +237,14 @@ class ContactActionTest {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
when(request.getMethod()).thenReturn(method.toString());
|
when(request.getMethod()).thenReturn(method.toString());
|
||||||
if (method.equals(Action.Method.GET)) {
|
if (method.equals(Action.Method.GET)) {
|
||||||
return new ContactAction(request, authResult, RESPONSE, GSON, registrarId, Optional.empty());
|
return new ContactAction(request, authResult, response, GSON, registrarId, Optional.empty());
|
||||||
} else {
|
} else {
|
||||||
when(request.getReader())
|
when(request.getReader())
|
||||||
.thenReturn(new BufferedReader(new StringReader("{\"contacts\":" + contacts + "}")));
|
.thenReturn(new BufferedReader(new StringReader("{\"contacts\":" + contacts + "}")));
|
||||||
Optional<ImmutableSet<RegistrarPoc>> maybeContacts =
|
Optional<ImmutableSet<RegistrarPoc>> maybeContacts =
|
||||||
RegistrarConsoleModule.provideContacts(
|
RegistrarConsoleModule.provideContacts(
|
||||||
GSON, RequestModule.provideJsonBody(request, GSON));
|
GSON, RequestModule.provideJsonBody(request, GSON));
|
||||||
return new ContactAction(request, authResult, RESPONSE, GSON, registrarId, maybeContacts);
|
return new ContactAction(request, authResult, response, GSON, registrarId, maybeContacts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue