From e0be4c944598e989c6b07bee411698b26198edf3 Mon Sep 17 00:00:00 2001 From: motoki317 Date: Tue, 8 Nov 2022 20:53:17 +0900 Subject: [PATCH 1/3] Fix twitter OGP url --- service/ogp/parser/domain_twitter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/ogp/parser/domain_twitter.go b/service/ogp/parser/domain_twitter.go index f2cc6364c..f77d2d7f2 100644 --- a/service/ogp/parser/domain_twitter.go +++ b/service/ogp/parser/domain_twitter.go @@ -68,7 +68,7 @@ func fetchTwitterSyndicationAPI(statusID string) (*TwitterSyndicationAPIResponse client := http.Client{ Timeout: 5 * time.Second, } - requestURL := fmt.Sprintf("https://syndication.twitter.com/tweet?id=%s", statusID) + requestURL := fmt.Sprintf("https://syndication.twitter.com/tweet-result?id=%s", statusID) resp, err := client.Get(requestURL) if err != nil { return nil, ErrNetwork From 42135ea9301a21f4c06c410dcc58298be197cba8 Mon Sep 17 00:00:00 2001 From: motoki317 Date: Tue, 8 Nov 2022 20:53:24 +0900 Subject: [PATCH 2/3] Add twitter OGP test --- service/ogp/parser/domain_twitter_test.go | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 service/ogp/parser/domain_twitter_test.go diff --git a/service/ogp/parser/domain_twitter_test.go b/service/ogp/parser/domain_twitter_test.go new file mode 100644 index 000000000..99ab2540e --- /dev/null +++ b/service/ogp/parser/domain_twitter_test.go @@ -0,0 +1,44 @@ +package parser + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_fetchTwitterSyndicationAPI(t *testing.T) { + tests := []struct { + name string + statusID string + want func(t *testing.T, res *TwitterSyndicationAPIResponse) + wantErr assert.ErrorAssertionFunc + }{ + { + name: "success", + statusID: "990696508403040256", + want: func(t *testing.T, res *TwitterSyndicationAPIResponse) { + assert.Equal(t, "@_winnie_on は?情緒不安定か?マンゴーうまいぜ", res.Text) + }, + wantErr: assert.NoError, + }, + { + name: "not found", + statusID: "990696508403040257", + want: func(t *testing.T, res *TwitterSyndicationAPIResponse) { + }, + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.ErrorIs(t, err, ErrClient, i...) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := fetchTwitterSyndicationAPI(tt.statusID) + if !tt.wantErr(t, err, fmt.Sprintf("fetchTwitterSyndicationAPI(%v)", tt.statusID)) { + return + } + tt.want(t, got) + }) + } +} From 091e08ea5e950de1700ea447ac2117e000de5eed Mon Sep 17 00:00:00 2001 From: motoki317 Date: Tue, 8 Nov 2022 21:01:15 +0900 Subject: [PATCH 3/3] Add VRChat OGP test --- service/ogp/parser/domain_vrchat_test.go | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 service/ogp/parser/domain_vrchat_test.go diff --git a/service/ogp/parser/domain_vrchat_test.go b/service/ogp/parser/domain_vrchat_test.go new file mode 100644 index 000000000..a37f00ccd --- /dev/null +++ b/service/ogp/parser/domain_vrchat_test.go @@ -0,0 +1,48 @@ +package parser + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_fetchVRChatWorldInfo(t *testing.T) { + tests := []struct { + name string + worldID string + want func(t *testing.T, res *VRChatAPIWorldResponse) + wantErr assert.ErrorAssertionFunc + }{ + { + name: "success", + worldID: "wrld_aa762efb-17b3-4302-8f41-09c4db2489ed", + want: func(t *testing.T, res *VRChatAPIWorldResponse) { + assert.Equal(t, "PROJECT˸ SUMMER FLARE", res.Name) + assert.Equal(t, "Break the Summer․ Break the tower․ Complete the Meridian Loop․ A story about reality and humanity․", res.Description) + assert.True(t, strings.HasPrefix(res.ImageURL, "https://")) + assert.True(t, strings.HasPrefix(res.ThumbnailImageURL, "https://")) + }, + wantErr: assert.NoError, + }, + { + name: "not found", + worldID: "wrld_aa762efb-17b3-4302-8f41-09c4db2489ee", + want: func(t *testing.T, res *VRChatAPIWorldResponse) { + }, + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.ErrorIs(t, err, ErrClient, i...) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := fetchVRChatWorldInfo(tt.worldID) + if !tt.wantErr(t, err, fmt.Sprintf("fetchVRChatWorldInfo(%v)", tt.worldID)) { + return + } + tt.want(t, got) + }) + } +}