2024-01-14 10:09:35 +00:00
|
|
|
import com.alttd.forms.contact.ContactFormData;
|
|
|
|
|
import com.alttd.forms.contact.StoreFormQuery;
|
|
|
|
|
import com.alttd.forms.database.DatabaseConnection;
|
|
|
|
|
import com.alttd.forms.form.Form;
|
|
|
|
|
import com.alttd.forms.verify_mail.FormQuery;
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
public class TestForm {
|
|
|
|
|
|
|
|
|
|
private static int code;
|
|
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
|
public static void testInsert() {
|
2024-04-28 19:25:09 +00:00
|
|
|
Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
|
2024-01-14 10:09:35 +00:00
|
|
|
StoreFormQuery storeFormQuery = new StoreFormQuery();
|
|
|
|
|
ContactFormData contactFormData = new ContactFormData("akastijn", "akastijn@alttd.com", "This is a test question.");
|
|
|
|
|
storeFormQuery.storeFormForVerificationCode("akastijn@alttd.com", contactFormData).
|
|
|
|
|
thenAccept(code -> {
|
|
|
|
|
TestForm.code = code;
|
|
|
|
|
Assertions.assertTrue(code > 999 && code < 10000);
|
|
|
|
|
})
|
|
|
|
|
.exceptionally(throwable -> Assertions.fail());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRetrieveForm() {
|
2024-04-28 19:25:09 +00:00
|
|
|
Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
|
2024-01-14 10:09:35 +00:00
|
|
|
new FormQuery().getFormForCode(String.valueOf(code), "akastijn@alttd.com").thenAccept(result -> {
|
|
|
|
|
Assertions.assertTrue(result.failReason().isEmpty());
|
|
|
|
|
Optional<Form> optionalForm = result.form();
|
|
|
|
|
Assertions.assertTrue(optionalForm.isPresent());
|
|
|
|
|
Form form = optionalForm.get();
|
|
|
|
|
Assertions.assertInstanceOf(ContactFormData.class, form);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|