Skip to content

Commit

Permalink
Merge pull request #15 from joshraphael/issue-14
Browse files Browse the repository at this point in the history
issue-14 -- Various general fixes
  • Loading branch information
joshraphael authored Feb 5, 2025
2 parents 46a824a + 0f6a1f3 commit 1248dc0
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 163 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ jobs:
config: ./.github/.testcoverage.yml
local-prefix: github.com/joshraphael/go-retroachievements
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
git-branch: badges
git-branch: badges

smoke:
name: smoke
runs-on: ubuntu-latest
env:
RA_API_KEY: ${{ secrets.RA_API_KEY }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3

- name: smoke test endpoints
run: bash ./scripts/smoke.sh
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ outfile := coverage
test:
bash ./scripts/test.sh --open

smoke:
bash ./scripts/smoke.sh

docs:
godoc -http=:8080
8 changes: 4 additions & 4 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

func TestGetAchievementOfTheWeek(tt *testing.T) {
achievementType := "progression"
dateCreated, err := time.Parse(time.DateTime, "2012-11-02 00:03:12")
dateCreated, err := time.Parse(time.DateOnly, "2012-11-02")
require.NoError(tt, err)
dateModified, err := time.Parse(time.DateTime, "2023-09-30 02:00:49")
dateModified, err := time.Parse(time.DateOnly, "2023-09-30")
require.NoError(tt, err)
dateAwarded, err := time.Parse(time.RFC3339Nano, "2024-11-22T17:25:17.000000Z")
require.NoError(tt, err)
Expand Down Expand Up @@ -88,10 +88,10 @@ func TestGetAchievementOfTheWeek(tt *testing.T) {
Points: 5,
TrueRatio: 7,
Author: "Scott",
DateCreated: models.DateTime{
DateCreated: &models.DateOnly{
Time: dateCreated,
},
DateModified: models.DateTime{
DateModified: &models.DateOnly{
Time: dateModified,
},
Type: &achievementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
client := retroachievements.NewClient(secret)

resp, err := client.GetUserWantToPlayList(models.GetUserWantToPlayListParameters{
Username: "jamiras",
Username: "spoony",
})
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestGetGameExtended(tt *testing.T) {
Time: released,
},
ID: 2991,
IsFinal: 0,
IsFinal: false,
RichPresencePatch: "e7a5e12072a6c976a1146756726fdd8c",
Updated: &updated,
ConsoleName: "PlayStation 2",
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestGetGameExtended(tt *testing.T) {
Time: released,
},
ID: 2991,
IsFinal: 0,
IsFinal: false,
RichPresencePatch: "e7a5e12072a6c976a1146756726fdd8c",
Updated: &updated,
ConsoleName: "PlayStation 2",
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestGetGameExtended(tt *testing.T) {
require.Equal(t, "Vehicular Combat", resp.Genre)
require.Equal(t, released, resp.Released.Time)
require.Equal(t, 2991, resp.ID)
require.Equal(t, 0, resp.IsFinal)
require.False(t, resp.IsFinal)
require.Equal(t, "e7a5e12072a6c976a1146756726fdd8c", resp.RichPresencePatch)
require.Equal(t, updated, *resp.Updated)
require.Equal(t, "PlayStation 2", resp.ConsoleName)
Expand Down
18 changes: 9 additions & 9 deletions models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type GetAchievementOfTheWeek struct {
}

type GetAchievementOfTheWeekAchievement struct {
ID int `json:"ID"`
Title string `json:"Title"`
Description string `json:"Description"`
Points int `json:"Points"`
TrueRatio int `json:"TrueRatio"`
Author string `json:"Author"`
DateCreated DateTime `json:"DateCreated"`
DateModified DateTime `json:"DateModified"`
Type *string `json:"Type"`
ID int `json:"ID"`
Title string `json:"Title"`
Description string `json:"Description"`
Points int `json:"Points"`
TrueRatio int `json:"TrueRatio"`
Author string `json:"Author"`
DateCreated *DateOnly `json:"DateCreated"`
DateModified *DateOnly `json:"DateModified"`
Type *string `json:"Type"`
}

type GetAchievementOfTheWeekConsole struct {
Expand Down
2 changes: 1 addition & 1 deletion models/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type GetGameExtented struct {
Genre string `json:"Genre"`
Released *DateOnly `json:"Released"`
ID int `json:"ID"`
IsFinal int `json:"IsFinal"`
IsFinal bool `json:"IsFinal"`
RichPresencePatch string `json:"RichPresencePatch"`
GuideURL *string `json:"GuideURL"`
Updated *time.Time `json:"Updated"`
Expand Down
31 changes: 0 additions & 31 deletions models/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,6 @@ func (do *DateOnly) String() string {
return fmt.Sprintf("%q", do.Format(time.DateOnly))
}

// LongMonthDate is a time data structure that can be used for string dates formatted as "January 02, 2006"
type LongMonthDate struct {
time.Time
}

const (
LongMonthDateFormat = "January 2, 2006"
)

func (lmd *LongMonthDate) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), `"`)
if s == "" {
*lmd = LongMonthDate{time.Time{}}
return nil
}
nt, err := time.Parse(LongMonthDateFormat, s)
if err != nil {
return err
}
*lmd = LongMonthDate{nt}
return nil
}

func (lmd LongMonthDate) MarshalJSON() ([]byte, error) {
return []byte(lmd.String()), nil
}

func (lmd *LongMonthDate) String() string {
return fmt.Sprintf("%q", lmd.Format(LongMonthDateFormat))
}

// RFC3339NumColonTZ is a time data structure that can be used for string dates formatted as "2006-01-02T15:04:05-07:00"
type RFC3339NumColonTZ struct {
time.Time
Expand Down
53 changes: 0 additions & 53 deletions models/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,59 +61,6 @@ func TestDateTimeString(tt *testing.T) {
require.Equal(tt, `"`+expectedString+`"`, d.String())
}

func TestLongMonthDateUnmarshalJSON(tt *testing.T) {
tests := []struct {
name string
input string
assert func(t *testing.T, date *models.LongMonthDate, err error)
}{
{
name: "empty string default",
input: "\"\"",
assert: func(t *testing.T, date *models.LongMonthDate, err error) {
require.NotNil(t, date)
require.True(t, date.Time.IsZero())
require.NoError(t, err)
},
},
{
name: "unknown bytes",
input: "\"?>?>>L:\"",
assert: func(t *testing.T, date *models.LongMonthDate, err error) {
require.NotNil(t, date)
require.True(t, date.Time.IsZero())
require.EqualError(t, err, "parsing time \"?>?>>L:\" as \"January 2, 2006\": cannot parse \"?>?>>L:\" as \"January\"")
},
},
{
name: "successfully unmarshal",
input: "\"March 02, 2024\"",
assert: func(t *testing.T, date *models.LongMonthDate, err error) {
ts, tErr := time.Parse(models.LongMonthDateFormat, "March 2, 2024")
require.NoError(t, tErr)
require.NotNil(t, date)
require.Equal(t, ts, date.Time)
require.NoError(t, err)
},
},
}
for _, test := range tests {
tt.Run(test.name, func(t *testing.T) {
d := &models.LongMonthDate{}
err := d.UnmarshalJSON([]byte(test.input))
test.assert(t, d, err)
})
}
}

func TestLongMonthDateString(tt *testing.T) {
expectedString := "March 2, 2024"
t, err := time.Parse(models.LongMonthDateFormat, expectedString)
require.NoError(tt, err)
d := &models.LongMonthDate{t}
require.Equal(tt, `"`+expectedString+`"`, d.String())
}

func TestRFC3339NumColonTZUnmarshalJSON(tt *testing.T) {
tests := []struct {
name string
Expand Down
21 changes: 1 addition & 20 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ type GetGameInfoAndUserProgress struct {
Genre string `json:"Genre"`
Released *DateOnly `json:"Released"`
ReleasedAtGranularity *string `json:"ReleasedAtGranularity"`
IsFinal int `json:"IsFinal"`
IsFinal bool `json:"IsFinal"`
RichPresencePatch string `json:"RichPresencePatch"`
GuideURL *string `json:"GuideURL"`
ConsoleName string `json:"ConsoleName"`
Expand Down Expand Up @@ -499,7 +499,6 @@ type GetUserSummary struct {
RecentlyPlayed []GetUserSummaryRecentlyPlayed `json:"RecentlyPlayed"`
Awarded map[string]GetUserSummaryAwarded `json:"Awarded"`
RecentAchievements map[string]map[string]GetUserSummaryRecentAchievements `json:"RecentAchievements"`
LastGame GetUserSummaryLastGame `json:"LastGame"`
}

type GetUserSummaryLastActivity struct {
Expand Down Expand Up @@ -543,24 +542,6 @@ type GetUserSummaryRecentAchievements struct {
HardcoreAchieved int `json:"HardcoreAchieved"`
}

type GetUserSummaryLastGame struct {
ID int `json:"ID"`
Title string `json:"Title"`
ConsoleID int `json:"ConsoleID"`
ConsoleName string `json:"ConsoleName"`
ForumTopicID int `json:"ForumTopicID"`
Flags int `json:"Flags"`
ImageIcon string `json:"ImageIcon"`
ImageTitle string `json:"ImageTitle"`
ImageIngame string `json:"ImageIngame"`
ImageBoxArt string `json:"ImageBoxArt"`
Publisher string `json:"Publisher"`
Developer string `json:"Developer"`
Genre string `json:"Genre"`
Released LongMonthDate `json:"Released"`
IsFinal int `json:"IsFinal"`
}

type GetUserCompletedGamesParameters struct {
// The target username
Username string
Expand Down
11 changes: 11 additions & 0 deletions scripts/smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

for file in ./examples/*/*/*.go; do
go run $file > /dev/null
if [ $? -eq 0 ]; then
echo "$file succeeded"
else
echo "$file failed"
exit 1
fi
done;
43 changes: 3 additions & 40 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@ func TestGetAchievementsEarnedOnDay(tt *testing.T) {
}

func TestGetGameInfoAndUserProgress(tt *testing.T) {
released, err := time.Parse(models.LongMonthDateFormat, "June 18, 2001")
require.NoError(tt, err)
released, err := time.Parse(time.DateOnly, "2001-06-18")
require.NoError(tt, err)
modified, err := time.Parse(time.DateTime, "2022-10-25 17:00:49")
require.NoError(tt, err)
Expand Down Expand Up @@ -746,7 +745,7 @@ func TestGetGameInfoAndUserProgress(tt *testing.T) {
Developer: "Incognito Entertainment",
Genre: "Vehicular Combat",
ID: 2991,
IsFinal: 0,
IsFinal: false,
RichPresencePatch: "e7a5e12072a6c976a1146756726fdd8c",
ConsoleName: "PlayStation 2",
NumDistinctPlayers: 1287,
Expand Down Expand Up @@ -807,7 +806,7 @@ func TestGetGameInfoAndUserProgress(tt *testing.T) {
require.Equal(t, "Vehicular Combat", gameProgress.Genre)
require.Equal(t, released, gameProgress.Released.Time)
require.Equal(t, 2991, gameProgress.ID)
require.Equal(t, 0, gameProgress.IsFinal)
require.False(t, gameProgress.IsFinal)
require.Equal(t, "e7a5e12072a6c976a1146756726fdd8c", gameProgress.RichPresencePatch)
require.Equal(t, "PlayStation 2", gameProgress.ConsoleName)
require.Equal(t, 1287, gameProgress.NumDistinctPlayers)
Expand Down Expand Up @@ -1976,8 +1975,6 @@ func TestGetUserSummary(tt *testing.T) {
require.NoError(tt, err)
lastPlayed, err := time.Parse(time.DateTime, "2024-11-17 04:00:35")
require.NoError(tt, err)
releaseDate, err := time.Parse(models.LongMonthDateFormat, "September 27, 2011")
require.NoError(tt, err)
cheevoType := "progression"
tests := []struct {
name string
Expand Down Expand Up @@ -2129,25 +2126,6 @@ func TestGetUserSummary(tt *testing.T) {
},
},
},
LastGame: models.GetUserSummaryLastGame{
ID: 9404,
Title: "Solatorobo: Red the Hunter",
ConsoleID: 18,
ConsoleName: "Nintendo DS",
ForumTopicID: 21569,
Flags: 0,
ImageIcon: "/Images/088320.png",
ImageTitle: "/Images/073286.png",
ImageIngame: "/Images/073287.png",
ImageBoxArt: "/Images/028653.png",
Publisher: "XSEED Games",
Developer: "CyberConnect2 | CyberConnect",
Genre: "Action RPG",
Released: models.LongMonthDate{
Time: releaseDate,
},
IsFinal: 0,
},
},
response: func(messageBytes []byte, errorBytes []byte) []byte {
return messageBytes
Expand Down Expand Up @@ -2213,21 +2191,6 @@ func TestGetUserSummary(tt *testing.T) {
require.NotNil(t, cheevo.Type)
require.Equal(t, cheevoType, *cheevo.Type)
require.Equal(t, lastPlayed, cheevo.DateAwarded.Time)
require.Equal(t, 9404, resp.LastGame.ID)
require.Equal(t, "Solatorobo: Red the Hunter", resp.LastGame.Title)
require.Equal(t, 18, resp.LastGame.ConsoleID)
require.Equal(t, "Nintendo DS", resp.LastGame.ConsoleName)
require.Equal(t, 21569, resp.LastGame.ForumTopicID)
require.Equal(t, 0, resp.LastGame.Flags)
require.Equal(t, "/Images/088320.png", resp.LastGame.ImageIcon)
require.Equal(t, "/Images/073286.png", resp.LastGame.ImageTitle)
require.Equal(t, "/Images/073287.png", resp.LastGame.ImageIngame)
require.Equal(t, "/Images/028653.png", resp.LastGame.ImageBoxArt)
require.Equal(t, "XSEED Games", resp.LastGame.Publisher)
require.Equal(t, "CyberConnect2 | CyberConnect", resp.LastGame.Developer)
require.Equal(t, "Action RPG", resp.LastGame.Genre)
require.Equal(t, releaseDate, resp.LastGame.Released.Time)
require.Equal(t, 0, resp.LastGame.IsFinal)
},
},
}
Expand Down

0 comments on commit 1248dc0

Please sign in to comment.