Skip to content

Commit

Permalink
Changed response for support rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed May 8, 2024
1 parent f3c8a79 commit 5b7003a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 253 deletions.
110 changes: 6 additions & 104 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2451,109 +2451,6 @@
}
}
},
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"text/html" : {
"schema" : {
"type" : "string"
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/v1/support/request" : {
"post" : {
"tags" : [ "support" ],
"summary" : "getSupportRedirectUrl",
"description" : "Service to retrieve Support contact's form",
"operationId" : "getSupportRedirectUrlUsingPOST",
"parameters" : [ {
"name" : "authenticated",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "boolean"
}
}, {
"name" : "authorities[0].authority",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "string"
}
}, {
"name" : "credentials",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
}, {
"name" : "details",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
}, {
"name" : "principal",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
} ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/SupportRequestDto"
}
}
}
},
"responses" : {
"200" : {
"description" : "OK",
Expand Down Expand Up @@ -2596,7 +2493,6 @@
}
}
},
"deprecated" : true,
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
Expand Down Expand Up @@ -6394,6 +6290,12 @@
"title" : "SupportResponse",
"type" : "object",
"properties" : {
"actionUrl" : {
"type" : "string"
},
"jwt" : {
"type" : "string"
},
"redirectUrl" : {
"type" : "string"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package it.pagopa.selfcare.dashboard.connector.model.support;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

@Data
@Builder
@ToString
@NoArgsConstructor @AllArgsConstructor
public class SupportResponse {
private String redirectUrl;
private String jwt;
private String actionUrl;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package it.pagopa.selfcare.dashboard.core;

import it.pagopa.selfcare.dashboard.connector.model.support.SupportRequest;
import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse;

public interface SupportService {
String sendRequest(SupportRequest supportRequest);
String getSupportRequest(SupportRequest supportRequest);
SupportResponse sendRequest(SupportRequest supportRequest);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package it.pagopa.selfcare.dashboard.core.config;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
Expand All @@ -19,7 +16,6 @@
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.net.URL;
import java.util.Properties;
Expand All @@ -33,14 +29,12 @@ class CoreConfig implements AsyncConfigurer {

private final URL rootTemplateUrl;


@Autowired
public CoreConfig(@Value("${dashboard.notification.template.default-url}") URL rootTemplateUrl) {
log.trace("Initializing {}", CoreConfig.class.getSimpleName());
this.rootTemplateUrl = rootTemplateUrl;
}


@Bean
public freemarker.template.Configuration customFreeMarkerConfiguration() throws TemplateException {
Properties settings = new Properties();
Expand All @@ -52,29 +46,16 @@ public freemarker.template.Configuration customFreeMarkerConfiguration() throws
return configuration;
}

@Bean("zendeskFreeMarker")
public FreeMarkerConfigurer freemarkerClassLoaderConfig() {
freemarker.template.Configuration configuration = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27);
TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), "/template-zendesk");
configuration.setTemplateLoader(templateLoader);
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
freeMarkerConfigurer.setConfiguration(configuration);
return freeMarkerConfigurer;
}


@Bean
public SimpleAsyncUncaughtExceptionHandler simpleAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}


@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return simpleAsyncUncaughtExceptionHandler();
}


@Bean
public DelegatingSecurityContextAsyncTaskExecutor taskExecutor(TaskExecutorBuilder taskExecutorBuilder) {
final ThreadPoolTaskExecutor delegate = taskExecutorBuilder.build();
Expand Down
10 changes: 0 additions & 10 deletions core/src/main/resources/template-zendesk/template-zendesk-form.ftl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package it.pagopa.selfcare.dashboard.core;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.TemplateLoader;
import it.pagopa.selfcare.dashboard.connector.api.UserRegistryConnector;
import it.pagopa.selfcare.dashboard.connector.exception.ResourceNotFoundException;
import it.pagopa.selfcare.dashboard.connector.exception.SupportException;
import it.pagopa.selfcare.dashboard.connector.model.support.SupportRequest;
import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse;
import it.pagopa.selfcare.dashboard.connector.model.support.UserField;
import it.pagopa.selfcare.dashboard.connector.model.user.CertifiedField;
import it.pagopa.selfcare.dashboard.connector.model.user.User;
Expand All @@ -14,9 +13,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -34,21 +31,20 @@ class SupportServiceImplTest {
*/
@Test
void testSendRequest(){
FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig();
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null);
String url = supportServiceImpl.sendRequest(this.dummySupportRequest());
assertNotNull(url);
assertTrue(url.contains("jwt"));
assertEquals("<html>", url.substring(0, 6));
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "test-organization", "redirectUrl", null);
SupportResponse response = supportServiceImpl.sendRequest(this.dummySupportRequest());
assertNotNull(response);
assertNotNull(response.getJwt());
assertNotNull(response.getRedirectUrl());
assertEquals("http", response.getRedirectUrl().substring(0, 4));
}

