-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mailing): added tests to check if mailing works when disabled an…
…d enabled
- Loading branch information
1 parent
9748e94
commit d61575a
Showing
7 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/dev/cloudeko/zenei/application/web/model/response/EmailAddressResponse.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dev.cloudeko.zenei.application.web.model.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import dev.cloudeko.zenei.domain.model.email.EmailAddress; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RegisterForReflection | ||
@Schema(name = "EmailAddress", description = "Represents an email address") | ||
public class EmailAddressResponse { | ||
|
||
@JsonProperty("email") | ||
@Schema(description = "Email address") | ||
private String email; | ||
|
||
@JsonProperty("email_verified") | ||
@Schema(description = "Whether the email address has been verified") | ||
private Boolean emailVerified; | ||
|
||
@JsonProperty("created_at") | ||
@Schema(description = "Timestamp when the email address was created") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") | ||
private LocalDateTime createdAt; | ||
|
||
@JsonProperty("updated_at") | ||
@Schema(description = "Timestamp when the email address was last updated") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") | ||
private LocalDateTime updatedAt; | ||
|
||
public EmailAddressResponse(EmailAddress emailAddress) { | ||
this.email = emailAddress.getEmail(); | ||
this.emailVerified = emailAddress.getEmailVerified(); | ||
this.createdAt = emailAddress.getCreatedAt(); | ||
this.updatedAt = emailAddress.getUpdatedAt(); | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
src/test/java/dev/cloudeko/zenei/auth/AuthenticationFlowWithDisabledMailingTest.java
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.cloudeko.zenei.auth; | ||
|
||
import dev.cloudeko.zenei.application.web.model.response.TokenResponse; | ||
import dev.cloudeko.zenei.profile.MailingDisabledProfile; | ||
import io.quarkus.mailer.MockMailbox; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.restassured.RestAssured; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.*; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@QuarkusTest | ||
@TestProfile(MailingDisabledProfile.class) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class AuthenticationFlowWithDisabledMailingTest { | ||
|
||
@ConfigProperty(name = "quarkus.http.test-port") | ||
int quarkusPort; | ||
|
||
@Inject | ||
MockMailbox mailbox; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
@DisplayName("Create user via email and password (POST /user) should return (200 OK)") | ||
void testCreateUser() { | ||
given() | ||
.contentType(MediaType.APPLICATION_FORM_URLENCODED) | ||
.formParam("username", "test-user2") | ||
.formParam("email", "[email protected]") | ||
.formParam("password", "test-password") | ||
.formParam("strategy", "PASSWORD") | ||
.post("/user") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.body( | ||
"id", notNullValue(), | ||
"username", notNullValue(), | ||
"primary_email_address", notNullValue() | ||
); | ||
|
||
assertEquals(0, mailbox.getTotalMessagesSent()); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("Retrieve user information (GET /user) should return (200 OK)") | ||
void testGetUserInfo() { | ||
final var token = given() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.queryParam("grant_type", "password") | ||
.queryParam("username", "[email protected]") | ||
.queryParam("password", "test-password") | ||
.post("/user/token") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.extract().as(TokenResponse.class); | ||
|
||
given() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer " + token.getAccessToken()) | ||
.get("/user") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()) | ||
.body( | ||
"id", notNullValue(), | ||
"username", notNullValue(), | ||
"primary_email_address", notNullValue(), | ||
"email_addresses", notNullValue(), | ||
"email_addresses.size()", greaterThanOrEqualTo(1), | ||
"email_addresses.getFirst().email_verified", equalTo(true) | ||
); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/test/java/dev/cloudeko/zenei/profile/MailingDisabledProfile.java
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.cloudeko.zenei.profile; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
import java.util.Map; | ||
|
||
public class MailingDisabledProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of("quarkus.mailer.mock", "false", "zenei.mailer.auto-confirm", "true"); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/dev/cloudeko/zenei/profile/MailingEnabledProfile.java
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.cloudeko.zenei.profile; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class MailingEnabledProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Collections.singletonMap("quarkus.mailer.mock", "true"); | ||
} | ||
} |