@@ 1,6 1,7 @@
package core_test
import (
+ "database/sql"
"links/cmd"
"links/core"
"links/models"
@@ 28,6 29,11 @@ func TestHandlers(t *testing.T) {
defer srv.Shutdown()
go srv.Run()
dbCtx := cmd.NewDBContext(srv.DB, "America/Managua")
+ domains, err := models.GetDomains(dbCtx, &database.FilterOptions{
+ Filter: sq.Expr("d.service = ?", models.DomainServiceList),
+ Limit: 1,
+ })
+ c.NoError(err)
t.Run("home link list", func(t *testing.T) {
httpmock.Activate()
@@ 44,15 50,7 @@ func TestHandlers(t *testing.T) {
User: loggedInUser,
}
ctx.SetPath("/home")
- err = cmd.MakeRequestWithMW(srv, coreService.OrgLinksList, ctx, func() echo.MiddlewareFunc {
- return func(next echo.HandlerFunc) echo.HandlerFunc {
- return func(c echo.Context) error {
- gctx := c.(*server.Context)
- gctx.Server.Session.Put(c.Request().Context(), "organization.Slug", "personal-org")
- return next(gctx)
- }
- }
- })
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinksList, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "Link one"))
@@ 74,7 72,7 @@ func TestHandlers(t *testing.T) {
User: cmd.NewTestUser(1, false, false, false, false), // No aunthenticated
}
ctx.SetPath("/recent")
- err = cmd.MakeRequest(srv, coreService.OrgLinksList, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinksList, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "Link one"))
@@ 104,7 102,7 @@ func TestHandlers(t *testing.T) {
}
ctx.SetPath("/add")
// We get the error from the API call
- err = cmd.MakeRequest(srv, coreService.OrgLinksCreate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinksCreate, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "Invalid URL"))
@@ 132,7 130,7 @@ func TestHandlers(t *testing.T) {
}
ctx.SetPath("/add")
// We get the error from the API call
- err = cmd.MakeRequest(srv, coreService.OrgLinksCreate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinksCreate, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 144,7 142,7 @@ func TestHandlers(t *testing.T) {
orgLink := &models.OrgLink{
Title: "link",
URL: "http://foo.com",
- BaseURLID: baseURL.ID,
+ BaseURLID: sql.NullInt64{Int64: int64(baseURL.ID), Valid: true},
OrgID: 1,
UserID: 1,
Visibility: models.OrgLinkVisibilityPublic,
@@ 176,7 174,7 @@ func TestHandlers(t *testing.T) {
ctx.SetParamNames("id")
ctx.SetParamValues(strconv.Itoa(orgLink.ID))
// We get the error from the API call
- err = cmd.MakeRequest(srv, coreService.OrgLinkUpdate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinkUpdate, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "Invalid URL"))
@@ 211,7 209,7 @@ func TestHandlers(t *testing.T) {
ctx.SetParamNames("id")
ctx.SetParamValues(strconv.Itoa(orgLink.ID))
// We get the error from the API call
- err = cmd.MakeRequest(srv, coreService.OrgLinkUpdate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinkUpdate, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 235,7 233,7 @@ func TestHandlers(t *testing.T) {
ctx.SetParamNames("id")
ctx.SetParamValues("1")
// We get the error from the API call
- err = cmd.MakeRequest(srv, coreService.OrgLinkDetail, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinkDetail, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "https://www.detail.org"))
@@ 259,7 257,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/link/:id/delete")
ctx.SetParamNames("id")
ctx.SetParamValues("1")
- err = cmd.MakeRequest(srv, coreService.OrgLinkDelete, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.OrgLinkDelete, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 286,7 284,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/:slug/domains/add")
ctx.SetParamNames("slug")
ctx.SetParamValues("personal-org")
- err = cmd.MakeRequest(srv, coreService.DomainCreate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.DomainCreate, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 313,7 311,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/:slug/domains/add")
ctx.SetParamNames("slug")
ctx.SetParamValues("personal-org")
- err = cmd.MakeRequest(srv, coreService.DomainCreate, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.DomainCreate, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "error"))
@@ 336,7 334,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/:slug/domains")
ctx.SetParamNames("slug")
ctx.SetParamValues("personal-org")
- err = cmd.MakeRequest(srv, coreService.DomainList, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.DomainList, ctx, domains[0])
c.NoError(err)
htmlBody := recorder.Body.String()
c.True(strings.Contains(htmlBody, "Domain one"))
@@ 361,7 359,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/:slug/domains/:id/delete")
ctx.SetParamNames("slug", "id")
ctx.SetParamValues("personal-org", "1")
- err = cmd.MakeRequest(srv, coreService.DomainDelete, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.DomainDelete, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 384,7 382,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/:slug/domains/:id/delete")
ctx.SetParamNames("slug", "id")
ctx.SetParamValues("personal-org", "1")
- err = cmd.MakeRequest(srv, coreService.DomainDelete, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.DomainDelete, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 406,7 404,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/q/:hash")
ctx.SetParamNames("hash")
ctx.SetParamValues("ab10")
- err = cmd.MakeRequest(srv, coreService.QRRedirect, ctx)
+ err = cmd.MakeRequestWithDomain(srv, coreService.QRRedirect, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 428,15 426,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/qr/:hash/detail")
ctx.SetParamNames("hash")
ctx.SetParamValues("ab10")
- err = cmd.MakeRequestWithMW(srv, coreService.QRManageDetail, ctx, func() echo.MiddlewareFunc {
- return func(next echo.HandlerFunc) echo.HandlerFunc {
- return func(c echo.Context) error {
- gctx := c.(*server.Context)
- gctx.Server.Session.Put(c.Request().Context(), "organization.Slug", "personal-org")
- return next(gctx)
- }
- }
- })
+ err = cmd.MakeRequestWithDomain(srv, coreService.QRManageDetail, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
htmlBody := recorder.Body.String()
@@ 462,15 452,7 @@ func TestHandlers(t *testing.T) {
ctx.SetPath("/qr/:id/delete")
ctx.SetParamNames("id")
ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, coreService.QRManageDelete, ctx, func() echo.MiddlewareFunc {
- return func(next echo.HandlerFunc) echo.HandlerFunc {
- return func(c echo.Context) error {
- gctx := c.(*server.Context)
- gctx.Server.Session.Put(c.Request().Context(), "organization.Slug", "personal-org")
- return next(gctx)
- }
- }
- })
+ err = cmd.MakeRequestWithDomain(srv, coreService.QRManageDelete, ctx, domains[0])
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})