this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

labeler: initial queryLabels test case

+51 -2
+18
labeler/helpers_test.go
··· 13 13 "github.com/stretchr/testify/assert" 14 14 15 15 comatproto "github.com/bluesky-social/indigo/api/atproto" 16 + label "github.com/bluesky-social/indigo/api/label" 16 17 ) 17 18 18 19 // fetches report, both getModerationReport and getModerationReports, verifies match ··· 237 238 238 239 return out 239 240 } 241 + 242 + func testQueryLabels(t *testing.T, e *echo.Echo, lm *Server, params *url.Values) (*label.QueryLabels_Output, error) { 243 + 244 + req := httptest.NewRequest(http.MethodGet, "/xrpc/com.atproto.label.queryLabels?"+params.Encode(), nil) 245 + req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) 246 + recorder := httptest.NewRecorder() 247 + c := e.NewContext(req, recorder) 248 + err := lm.HandleComAtprotoLabelQueryLabels(c) 249 + if err != nil { 250 + return nil, err 251 + } 252 + var out label.QueryLabels_Output 253 + if err := json.Unmarshal([]byte(recorder.Body.String()), &out); err != nil { 254 + t.Fatal(err) 255 + } 256 + return &out, nil 257 + }
+33 -2
labeler/xrpc_test.go
··· 1 1 package labeler 2 2 3 3 import ( 4 + "context" 4 5 "encoding/json" 5 6 "fmt" 6 7 "net/http" 7 8 "net/http/httptest" 9 + "net/url" 8 10 "strings" 9 11 "testing" 10 12 13 + comatproto "github.com/bluesky-social/indigo/api/atproto" 14 + label "github.com/bluesky-social/indigo/api/label" 15 + 11 16 "github.com/labstack/echo/v4" 12 17 "github.com/stretchr/testify/assert" 13 - 14 - comatproto "github.com/bluesky-social/indigo/api/atproto" 15 18 ) 16 19 17 20 func TestLabelMakerXRPCReportRepo(t *testing.T) { ··· 285 288 assert.Equal(reportId, actionOutDetail.ResolvedReports[0].Id) 286 289 assert.Equal(reversalOut.Reversal, actionOutDetail.Reversal) 287 290 } 291 + 292 + func TestLabelMakerXRPCLabelQuery(t *testing.T) { 293 + assert := assert.New(t) 294 + e := echo.New() 295 + lm := testLabelMaker(t) 296 + ctx := context.TODO() 297 + 298 + // simple query, no labels 299 + p1 := make(url.Values) 300 + p1.Set("uriPatterns", "*") 301 + out1, err := testQueryLabels(t, e, lm, &p1) 302 + assert.NoError(err) 303 + assert.Equal(0, len(out1.Labels)) 304 + 305 + // create a label, then query 306 + l3 := label.Label{ 307 + Uri: "at://did:plc:fake/com.example/abc234", 308 + Val: "example", 309 + Cts: "2023-03-15T22:16:18.408Z", 310 + } 311 + lm.CommitLabels(ctx, []*label.Label{&l3}, false) 312 + p3 := make(url.Values) 313 + p3.Set("uriPatterns", l3.Uri) 314 + out3, err := testQueryLabels(t, e, lm, &p3) 315 + assert.NoError(err) 316 + assert.Equal(1, len(out3.Labels)) 317 + assert.Equal(&l3, out3.Labels[0]) 318 + }