345d4c056c
Release package / release (push) Successful in 26m36s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #51
117 lines
3.0 KiB
Java
117 lines
3.0 KiB
Java
package com.drinkool.services;
|
|
|
|
import static io.restassured.RestAssured.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import com.drinkool.*;
|
|
import com.drinkool.entities.StaffEntity;
|
|
import com.drinkool.lib.dtos.*;
|
|
import io.quarkus.test.common.QuarkusTestResource;
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
import io.quarkus.test.kafka.*;
|
|
import io.restassured.http.ContentType;
|
|
import jakarta.ws.rs.core.Response;
|
|
import net.datafaker.Faker;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@QuarkusTest
|
|
@QuarkusTestResource(KafkaCompanionResource.class)
|
|
public class StaffServiceTest {
|
|
|
|
private final Faker faker = new Faker();
|
|
|
|
private String managerId;
|
|
|
|
@BeforeEach
|
|
void setup() {
|
|
ManagerSignup input = new ManagerSignup();
|
|
input.name = "Ho Van Quan";
|
|
input.phone = Utils.generateRandomPhone();
|
|
input.password = "strong_password";
|
|
input.eateryName = "Quan Com Ngon";
|
|
|
|
var response = given()
|
|
.contentType("application/json")
|
|
.body(input)
|
|
.when()
|
|
.post(Role.Manager + Url.Signup)
|
|
.then()
|
|
.statusCode(201)
|
|
.header(InternalValue.userId, org.hamcrest.Matchers.notNullValue())
|
|
.header(InternalValue.role, Role.Manager)
|
|
.extract();
|
|
|
|
managerId = response.header(InternalValue.userId);
|
|
}
|
|
|
|
@Test
|
|
void signup_Success() {
|
|
String staffName = faker.name().fullName();
|
|
String staffPhone = Utils.generateRandomPhone();
|
|
|
|
Signup signup = new Signup(
|
|
staffName,
|
|
staffPhone,
|
|
faker.famousLastWords().lastWords()
|
|
);
|
|
|
|
given()
|
|
.contentType(ContentType.JSON)
|
|
.header(InternalValue.role, Role.Manager)
|
|
.header(InternalValue.userId, managerId)
|
|
.body(signup)
|
|
.when()
|
|
.post(Role.Staff + Url.Signup)
|
|
.then()
|
|
.statusCode(Response.Status.CREATED.getStatusCode())
|
|
.header(InternalValue.userId, org.hamcrest.Matchers.notNullValue())
|
|
.header(InternalValue.role, Role.Staff);
|
|
|
|
StaffEntity staff = StaffEntity.find("phone", staffPhone).firstResult();
|
|
|
|
assertEquals(managerId, staff.serve.id.toString());
|
|
}
|
|
|
|
@Test
|
|
void signup_FailedDueToInvalidRole() {
|
|
given()
|
|
.contentType(ContentType.JSON)
|
|
.header(InternalValue.role, Role.Customer)
|
|
.header(InternalValue.userId, managerId)
|
|
.body("")
|
|
.when()
|
|
.post(Role.Staff + Url.Signup)
|
|
.then()
|
|
.statusCode(Response.Status.FORBIDDEN.getStatusCode());
|
|
}
|
|
|
|
@Test
|
|
void testLoginSuccess() {
|
|
String staffName = faker.name().fullName();
|
|
String staffPhone = Utils.generateRandomPhone();
|
|
String password = faker.famousLastWords().lastWords();
|
|
|
|
Signup signup = new Signup(staffName, staffPhone, password);
|
|
|
|
given()
|
|
.contentType(ContentType.JSON)
|
|
.header(InternalValue.role, Role.Manager)
|
|
.header(InternalValue.userId, managerId)
|
|
.body(signup)
|
|
.when()
|
|
.post(Role.Staff + Url.Signup)
|
|
.then();
|
|
|
|
Login loginInput = new Login(staffPhone, password);
|
|
|
|
given()
|
|
.contentType(ContentType.JSON)
|
|
.body(loginInput)
|
|
.when()
|
|
.post(Role.Staff + Url.Login)
|
|
.then()
|
|
.statusCode(Response.Status.ACCEPTED.getStatusCode());
|
|
}
|
|
}
|