2022-10-31 10:49:21 +00:00
|
|
|
package api_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-04-21 06:49:17 +00:00
|
|
|
"github.com/reiver/greatape/components/api/handlers"
|
|
|
|
"github.com/reiver/greatape/components/api/operations"
|
|
|
|
. "github.com/reiver/greatape/components/api/protobuf"
|
|
|
|
"github.com/reiver/greatape/components/constants"
|
|
|
|
. "github.com/reiver/greatape/components/contracts"
|
|
|
|
"github.com/reiver/greatape/components/core"
|
|
|
|
"github.com/reiver/greatape/components/model/repository"
|
|
|
|
"github.com/reiver/greatape/providers/outbound/email"
|
|
|
|
"github.com/reiver/greatape/providers/outbound/sms"
|
2022-10-31 10:49:21 +00:00
|
|
|
"github.com/xeronith/diamante/analytics"
|
|
|
|
"github.com/xeronith/diamante/logging"
|
|
|
|
"github.com/xeronith/diamante/server"
|
|
|
|
"github.com/xeronith/diamante/settings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var api IApi
|
|
|
|
|
|
|
|
func TestReloadSystemComponentApi(test *testing.T) {
|
|
|
|
input := &SystemCallRequest{
|
|
|
|
Command: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.SystemCall(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEchoApi(test *testing.T) {
|
|
|
|
input := &EchoRequest{
|
|
|
|
Document: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.Echo(input); err != nil {
|
2023-05-29 10:37:31 +00:00
|
|
|
test.Fatal(err)
|
2023-06-23 11:22:07 +00:00
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetServerConfigurationApi(test *testing.T) {
|
|
|
|
input := &GetServerConfigurationRequest{}
|
|
|
|
|
|
|
|
if output, err := api.GetServerConfiguration(input); err != nil {
|
|
|
|
test.Fatal(err)
|
2023-05-29 10:37:31 +00:00
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckUsernameAvailabilityApi(test *testing.T) {
|
|
|
|
input := &CheckUsernameAvailabilityRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.CheckUsernameAvailability(input); err != nil {
|
2022-10-31 10:49:21 +00:00
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 08:45:13 +00:00
|
|
|
func TestSignupApi(test *testing.T) {
|
|
|
|
input := &SignupRequest{
|
|
|
|
Username: "username",
|
|
|
|
Email: "email",
|
|
|
|
Password: "password",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.Signup(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-19 08:03:44 +00:00
|
|
|
func TestResendVerificationCodeApi(test *testing.T) {
|
|
|
|
input := &ResendVerificationCodeRequest{
|
|
|
|
Email: "email",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.ResendVerificationCode(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 08:45:13 +00:00
|
|
|
func TestVerifyApi(test *testing.T) {
|
|
|
|
input := &VerifyRequest{
|
|
|
|
Email: "email",
|
|
|
|
Token: "token",
|
|
|
|
Code: "code",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.Verify(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoginApi(test *testing.T) {
|
|
|
|
input := &LoginRequest{
|
|
|
|
Email: "email",
|
|
|
|
Password: "password",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.Login(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 09:06:08 +00:00
|
|
|
func TestGetProfileByUserApi(test *testing.T) {
|
|
|
|
input := &GetProfileByUserRequest{}
|
|
|
|
|
|
|
|
if output, err := api.GetProfileByUser(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateProfileByUserApi(test *testing.T) {
|
|
|
|
input := &UpdateProfileByUserRequest{
|
|
|
|
DisplayName: "display_name",
|
|
|
|
Avatar: "avatar",
|
|
|
|
Banner: "banner",
|
|
|
|
Summary: "summary",
|
|
|
|
Github: "github",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.UpdateProfileByUser(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-05 08:00:06 +00:00
|
|
|
func TestChangePasswordApi(test *testing.T) {
|
|
|
|
input := &ChangePasswordRequest{
|
|
|
|
CurrentPassword: "current_password",
|
|
|
|
NewPassword: "new_password",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.ChangePassword(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 07:12:37 +00:00
|
|
|
func TestResetPasswordApi(test *testing.T) {
|
|
|
|
input := &ResetPasswordRequest{
|
|
|
|
UsernameOrEmail: "username_or_email",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.ResetPassword(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 07:55:48 +00:00
|
|
|
func TestLogoutApi(test *testing.T) {
|
|
|
|
input := &LogoutRequest{}
|
|
|
|
|
|
|
|
if output, err := api.Logout(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:15:22 +00:00
|
|
|
func TestWebfingerApi(test *testing.T) {
|
|
|
|
input := &WebfingerRequest{
|
|
|
|
Resource: "resource",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.Webfinger(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 17:50:08 +00:00
|
|
|
func TestGetPackagesApi(test *testing.T) {
|
|
|
|
input := &GetPackagesRequest{}
|
|
|
|
|
|
|
|
if output, err := api.GetPackages(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 08:29:01 +00:00
|
|
|
func TestGetActorApi(test *testing.T) {
|
|
|
|
input := &GetActorRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.GetActor(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 18:37:39 +00:00
|
|
|
func TestFollowActorApi(test *testing.T) {
|
|
|
|
input := &FollowActorRequest{
|
|
|
|
Username: "username",
|
|
|
|
Acct: "acct",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.FollowActor(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 08:20:35 +00:00
|
|
|
func TestAuthorizeInteractionApi(test *testing.T) {
|
|
|
|
input := &AuthorizeInteractionRequest{
|
|
|
|
Uri: "uri",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.AuthorizeInteraction(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 18:42:31 +00:00
|
|
|
func TestGetFollowersApi(test *testing.T) {
|
|
|
|
input := &GetFollowersRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.GetFollowers(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 16:17:16 +00:00
|
|
|
func TestGetFollowingApi(test *testing.T) {
|
|
|
|
input := &GetFollowingRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.GetFollowing(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 15:14:08 +00:00
|
|
|
func TestPostToOutboxApi(test *testing.T) {
|
|
|
|
input := &PostToOutboxRequest{
|
2023-05-03 18:24:05 +00:00
|
|
|
Username: "username",
|
|
|
|
Body: nil,
|
2022-12-15 15:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.PostToOutbox(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 13:20:59 +00:00
|
|
|
func TestGetOutboxApi(test *testing.T) {
|
|
|
|
input := &GetOutboxRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.GetOutbox(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-22 16:47:52 +00:00
|
|
|
func TestPostToInboxApi(test *testing.T) {
|
|
|
|
input := &PostToInboxRequest{
|
|
|
|
Username: "username",
|
2023-05-03 18:24:05 +00:00
|
|
|
Body: nil,
|
2022-12-22 16:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.PostToInbox(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 09:53:13 +00:00
|
|
|
func TestGetInboxApi(test *testing.T) {
|
|
|
|
input := &GetInboxRequest{
|
|
|
|
Username: "username",
|
|
|
|
}
|
|
|
|
|
|
|
|
if output, err := api.GetInbox(input); err != nil {
|
|
|
|
test.Fatal(err)
|
|
|
|
} else if output == nil {
|
|
|
|
test.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 10:49:21 +00:00
|
|
|
//region Initialization
|
|
|
|
|
|
|
|
func TestMain(main *testing.M) {
|
|
|
|
logger := logging.NewLogger(false)
|
|
|
|
configuration := settings.NewTestConfiguration()
|
|
|
|
operationsFactory := operations.NewFactory()
|
|
|
|
handlersFactory := handlers.NewFactory()
|
|
|
|
measurementsProvider := analytics.NewInfluxDbProvider(configuration, logger)
|
|
|
|
emailProvider := email.NewProvider(logger)
|
|
|
|
smsProvider := sms.NewProvider(logger)
|
|
|
|
|
2023-06-26 07:58:16 +00:00
|
|
|
if testServer, err := server.New(configuration, operationsFactory, handlersFactory); err != nil {
|
2022-10-31 10:49:21 +00:00
|
|
|
logger.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := repository.Initialize(configuration, logger); err != nil {
|
|
|
|
logger.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := core.Initialize(configuration, logger); err != nil {
|
|
|
|
logger.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testServer.Localizer().Register(constants.Errors)
|
|
|
|
testServer.SetSecurityHandler(core.Conductor.IdentityManager())
|
|
|
|
testServer.SetMeasurementsProvider(measurementsProvider)
|
|
|
|
testServer.SetEmailProvider(emailProvider)
|
|
|
|
testServer.SetSMSProvider(smsProvider)
|
|
|
|
|
|
|
|
go testServer.Start()
|
|
|
|
|
|
|
|
api = core.NewApi(testServer.PassiveEndpoint(), logger)
|
|
|
|
os.Exit(main.Run())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|