Skip to content

Commit

Permalink
enhancement(test): enhanced tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Jul 31, 2023
1 parent 1fa7af2 commit 893688c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions server/src/test/java/dev/shiperist/AuthResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
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;
Expand All @@ -23,7 +20,10 @@ class AuthResourceTest {
@BeforeEach
public void setUp() {
user = Instancio.of(User.class)
.generate(field(User::getName, gen -> gen.name().fullName()))
.generate(field(User::getName), gen -> gen.text().uuid())
.generate(field(User::getEmail), gen -> gen.text().pattern("[a-z]{5}@test.com"))
.generate(field(User::getImage), gen -> gen.net().url())
.generate(field(User::getPassword), gen -> gen.text().uuid())
.create();
}

Expand All @@ -38,29 +38,29 @@ public void testGetSettings() {
public void testSignUp() {
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()));
}

@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())
.formParam("email", user.getEmail())
.formParam("password", user.getPassword())
.when().post("/auth/token")
.then().statusCode(200)
.body("accessToken", notNullValue(),
Expand Down

0 comments on commit 893688c

Please sign in to comment.