-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1565 from traPtitech/fix/twitter-ogp
TwitterのOGP取得修正とテスト追加
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |