-
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): started working on unit tests
- Loading branch information
1 parent
42326ba
commit 1fa7af2
Showing
4 changed files
with
50 additions
and
14 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
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 |
---|---|---|
|
@@ -3,14 +3,30 @@ | |
import dev.shiperist.model.account.User; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import org.instancio.Instancio; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.instancio.Select.field; | ||
|
||
@QuarkusTest | ||
class AuthResourceTest { | ||
|
||
private User user; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
user = Instancio.of(User.class) | ||
.generate(field(User::getName, gen -> gen.name().fullName())) | ||
.create(); | ||
} | ||
|
||
@Test | ||
public void testGetSettings() { | ||
given() | ||
|
@@ -20,19 +36,36 @@ public void testGetSettings() { | |
|
||
@Test | ||
public void testSignUp() { | ||
User user = new User(); | ||
user.setName("test"); | ||
user.setEmail("[email protected]"); | ||
user.setImage("testImage"); | ||
user.setPassword("testPassword"); | ||
given() | ||
.contentType(ContentType.JSON) | ||
.body(USER) | ||
.when().post("/auth/signup") | ||
.then().statusCode(200) | ||
.body("name", equalTo(USER.getName()), | ||
"email", equalTo(USER.getEmail()), | ||
"image", equalTo(USER.getImage())); | ||
} | ||
|
||
@Test | ||
public void testToken() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.body(user) | ||
.body(USER) | ||
.when().post("/auth/signup") | ||
.then().statusCode(200) | ||
.body("name", equalTo(user.getName()), | ||
"email", equalTo(user.getEmail()), | ||
"image", equalTo(user.getImage())); | ||
.body("name", equalTo(USER.getName()), | ||
"email", equalTo(USER.getEmail()), | ||
"image", equalTo(USER.getImage())); | ||
|
||
given() | ||
.formParam("grant_type", "password") | ||
.formParam("email", USER.getEmail()) | ||
.formParam("password", USER.getPassword()) | ||
.when().post("/auth/token") | ||
.then().statusCode(200) | ||
.body("accessToken", notNullValue(), | ||
"tokenType", equalTo("bearer"), | ||
"expiresIn", notNullValue(), | ||
"refreshToken", notNullValue()); | ||
} | ||
} |