Skip to content

Commit

Permalink
enhancements(test): started working on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Jul 31, 2023
1 parent 42326ba commit 1fa7af2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
6 changes: 6 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.instancio</groupId>
<artifactId>instancio-junit</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.Date;

@Data
@Entity(name = "Account")
@Table(name = "account", schema = "public")
@Entity(name = "ProjectApp")
@Table(name = "project_app", schema = "public")
@EqualsAndHashCode(callSuper = true)
public class ProjectAppEntity extends PanacheEntityBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class ProjectEntity extends PanacheEntityBase {
@OneToMany(mappedBy = "project", fetch = FetchType.EAGER)
private Set<ProjectMemberEntity> members;

@ManyToMany(mappedBy = "projects")
private Set<UserEntity> users;

@OneToMany(mappedBy = "project", fetch = FetchType.EAGER)
private Set<ProjectAppEntity> projectApps;
}
51 changes: 42 additions & 9 deletions server/src/test/java/dev/shiperist/AuthResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
}
}

0 comments on commit 1fa7af2

Please sign in to comment.