this repo has no description
0
fork

Configure Feed

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

labelmaker: start of basic XRPC endpoint tests

+127
+68
labeling/moderation_test.go
··· 1 + package labeling 2 + 3 + import ( 4 + "encoding/json" 5 + "net/http" 6 + "net/http/httptest" 7 + "net/url" 8 + "strconv" 9 + "strings" 10 + "testing" 11 + 12 + "github.com/labstack/echo/v4" 13 + "github.com/stretchr/testify/assert" 14 + 15 + comatproto "github.com/bluesky-social/indigo/api/atproto" 16 + ) 17 + 18 + func TestLabelMakerXRPCReport(t *testing.T) { 19 + e := echo.New() 20 + lm := testLabelMaker(t) 21 + 22 + // create and read back a basic repo report 23 + rt := "spam" 24 + report := comatproto.ReportCreate_Input{ 25 + //Reason 26 + ReasonType: &rt, 27 + Subject: &comatproto.ReportCreate_Input_Subject{ 28 + RepoRepoRef: &comatproto.RepoRepoRef{ 29 + //com.atproto.repo.repoRef 30 + Did: "did:plc:123", 31 + }, 32 + }, 33 + } 34 + reportJSON, err := json.Marshal(report) 35 + if err != nil { 36 + t.Fatal(err) 37 + } 38 + req := httptest.NewRequest(http.MethodPost, "/xrpc/com.atproto.report.create", strings.NewReader(string(reportJSON))) 39 + req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) 40 + recorder := httptest.NewRecorder() 41 + c := e.NewContext(req, recorder) 42 + 43 + assert.NoError(t, lm.HandleComAtprotoReportCreate(c)) 44 + // TODO: "Created" / 201 45 + assert.Equal(t, 200, recorder.Code) 46 + 47 + var out comatproto.ReportCreate_Output 48 + if err := json.Unmarshal([]byte(recorder.Body.String()), &out); err != nil { 49 + t.Fatal(err) 50 + } 51 + assert.Equal(t, report.ReasonType, out.ReasonType) 52 + assert.Equal(t, report.Subject.RepoRepoRef, out.Subject.RepoRepoRef) 53 + 54 + // read it back 55 + params := make(url.Values) 56 + params.Set("id", strconv.Itoa(int(out.Id))) 57 + req = httptest.NewRequest(http.MethodGet, "/xrpc/com.atproto.admin.getModerationReport?"+params.Encode(), nil) 58 + recorder = httptest.NewRecorder() 59 + c = e.NewContext(req, recorder) 60 + assert.NoError(t, lm.HandleComAtprotoAdminGetModerationReport(c)) 61 + assert.Equal(t, 200, recorder.Code) 62 + 63 + var view comatproto.AdminModerationReport_ViewDetail 64 + if err := json.Unmarshal([]byte(recorder.Body.String()), &view); err != nil { 65 + t.Fatal(err) 66 + } 67 + assert.Equal(t, report.ReasonType, view.ReasonType) 68 + }
+59
labeling/service_test.go
··· 1 + package labeling 2 + 3 + import ( 4 + "os" 5 + "path/filepath" 6 + "testing" 7 + 8 + "github.com/bluesky-social/indigo/carstore" 9 + "gorm.io/driver/sqlite" 10 + "gorm.io/gorm" 11 + ) 12 + 13 + func testLabelMaker(t *testing.T) *Server { 14 + 15 + tempdir, err := os.MkdirTemp("", "labelmaker-test-") 16 + if err != nil { 17 + t.Fatal(err) 18 + } 19 + sharddir := filepath.Join(tempdir, "shards") 20 + if err := os.MkdirAll(sharddir, 0775); err != nil { 21 + t.Fatal(err) 22 + } 23 + 24 + db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{SkipDefaultTransaction: true}) 25 + if err != nil { 26 + t.Fatal(err) 27 + } 28 + 29 + cs, err := carstore.NewCarStore(db, sharddir) 30 + if err != nil { 31 + t.Fatal(err) 32 + } 33 + 34 + repoKeyPath := filepath.Join(tempdir, "labelmaker.key") 35 + serkey, err := LoadOrCreateKeyFile(repoKeyPath, "auto-labelmaker") 36 + if err != nil { 37 + t.Fatal(err) 38 + } 39 + 40 + plcURL := "http://did-plc-test.dummy" 41 + blobPdsURL := "http://pds-test.dummy" 42 + repoUser := RepoConfig{ 43 + Handle: "test.handle.dummy", 44 + Did: "did:plc:testdummy", 45 + SigningKey: serkey, 46 + UserId: 1, 47 + } 48 + 49 + lm, err := NewServer(db, cs, repoUser, plcURL, blobPdsURL, false) 50 + if err != nil { 51 + t.Fatal(err) 52 + } 53 + return lm 54 + } 55 + 56 + func TestLabelMakerCreation(t *testing.T) { 57 + lm := testLabelMaker(t) 58 + _ = lm 59 + }