-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returning validation failures while creating organization (#1084)
* Returning validation failures while creating organization * Added unit tests * Changing the name of test security config Co-authored-by: nitesh261193 <[email protected]>
- Loading branch information
1 parent
e85d5ed
commit 67ef538
Showing
5 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../appsmith-server/src/test/java/com/appsmith/server/configurations/SecurityTestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.appsmith.server.configurations; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; | ||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; | ||
import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
import org.springframework.security.web.server.SecurityWebFilterChain; | ||
|
||
@EnableWebFluxSecurity | ||
@EnableReactiveMethodSecurity | ||
public class SecurityTestConfig { | ||
|
||
@Bean | ||
public SecurityWebFilterChain testSecurityWebFilterChain(ServerHttpSecurity http){ | ||
return http.csrf().disable().build(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...mith-server/src/test/java/com/appsmith/server/controllers/OrganizationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.appsmith.server.controllers; | ||
|
||
import com.appsmith.server.configurations.CommonConfig; | ||
import com.appsmith.server.configurations.SecurityTestConfig; | ||
import com.appsmith.server.services.OrganizationService; | ||
import com.appsmith.server.services.UserOrganizationService; | ||
import com.appsmith.server.services.UserService; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
|
||
@RunWith(SpringRunner.class) | ||
@WebFluxTest(OrganizationController.class) | ||
@Import(SecurityTestConfig.class) | ||
public class OrganizationControllerTest { | ||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
@MockBean | ||
private OrganizationService organizationService; | ||
|
||
@MockBean | ||
private UserOrganizationService userOrganizationService; | ||
|
||
@MockBean | ||
private UserService userService; | ||
|
||
@MockBean | ||
private CommonConfig commonConfig; | ||
|
||
@Test | ||
@WithMockUser | ||
public void getOrganizationNoName() { | ||
webTestClient.post().uri("/api/v1/organizations"). | ||
contentType(MediaType.APPLICATION_JSON). | ||
body(BodyInserters.fromValue("{}")). | ||
exchange(). | ||
expectStatus().isEqualTo(400). | ||
expectBody().json("{\n" + | ||
" \"responseMeta\": {\n" + | ||
" \"status\": 400,\n" + | ||
" \"success\": false,\n" + | ||
" \"error\": {\n" + | ||
" \"code\": 4028,\n" + | ||
" \"message\": \"Validation Failure(s): {name=Name is mandatory}\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"); | ||
} | ||
} |