/**
* Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)}
*/
@Test
void testSendRequestWithUserId(){
FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig();
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, userRegistryConnector);
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "test-organization", "redirectUrl", userRegistryConnector);
SupportRequest supportRequest = this.dummySupportRequest();
supportRequest.setUserId("userId");
supportRequest.setInstitutionId("institutionId");
Expand All @@ -59,19 +55,19 @@ void testSendRequestWithUserId(){
user.setName(certifiedField);
user.setFamilyName(certifiedField);
when(userRegistryConnector.getUserByInternalId(anyString(), any())).thenReturn(user);
String url = supportServiceImpl.sendRequest(supportRequest);
assertNotNull(url);
assertTrue(url.contains("jwt"));
assertEquals("<html>", url.substring(0, 6));
SupportResponse response = supportServiceImpl.sendRequest(supportRequest);
assertNotNull(response);
assertNotNull(response.getJwt());
assertNotNull(response.getRedirectUrl());
assertEquals("http", response.getRedirectUrl().substring(0, 4));
}

/**
* Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)}
*/
@Test
void testSendRequestUserNotFound(){
FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig();
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null);
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", null);
SupportRequest supportRequest = this.dummySupportRequest();
supportRequest.setUserId("null");
Executable executable = () -> supportServiceImpl.sendRequest(supportRequest);
Expand All @@ -80,58 +76,31 @@ void testSendRequestUserNotFound(){
Assertions.assertEquals("User with id null not found", e.getMessage());
}

/**
* Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)}
*/
@Test
void testSendRequestThrowException() {
FreeMarkerConfigurer freeMarkerConfigurer = Mockito.mock(FreeMarkerConfigurer.class);
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null);
Exception exception = assertThrows(Exception.class, () -> supportServiceImpl.sendRequest(this.dummySupportRequest()));
assertEquals("Impossible to retrieve zendesk form template", exception.getMessage());
}

/**
* Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)}
*/
@Test
void testSendRequestWithProductId() {
FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig();
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "", "redirectUrl", freeMarkerConfigurer, null);
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "", "redirectUrl", null);
SupportRequest supportRequest = this.dummySupportRequest();
supportRequest.setProductId("prodottoDiTest");
String url = supportServiceImpl.sendRequest(supportRequest);
assertNotNull(url);
assertTrue(url.contains("jwt"));
assertTrue(url.contains(supportRequest.getProductId()));
assertEquals("<html>", url.substring(0, 6));
SupportResponse response = supportServiceImpl.sendRequest(supportRequest);
assertNotNull(response);
assertNotNull(response.getJwt());
assertNotNull(response.getRedirectUrl());
assertEquals("http", response.getRedirectUrl().substring(0, 4));
assertTrue(response.getRedirectUrl().contains(supportRequest.getProductId()));
}

/**
* Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)}
*/
@Test
void testRequestWithMalformedEmptyKey() {
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("", "", "test", "redirectUrl", null, null);
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("", "", "test", "redirectUrl", null);
SupportException exception = assertThrows(SupportException.class, () -> supportServiceImpl.sendRequest(this.dummySupportRequest()));
assertEquals("secret key byte array cannot be null or empty.", exception.getMessage());
}

/**
* Method under test: {@link SupportServiceImpl#getSupportRequest(SupportRequest)}
*/
@Test
void testGetRequestUrlWithProductId() {
FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig();
SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "", "redirectUrl", freeMarkerConfigurer, null);
SupportRequest supportRequest = this.dummySupportRequest();
supportRequest.setProductId("prodottoDiTest");
String url = supportServiceImpl.getSupportRequest(supportRequest);
assertNotNull(url);
assertTrue(url.contains("jwt"));
assertTrue(url.contains(supportRequest.getProductId()));
assertEquals("http", url.substring(0, 4));
}

private SupportRequest dummySupportRequest() {
SupportRequest supportRequest = new SupportRequest();
Expand All @@ -142,12 +111,5 @@ private SupportRequest dummySupportRequest() {
supportRequest.setUserFields(userField);
return supportRequest;
}
private FreeMarkerConfigurer freemarkerClassLoaderConfig() {
freemarker.template.Configuration configuration = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27);
TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), "/template-zendesk");
configuration.setTemplateLoader(templateLoader);
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
freeMarkerConfigurer.setConfiguration(configuration);
return freeMarkerConfigurer;
}

}
Loading

0 comments on commit 5b7003a

Please sign in to comment.