M api/api_test.go => api/api_test.go +30 -12
@@ 140,15 140,18 @@ func TestDirective(t *testing.T) {
}
var resultAddLink GraphQLResponseAddLink
- q = `mutation AddLink($title: String!, $url: String!, $visibility: Int!,
- $slug: String!, $tags: String, $unread: Boolean!, $starred: Boolean!) {
+ q = `mutation AddLink($title: String!, $url: String!, $description: String,
+ $visibility: Int!, $unread: Boolean!, $starred: Boolean!,
+ $archive: Boolean! $slug: String!, $tags: String) {
addLink(input: {
title: $title,
url: $url,
+ description: $description,
visibility: $visibility,
- orgSlug: $slug,
unread: $unread,
starred: $starred,
+ archive: $archive,
+ orgSlug: $slug,
tags: $tags}) {
id
}
@@ 161,6 164,7 @@ func TestDirective(t *testing.T) {
op.Var("slug", "personal-org")
op.Var("unread", false)
op.Var("starred", false)
+ op.Var("archive", false)
client = cmd.NewClientTest(accessToken)
err = client.Execute(ctx.Request().Context(), op, &resultAddLink)
@@ 262,15 266,18 @@ func TestAPI(t *testing.T) {
}
var result GraphQLResponse
- q := `mutation AddLink($title: String!, $url: String!, $visibility: Int!,
- $slug: String!, $tags: String, $unread: Boolean!, $starred: Boolean!) {
+ q := `mutation AddLink($title: String!, $url: String!, $description: String,
+ $visibility: Int!, $unread: Boolean!, $starred: Boolean!,
+ $archive: Boolean! $slug: String!, $tags: String) {
addLink(input: {
title: $title,
url: $url,
+ description: $description,
visibility: $visibility,
- orgSlug: $slug,
unread: $unread,
starred: $starred,
+ archive: $archive,
+ orgSlug: $slug,
tags: $tags}) {
id
}
@@ 282,6 289,7 @@ func TestAPI(t *testing.T) {
op.Var("tags", "one, two")
op.Var("unread", true)
op.Var("starred", true)
+ op.Var("archive", false)
op.Var("slug", "org_to_fail")
// TEST WRONG ORG
@@ 299,6 307,7 @@ func TestAPI(t *testing.T) {
op.Var("slug", "personal-org")
op.Var("unread", true)
op.Var("starred", true)
+ op.Var("archive", false)
err = links.Execute(ctx, op, &result)
c.Error(err)
c.Equal("gqlclient: server failure: Invalid URL.", err.Error())
@@ 312,6 321,7 @@ func TestAPI(t *testing.T) {
op.Var("slug", "personal-org")
op.Var("unread", true)
op.Var("starred", true)
+ op.Var("archive", false)
err = links.Execute(ctx, op, &result)
c.Error(err)
c.Equal("gqlclient: server failure: Invalid Visibility value.", err.Error())
@@ 323,15 333,18 @@ func TestAPI(t *testing.T) {
}
var result GraphQLResponse
- q := `mutation AddLink($title: String!, $url: String!, $visibility: Int!,
- $slug: String!, $tags: String, $unread: Boolean!, $starred: Boolean!) {
+ q := `mutation AddLink($title: String!, $url: String!, $description: String,
+ $visibility: Int!, $unread: Boolean!, $starred: Boolean!,
+ $archive: Boolean! $slug: String!, $tags: String) {
addLink(input: {
title: $title,
url: $url,
+ description: $description,
visibility: $visibility,
- orgSlug: $slug,
unread: $unread,
starred: $starred,
+ archive: $archive,
+ orgSlug: $slug,
tags: $tags}) {
id
}
@@ 344,6 357,7 @@ func TestAPI(t *testing.T) {
op.Var("slug", "personal-org")
op.Var("unread", true)
op.Var("starred", true)
+ op.Var("archive", false)
err := links.Execute(ctx, op, &result)
c.NoError(err)
@@ 370,6 384,7 @@ func TestAPI(t *testing.T) {
op.Var("slug", "personal-org")
op.Var("unread", true)
op.Var("starred", true)
+ op.Var("archive", false)
err = links.Execute(ctx, op, &result)
c.NoError(err)
@@ 496,7 511,10 @@ func TestAPI(t *testing.T) {
id
title
url
- baseUrlId
+ baseUrlId {
+ valid
+ int64
+ }
orgId
userId
visibility
@@ 733,9 751,9 @@ func TestAPI(t *testing.T) {
t.Run("delete link", func(t *testing.T) {
orgLinks, err := models.GetOrgLinks(dbCtx,
- &database.FilterOptions{Filter: sq.Expr("url = ?", "http://netlandish.com")})
+ &database.FilterOptions{Filter: sq.Expr("ol.url = ?", "http://netlandish.com")})
orgLink := orgLinks[0]
- baseURLID := orgLink.BaseURLID
+ baseURLID := orgLink.BaseURLID.Int64
type GraphQLResponse struct {
DeleteLink struct {
Success bool `json:"success"`
M list/routes_test.go => list/routes_test.go +40 -116
@@ 51,16 51,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/add")
- err = cmd.MakeRequestWithMW(srv, listService.ListingCreate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/add")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingCreate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 87,18 81,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/edit")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingUpdate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/edit")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingUpdate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 117,18 103,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/delete")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingDelete, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/delete")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingDelete, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 147,16 125,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/")
- err = cmd.MakeRequestWithMW(srv, listService.ListingList, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list")
+ ctx.SetParamNames("slug")
+ ctx.SetParamValues("personal-org")
+ err = cmd.MakeRequest(srv, listService.ListingList, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
htmlBody := recorder.Body.String()
@@ 178,18 150,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/links")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingLinksManage, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/links")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingLinksManage, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
htmlBody := recorder.Body.String()
@@ 217,18 181,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/links/add")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingLinksCreate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/links/add")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingLinksCreate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 253,18 209,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/links/:lid/edit")
- ctx.SetParamNames("id", "lid")
- ctx.SetParamValues("100", "100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingLinksUpdate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/links/:lid/edit")
+ ctx.SetParamNames("slug", "id", "lid")
+ ctx.SetParamValues("personal-org", "100", "100")
+ err = cmd.MakeRequest(srv, listService.ListingLinksUpdate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 283,18 231,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/links/:lid/delete")
- ctx.SetParamNames("id", "lid")
- ctx.SetParamValues("100", "100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingLinksDelete, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/links/:lid/delete")
+ ctx.SetParamNames("slug", "id", "lid")
+ ctx.SetParamValues("personal-org", "100", "100")
+ err = cmd.MakeRequest(srv, listService.ListingLinksDelete, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 319,18 259,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/qr/add")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingQRCodeCreate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/qr/add")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingQRCodeCreate, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
htmlBody := recorder.Body.String()
@@ 352,18 284,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: user,
}
- ctx.SetPath("/:id/qr")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, listService.ListingQRCodeList, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/list/:id/qr")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, listService.ListingQRCodeList, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
})
M short/routes_test.go => short/routes_test.go +28 -72
@@ 42,7 42,7 @@ func TestHandlers(t *testing.T) {
f.Set("slug", "personal-org")
f.Set("domain", "1")
f.Set("short", "xyz")
- request := httptest.NewRequest(http.MethodPost, "/short/add", strings.NewReader(f.Encode()))
+ request := httptest.NewRequest(http.MethodPost, "/:slug/short/add", strings.NewReader(f.Encode()))
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationForm)
recorder := httptest.NewRecorder()
ctx := &server.Context{
@@ 50,16 50,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/short/add")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortCreate, 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)
- }
- }
- })
+ ctx.SetPath(":slug/short/add")
+ ctx.SetParamNames("slug")
+ ctx.SetParamValues("personal-org")
+ err = cmd.MakeRequest(srv, shortService.LinkShortCreate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 77,7 71,7 @@ func TestHandlers(t *testing.T) {
f.Set("slug", "personal-org")
f.Set("domain", "1")
f.Set("short", "foo")
- request := httptest.NewRequest(http.MethodPost, "/:id/edit", strings.NewReader(f.Encode()))
+ request := httptest.NewRequest(http.MethodPost, "/:slug/short/:id/edit", strings.NewReader(f.Encode()))
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationForm)
recorder := httptest.NewRecorder()
ctx := &server.Context{
@@ 85,18 79,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/:id/edit")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortUpdate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/short/:id/edit")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, shortService.LinkShortUpdate, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 108,7 94,7 @@ func TestHandlers(t *testing.T) {
c.NoError(err)
httpmock.RegisterResponder("POST", "http://127.0.0.1:8080/query", jsonResponse)
- request := httptest.NewRequest(http.MethodPost, "/", nil)
+ request := httptest.NewRequest(http.MethodPost, "/:slug/short", nil)
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationForm)
recorder := httptest.NewRecorder()
ctx := &server.Context{
@@ 116,16 102,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortList, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/short")
+ ctx.SetParamNames("slug")
+ ctx.SetParamValues("personal-org")
+ err = cmd.MakeRequest(srv, shortService.LinkShortList, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
})
@@ 137,25 117,17 @@ func TestHandlers(t *testing.T) {
c.NoError(err)
httpmock.RegisterResponder("POST", "http://127.0.0.1:8080/query", jsonResponse)
- request := httptest.NewRequest(http.MethodPost, "/:id/delete", nil)
+ request := httptest.NewRequest(http.MethodPost, "/:slug/short/:id/delete", nil)
recorder := httptest.NewRecorder()
ctx := &server.Context{
Server: srv,
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/:id/delete")
- ctx.SetParamNames("id")
- ctx.SetParamValues("1")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortDelete, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/short/:id/delete")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "1")
+ err = cmd.MakeRequest(srv, shortService.LinkShortDelete, ctx)
c.NoError(err)
c.Equal(http.StatusMovedPermanently, recorder.Code)
})
@@ 180,18 152,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/:id/qr/add")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortQRCodeCreate, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/short/:id/qr/add")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, shortService.LinkShortQRCodeCreate, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
htmlBody := recorder.Body.String()
@@ 213,18 177,10 @@ func TestHandlers(t *testing.T) {
Context: e.NewContext(request, recorder),
User: loggedInUser,
}
- ctx.SetPath("/:id/qr")
- ctx.SetParamNames("id")
- ctx.SetParamValues("100")
- err = cmd.MakeRequestWithMW(srv, shortService.LinkShortQRCodeList, 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)
- }
- }
- })
+ ctx.SetPath("/:slug/short/:id/qr")
+ ctx.SetParamNames("slug", "id")
+ ctx.SetParamValues("personal-org", "100")
+ err = cmd.MakeRequest(srv, shortService.LinkShortQRCodeList, ctx)
c.NoError(err)
c.Equal(http.StatusOK, recorder.Code)
})