Fail with an error if can't find page when creating an action

This commit is contained in:
Shrikant Kandula 2020-06-18 15:05:55 +05:30
parent 69dd082cf6
commit 1d5fa960db
2 changed files with 21 additions and 1 deletions

View File

@ -48,7 +48,6 @@ import org.springframework.util.StringUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import retrofit.http.HEAD;
import javax.lang.model.SourceVersion;
import javax.validation.Validator;
@ -143,6 +142,8 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
return pageService
.findById(action.getPageId(), READ_PAGES)
.switchIfEmpty(Mono.error(
new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "page", action.getPageId())))
.zipWith(userMono)
.flatMap(tuple -> {
Page page = tuple.getT1();

View File

@ -243,6 +243,25 @@ public class ActionServiceTest {
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void invalidCreateActionInvalidPageId() {
Action action = new Action();
action.setName("randomActionName3");
action.setPageId("invalid page id here");
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setHttpMethod(HttpMethod.GET);
action.setActionConfiguration(actionConfiguration);
Mono<Action> actionMono = Mono.just(action)
.flatMap(actionService::create);
StepVerifier
.create(actionMono)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(
AppsmithError.NO_RESOURCE_FOUND.getMessage("page", "invalid page id here")))
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void testVariableSubstitution() {