-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancements(test): Improve UserResourceTest and add JSONB dependency.
- Loading branch information
1 parent
7cb004a
commit 733a3e1
Showing
2 changed files
with
23 additions
and
13 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
32 changes: 19 additions & 13 deletions
32
server/src/test/java/dev/shiperist/user/resource/UserResourceTest.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 |
---|---|---|
@@ -1,29 +1,35 @@ | ||
package dev.shiperist.user.resource; | ||
|
||
import dev.shiperist.user.model.request.CreateUserRequest; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@QuarkusTest | ||
public class UserResourceTest { | ||
|
||
private Jsonb jsonb = JsonbBuilder.create(); | ||
|
||
@Test | ||
void createUser() { | ||
String userCreateRequest = """ | ||
{ | ||
"name": "test", | ||
"email": "[email protected]", | ||
"isEmailVerified": true, | ||
"image": "test" | ||
} | ||
"""; | ||
public void testCreateUserEndpoint() { | ||
CreateUserRequest request = new CreateUserRequest(); | ||
request.setName("Test User"); | ||
request.setEmail("[email protected]"); | ||
request.setIsEmailVerified(LocalDateTime.now()); | ||
request.setImage("http://example.com/image.jpg"); | ||
|
||
String requestBody = jsonb.toJson(request); | ||
|
||
given() | ||
.when() | ||
.body(userCreateRequest) | ||
.post("/user/create") | ||
.body(requestBody) | ||
.header("Content-Type", ContentType.JSON) | ||
.when().post("/create") | ||
.then() | ||
.statusCode(200); | ||
.statusCode(200) | ||
.body("name", is(request.getName())) | ||
.body("email", is(request.getEmail())); | ||
} | ||
} |