Skip to content

Commit

Permalink
Merge pull request #1565 from traPtitech/fix/twitter-ogp
Browse files Browse the repository at this point in the history
TwitterのOGP取得修正とテスト追加
  • Loading branch information
motoki317 authored Nov 8, 2022
2 parents 8d76c81 + 091e08e commit e0c6a41
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion service/ogp/parser/domain_twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions service/ogp/parser/domain_twitter_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
48 changes: 48 additions & 0 deletions service/ogp/parser/domain_vrchat_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit e0c6a41

Please sign in to comment.