Open platform to collect and prioritize feedback
wip
goenning6b420a7ee6dc
diff --git a/app/feedback/handler.go b/app/handlers/feedback.gosimilarity index 99%rename from app/feedback/handler.gorename to app/handlers/feedback.goindex e6e2da575..f34a346fe 100644--- a/app/feedback/handler.go+++ b/app/handlers/feedback.go@@ -1,4 +1,4 @@-package feedback+package handlersimport ("strings"diff --git a/app/feedback/handler_test.go b/app/handlers/feedback_test.gosimilarity index 87%rename from app/feedback/handler_test.gorename to app/handlers/feedback_test.goindex 8b91cc29d..8f105df37 100644--- a/app/feedback/handler_test.go+++ b/app/handlers/feedback_test.go@@ -1,10 +1,10 @@-package feedback_test+package handlers_testimport ("testing""github.com/WeCanHearYou/wechy/app"- "github.com/WeCanHearYou/wechy/app/feedback"+ "github.com/WeCanHearYou/wechy/app/handlers""github.com/WeCanHearYou/wechy/app/mock""github.com/WeCanHearYou/wechy/app/models". "github.com/onsi/gomega"@@ -62,7 +62,7 @@ func TestListHandler(t *testing.T) {server := mock.NewServer()server.Context.Set("__CTX_TENANT", &models.Tenant{ID: 2, Name: "Any Tenant"})- code, _ := server.Execute(feedback.Handlers(NewMockIdeaStorage()).List())+ code, _ := server.Execute(handlers.Handlers(NewMockIdeaStorage()).List())Expect(code).To(Equal(200))}@@ -75,7 +75,7 @@ func TestDetailsHandler(t *testing.T) {server.Context.SetParamNames("number")server.Context.SetParamValues("1")- code, _ := server.Execute(feedback.Handlers(NewMockIdeaStorage()).Details())+ code, _ := server.Execute(handlers.Handlers(NewMockIdeaStorage()).Details())Expect(code).To(Equal(200))}@@ -88,7 +88,7 @@ func TestDetailsHandler_NotFound(t *testing.T) {server.Context.SetParamNames("number")server.Context.SetParamValues("99")- code, _ := server.Execute(feedback.Handlers(NewMockIdeaStorage()).Details())+ code, _ := server.Execute(handlers.Handlers(NewMockIdeaStorage()).Details())Expect(code).To(Equal(404))}@@ -99,7 +99,7 @@ func TestDetailsHandler_AddIdea(t *testing.T) {server := mock.NewServer()server.Context.Set("__CTX_TENANT", &models.Tenant{ID: 2, Name: "Any Tenant"})server.Context.Set("__CTX_USER", &models.User{ID: 1, Name: "Jon"})- handler := feedback.Handlers(NewMockIdeaStorage()).PostIdea()+ handler := handlers.Handlers(NewMockIdeaStorage()).PostIdea()code, _ := server.ExecutePost(handler, `{ "title": "My newest idea :)" }`)Expect(code).To(Equal(200))@@ -111,7 +111,7 @@ func TestDetailsHandler_AddIdea_WithoutTitle(t *testing.T) {server := mock.NewServer()server.Context.Set("__CTX_TENANT", &models.Tenant{ID: 2, Name: "Any Tenant"})server.Context.Set("__CTX_USER", &models.User{ID: 1, Name: "Jon"})- handler := feedback.Handlers(NewMockIdeaStorage()).PostIdea()+ handler := handlers.Handlers(NewMockIdeaStorage()).PostIdea()code, _ := server.ExecutePost(handler, `{ "title": "" }`)Expect(code).To(Equal(400))@@ -125,7 +125,7 @@ func TestDetailsHandler_AddComment(t *testing.T) {server.Context.Set("__CTX_USER", &models.User{ID: 1, Name: "Jon"})server.Context.SetParamNames("id")server.Context.SetParamValues("1")- handler := feedback.Handlers(NewMockIdeaStorage()).PostComment()+ handler := handlers.Handlers(NewMockIdeaStorage()).PostComment()code, _ := server.ExecutePost(handler, `{ "content": "This is a comment!" }`)Expect(code).To(Equal(200))@@ -139,7 +139,7 @@ func TestDetailsHandler_AddComment_WithoutContent(t *testing.T) {server.Context.Set("__CTX_USER", &models.User{ID: 1, Name: "Jon"})server.Context.SetParamNames("id")server.Context.SetParamValues("1")- handler := feedback.Handlers(NewMockIdeaStorage()).PostComment()+ handler := handlers.Handlers(NewMockIdeaStorage()).PostComment()code, _ := server.ExecutePost(handler, `{ "content": "" }`)Expect(code).To(Equal(400))diff --git a/app/identity/handler.go b/app/handlers/identity.gosimilarity index 99%rename from app/identity/handler.gorename to app/handlers/identity.goindex 494710058..e66503438 100644--- a/app/identity/handler.go+++ b/app/handlers/identity.go@@ -1,4 +1,4 @@-package identity+package handlersimport ("net/http"diff --git a/app/identity/handler_test.go b/app/handlers/identity_test.gosimilarity index 88%rename from app/identity/handler_test.gorename to app/handlers/identity_test.goindex f63b289b3..c32855d38 100644--- a/app/identity/handler_test.go+++ b/app/handlers/identity_test.go@@ -1,4 +1,4 @@-package identity_test+package handlers_testimport ("testing"@@ -7,10 +7,10 @@ import ("net/url"- "github.com/WeCanHearYou/wechy/app/identity"+ "github.com/WeCanHearYou/wechy/app/handlers""github.com/WeCanHearYou/wechy/app/mock"- "github.com/WeCanHearYou/wechy/app/pkg/oauth""github.com/WeCanHearYou/wechy/app/pkg/dbx"+ "github.com/WeCanHearYou/wechy/app/pkg/oauth""github.com/WeCanHearYou/wechy/app/storage/postgres". "github.com/onsi/gomega")@@ -67,16 +67,16 @@ func (p *OAuthService) GetProfile(provider string, code string) (*oauth.UserProfreturn nil, nil}-func handlers() identity.OAuthHandlers {+func getHandlers() handlers.OAuthHandlers {setup()- return identity.OAuth(TenantStorage, oauthService, UserStorage)+ return handlers.OAuth(TenantStorage, oauthService, UserStorage)}func TestLoginHandler(t *testing.T) {RegisterTestingT(t)server := mock.NewServer()- code, response := server.ExecuteRaw(handlers().Login(oauth.FacebookProvider))+ code, response := server.ExecuteRaw(getHandlers().Login(oauth.FacebookProvider))Expect(code).To(Equal(http.StatusTemporaryRedirect))Expect(response.Header.Get("Location")).To(Equal("http://orange.test.canherayou.com/oauth/token?provider=facebook&redirect="))@@ -87,7 +87,7 @@ func TestCallbackHandler_InvalidState(t *testing.T) {server := mock.NewServer()server.Context.Request().URL, _ = url.Parse("http://login.test.canherayou.com/oauth/callback?state=abc")- code, _ := server.ExecuteRaw(handlers().Callback(oauth.FacebookProvider))+ code, _ := server.ExecuteRaw(getHandlers().Callback(oauth.FacebookProvider))Expect(code).To(Equal(http.StatusInternalServerError))}@@ -97,7 +97,7 @@ func TestCallbackHandler_InvalidCode(t *testing.T) {server := mock.NewServer()server.Context.Request().URL, _ = url.Parse("http://login.test.canherayou.com/oauth/callback?state=http://orange.test.canhearyou.com")- code, response := server.ExecuteRaw(handlers().Callback(oauth.FacebookProvider))+ code, response := server.ExecuteRaw(getHandlers().Callback(oauth.FacebookProvider))Expect(code).To(Equal(http.StatusTemporaryRedirect))Expect(response.Header.Get("Location")).To(Equal("http://orange.test.canhearyou.com"))@@ -108,7 +108,7 @@ func TestCallbackHandler_ExistingUserAndProvider(t *testing.T) {server := mock.NewServer()server.Context.Request().URL, _ = url.Parse("http://demo.test.canherayou.com/oauth/callback?state=http://demo.test.canhearyou.com&code=123")- code, response := server.ExecuteRaw(handlers().Callback(oauth.FacebookProvider))+ code, response := server.ExecuteRaw(getHandlers().Callback(oauth.FacebookProvider))Expect(db.Count("SELECT id FROM users WHERE email = '[email protected]'")).To(Equal(1))@@ -121,7 +121,7 @@ func TestCallbackHandler_NewUser(t *testing.T) {server := mock.NewServer()server.Context.Request().URL, _ = url.Parse("http://login.test.canherayou.com/oauth/callback?state=http://orange.test.canhearyou.com&code=456")- code, response := server.ExecuteRaw(handlers().Callback(oauth.FacebookProvider))+ code, response := server.ExecuteRaw(getHandlers().Callback(oauth.FacebookProvider))Expect(db.QueryInt("SELECT tenant_id FROM users WHERE email = '[email protected]'")).To(Equal(400))Expect(db.Exists("SELECT * FROM user_providers WHERE provider_uid = 'FB5678'")).To(BeTrue())@@ -135,7 +135,7 @@ func TestCallbackHandler_ExistingUser_NewProvider(t *testing.T) {server := mock.NewServer()server.Context.Request().URL, _ = url.Parse("http://login.test.canherayou.com/oauth/callback?state=http://demo.test.canhearyou.com&code=123")- code, response := server.ExecuteRaw(handlers().Callback(oauth.GoogleProvider))+ code, response := server.ExecuteRaw(getHandlers().Callback(oauth.GoogleProvider))Expect(db.Count("SELECT id FROM users WHERE email = '[email protected]'")).To(Equal(1))Expect(db.QueryString("SELECT provider_uid FROM user_providers WHERE user_id = 300 and provider = 'facebook'")).To(Equal("FB1234"))diff --git a/app/infra/handler.go b/app/handlers/status.gosimilarity index 97%rename from app/infra/handler.gorename to app/handlers/status.goindex 5691ef63d..7e425e5ce 100644--- a/app/infra/handler.go+++ b/app/handlers/status.go@@ -1,4 +1,4 @@-package infra+package handlersimport ("net/http"diff --git a/app/infra/handler_test.go b/app/handlers/status_test.gosimilarity index 74%rename from app/infra/handler_test.gorename to app/handlers/status_test.goindex 7c49a29af..42cfe3af7 100644--- a/app/infra/handler_test.go+++ b/app/handlers/status_test.go@@ -1,9 +1,9 @@-package infra_test+package handlers_testimport ("testing"- "github.com/WeCanHearYou/wechy/app/infra"+ "github.com/WeCanHearYou/wechy/app/handlers""github.com/WeCanHearYou/wechy/app/mock""github.com/WeCanHearYou/wechy/app/models". "github.com/onsi/gomega"@@ -17,7 +17,7 @@ func TestStatusHandler(t *testing.T) {}server := mock.NewServer()- status, query := server.Execute(infra.Status(settings))+ status, query := server.Execute(handlers.Status(settings))Expect(query.String("build")).To(Equal("today"))Expect(status).To(Equal(200))diff --git a/router.go b/router.goindex 1f62f9be3..c4f74e60a 100644--- a/router.go+++ b/router.go@@ -6,13 +6,11 @@ import ("strings""github.com/WeCanHearYou/wechy/app"- "github.com/WeCanHearYou/wechy/app/feedback"- "github.com/WeCanHearYou/wechy/app/identity"- "github.com/WeCanHearYou/wechy/app/infra"+ "github.com/WeCanHearYou/wechy/app/handlers""github.com/WeCanHearYou/wechy/app/middlewares""github.com/WeCanHearYou/wechy/app/models"- "github.com/WeCanHearYou/wechy/app/pkg/oauth""github.com/WeCanHearYou/wechy/app/pkg/env"+ "github.com/WeCanHearYou/wechy/app/pkg/oauth""github.com/WeCanHearYou/wechy/app/storage""github.com/labstack/echo""github.com/labstack/echo/middleware"@@ -98,7 +96,7 @@ func GetMainEngine(ctx *WechyServices) *echo.Echo {assetsGroup.Static("/", "dist")}- oauthHandlers := identity.OAuth(ctx.Tenant, ctx.OAuth, ctx.User)+ oauthHandlers := handlers.OAuth(ctx.Tenant, ctx.OAuth, ctx.User)authGroup := group(router, "/oauth"){use(authGroup, middlewares.HostChecker(env.MustGet("AUTH_ENDPOINT")))@@ -115,10 +113,10 @@ func GetMainEngine(ctx *WechyServices) *echo.Echo {use(appGroup, middlewares.JwtGetter(ctx.User))use(appGroup, middlewares.JwtSetter())- get(appGroup, "/", feedback.Handlers(ctx.Idea).List())- get(appGroup, "/ideas/:number", feedback.Handlers(ctx.Idea).Details())+ get(appGroup, "/", handlers.Handlers(ctx.Idea).List())+ get(appGroup, "/ideas/:number", handlers.Handlers(ctx.Idea).Details())get(appGroup, "/logout", oauthHandlers.Logout())- get(appGroup, "/api/status", infra.Status(ctx.Settings))+ get(appGroup, "/api/status", handlers.Status(ctx.Settings))}securedGroup := group(router, "/api")@@ -128,8 +126,8 @@ func GetMainEngine(ctx *WechyServices) *echo.Echo {use(securedGroup, middlewares.JwtSetter())use(securedGroup, middlewares.IsAuthenticated())- post(securedGroup, "/ideas", feedback.Handlers(ctx.Idea).PostIdea())- post(securedGroup, "/ideas/:id/comments", feedback.Handlers(ctx.Idea).PostComment())+ post(securedGroup, "/ideas", handlers.Handlers(ctx.Idea).PostIdea())+ post(securedGroup, "/ideas/:id/comments", handlers.Handlers(ctx.Idea).PostComment())}adminGroup := group(router, "/admin")