From 4f8e0bc6271ad3436c592acb91b9b79ea7061e24 Mon Sep 17 00:00:00 2001 From: Noah Hernandez <63211322+oahnh@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:05:43 -0800 Subject: [PATCH 1/2] adds bsky tests --- bot/pkg/bsky/bsky_test.go | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bot/pkg/bsky/bsky_test.go diff --git a/bot/pkg/bsky/bsky_test.go b/bot/pkg/bsky/bsky_test.go new file mode 100644 index 0000000..5acf3e2 --- /dev/null +++ b/bot/pkg/bsky/bsky_test.go @@ -0,0 +1,49 @@ +package bsky + +import ( + "testing" +) + +func TestGenerateBskyUrl(t *testing.T) { + post := Post{ + URI: "at://did:plc:tixombvfeipi656t6fpzyi2h/app.bsky.feed.post/3la5fcokczp2e", + Author: map[string]interface{}{ + "handle": "testhandle.bsky.social", + }, + } + + url, err := generateBskyUrl(post) + if err != nil { + t.Errorf("expected no error generating bsky url: %v", err) + } + + expectedUrl := "https://bsky.app/profile/testhandle.bsky.social/post/3la5fcokczp2e" + if url != expectedUrl { + t.Errorf("expected %s, got %s", expectedUrl, url) + } + +} + +func TestExtractRKey(t *testing.T) { + tests := []struct { + uri string + expectedRkey string + testShouldErr bool + }{ + {"at://did:plc:tixombvfeipi656t6fpzyi2h/app.bsky.feed.post/3la5fcokczp2e", "3la5fcokczp2e", false}, + {"invalid/uri/fmt", "", true}, + } + + for _, tt := range tests { + rkey, err := extractRKey(tt.uri) + if (err != nil) != tt.testShouldErr { + t.Errorf("extractRKey error for uri %q: %v, testShouldErr = %v", tt.uri, err, tt.testShouldErr) + } + + if rkey != tt.expectedRkey { + t.Errorf("extractRKey for uri %q = %q, expected %q", tt.uri, rkey, tt.expectedRkey) + } + + } + +} From d0026a79ad4874e4ee2865786ed06cea70bf9ea1 Mon Sep 17 00:00:00 2001 From: Noah Hernandez <63211322+oahnh@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:56:15 -0800 Subject: [PATCH 2/2] refactor: test --- bot/pkg/bsky/bsky_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/pkg/bsky/bsky_test.go b/bot/pkg/bsky/bsky_test.go index 5acf3e2..068f28e 100644 --- a/bot/pkg/bsky/bsky_test.go +++ b/bot/pkg/bsky/bsky_test.go @@ -31,7 +31,7 @@ func TestExtractRKey(t *testing.T) { testShouldErr bool }{ {"at://did:plc:tixombvfeipi656t6fpzyi2h/app.bsky.feed.post/3la5fcokczp2e", "3la5fcokczp2e", false}, - {"invalid/uri/fmt", "", true}, + {"invalid/", "", true}, } for _, tt := range tests {