tsk-51: Send message endpoint (#52)
Closes #51 Reviewed-on: phoenix/textsender-api#52 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
+19
-12
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
||||
"git.kundeng.us/phoenix/textsender-api/internal/db"
|
||||
"git.kundeng.us/phoenix/textsender-api/internal/handler"
|
||||
@@ -24,7 +26,7 @@ import (
|
||||
var testRouter *chi.Mux
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
cfg := load()
|
||||
cfg, apiApp := load()
|
||||
|
||||
database, err := db.NewDatabase(cfg.GetDBConnString())
|
||||
if err != nil {
|
||||
@@ -60,12 +62,12 @@ func TestMain(m *testing.M) {
|
||||
schMsgEventStore := store.NewScheduledMessageEventStore(db.Pool)
|
||||
merStore := store.NewMessageEventResponseStore(db.Pool)
|
||||
|
||||
contactHandler := handler.NewContactHandler(contactStore)
|
||||
messageHandler := handler.NewMessageHandler(messageStore)
|
||||
scheduledMessageHandler := handler.NewScheduledMessageHandler(schStore)
|
||||
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(schMsgEventStore, schStore)
|
||||
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(schMsgEventStore, schStore)
|
||||
eventHandler := handler.NewEventResponseHandler(merStore)
|
||||
contactHandler := handler.NewContactHandler(apiApp, contactStore)
|
||||
messageHandler := handler.NewMessageHandler(apiApp, messageStore)
|
||||
scheduledMessageHandler := handler.NewScheduledMessageHandler(apiApp, schStore)
|
||||
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(apiApp, schMsgEventStore, schStore)
|
||||
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(apiApp, schMsgEventStore, schStore)
|
||||
eventHandler := handler.NewEventResponseHandler(apiApp, merStore)
|
||||
|
||||
testRouter = chi.NewRouter()
|
||||
testRouter.Handle(endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
|
||||
@@ -84,7 +86,7 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func load() *config.Config {
|
||||
func load() (*config.Config, *app.App) {
|
||||
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
||||
port := flag.String("port", config.PORT, "Server port")
|
||||
flag.Parse()
|
||||
@@ -103,10 +105,15 @@ func load() *config.Config {
|
||||
unpackedConnString := config.UnpackDBConnString()
|
||||
dbConnString := unpackedConnString.Parse()
|
||||
|
||||
return &config.Config{
|
||||
DBConnString: dbConnString,
|
||||
ServerPort: *port,
|
||||
ResetDB: *resetDb,
|
||||
if tCfg, err := config.TwilioConfig(); err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
return nil, nil
|
||||
} else {
|
||||
return &config.Config{
|
||||
DBConnString: dbConnString,
|
||||
ServerPort: *port,
|
||||
ResetDB: *resetDb,
|
||||
}, &app.App{TwilioConfig: tCfg}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user