68 lines
1.7 KiB
Java
68 lines
1.7 KiB
Java
package de.tavolio.session;
|
|
|
|
import de.tavolio.account.AccountEntity;
|
|
import de.tavolio.account.AccountRepo;
|
|
import de.tavolio.utils.Database;
|
|
import io.quarkus.elytron.security.common.BcryptUtil;
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
import io.restassured.http.ContentType;
|
|
import io.restassured.response.Response;
|
|
import jakarta.inject.Inject;
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static io.restassured.RestAssured.given;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
@QuarkusTest
|
|
public class SessionResourceTest
|
|
{
|
|
@Inject
|
|
Database database;
|
|
|
|
@Inject
|
|
AccountRepo accountRepo;
|
|
|
|
@AfterEach
|
|
void afterEach()
|
|
{
|
|
database.clear();
|
|
}
|
|
|
|
@Test
|
|
void testGet()
|
|
{
|
|
// given
|
|
database.setup(() -> {
|
|
AccountEntity accountEntity = AccountEntity.init()
|
|
.setEmail("andreas.j.dinauer@gmail.com")
|
|
.setFirstname("Andreas")
|
|
.setLastname("Dinauer")
|
|
.setPassword(BcryptUtil.bcryptHash("pw"));
|
|
accountRepo.persist(accountEntity);
|
|
});
|
|
|
|
String loginRequest = """
|
|
{
|
|
"email": "andreas.j.dinauer@gmail.com",
|
|
"password": "pw"
|
|
}
|
|
""";
|
|
|
|
// when
|
|
Response response = given()
|
|
.contentType(ContentType.JSON)
|
|
.body(loginRequest)
|
|
.when()
|
|
.post("/sessions")
|
|
.then()
|
|
.extract()
|
|
.response();
|
|
|
|
// then
|
|
assertEquals(200, response.statusCode());
|
|
assertTrue(response.getBody().prettyPrint().startsWith("ey"));
|
|
}
|
|
}
|