From bdc2c88f833a3fcdafdc674009de3587d09c81fb Mon Sep 17 00:00:00 2001 From: Jeffrey Duroyon Date: Fri, 26 Sep 2025 14:02:01 +0200 Subject: [PATCH] feat: format and add test --- .github/copilot-instructions.md | 46 +++++++++++++++++++++++++++++++++ client/cards_test.go | 28 ++++++++++++++++++++ client/series_test.go | 28 ++++++++++++++++++++ client/sets_test.go | 28 ++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 .github/copilot-instructions.md create mode 100644 client/cards_test.go create mode 100644 client/series_test.go create mode 100644 client/sets_test.go diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..120adf2 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,46 @@ +# Copilot Instructions for tcgdex-golang + +## Project Overview +This repository implements a Go client for interacting with the tcgdex (Trading Card Game Database) API. The codebase is organized into two main directories: +- `client/`: Contains API client logic and request builders for cards, series, and sets. +- `models/`: Defines data structures representing cards, abilities, attacks, items, variants, legalities, series, and sets. + +## Architecture & Data Flow +- The `client` package provides entry points for querying tcgdex data. Each file (e.g., `cards.go`, `series.go`) encapsulates logic for a specific resource type. +- The `models` package contains Go structs that mirror the API's JSON schema. These are used for unmarshalling API responses and internal data handling. +- Data flows from API requests (built in `client/`) into model structs, which are then consumed by application logic or returned to callers. + +## Developer Workflows +- **Build:** Use `go build ./...` from the project root to build all packages. +- **Test:** Run `go test ./...` to execute all tests (if present). No test files detected in the current structure. +- **Coverage:** If coverage is needed, use `go test -coverprofile=coverage.out ./...`. +- **Dependencies:** Managed via Go modules (`go.mod`, `go.sum`). Use `go mod tidy` to clean up dependencies. +- **Makefile:** If present, check for custom build/test commands. (No custom targets detected in current context.) + +## Project-Specific Patterns +- **Resource Separation:** Each API resource (card, series, set) has its own client and model files. Follow this pattern for new resources. +- **Model Naming:** Model structs use the `card_`, `serie_`, and `set_` prefixes to indicate their domain. Maintain this convention for clarity. +- **Client Builders:** Use builder patterns in `client/client_builder.go` for constructing complex queries. +- **Error Handling:** Standard Go error handling is used. Return errors from client methods and propagate them up. + +## Integration Points +- **External API:** All data is fetched from the tcgdex API. No other external services detected. +- **No Database:** The project does not persist data locally; it acts as a pure API client. + +## Examples +- To add a new resource, create a model in `models/` (e.g., `resource.go`) and a client in `client/` (e.g., `resource.go`). +- To extend card functionality, update `models/card.go` and `client/cards.go`. + +## Key Files +- `client/cards.go`, `client/series.go`, `client/sets.go`: API resource clients +- `models/card.go`, `models/serie.go`, `models/set.go`: Core data models +- `client/client_builder.go`: Query builder logic +- `go.mod`, `go.sum`: Dependency management + +## Conventions +- Keep resource logic and models in separate files for maintainability. +- Use Go idioms for error handling and struct design. +- Document public methods with GoDoc comments for clarity. + +--- +If any section is unclear or missing important details, please specify which part needs improvement or what additional context is required. \ No newline at end of file diff --git a/client/cards_test.go b/client/cards_test.go new file mode 100644 index 0000000..72752b7 --- /dev/null +++ b/client/cards_test.go @@ -0,0 +1,28 @@ +package client + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGetCardByID(t *testing.T) { + tests := []struct { + name string + cardID string + wantErr bool + wantCard *Card + }{ + {"valid card", "xy1-1", false, &Card{ID: "xy1-1"}}, + {"invalid card", "invalid-id", true, nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + card, err := GetCardByID(tt.cardID) + + require.ErrorIs(t, err, ErrNotFound) + require.Equal(t, tt.wantCard, card, "expected card: %v, got: %v for cardID %v", tt.wantCard, card, tt.cardID) + }) + } +} diff --git a/client/series_test.go b/client/series_test.go new file mode 100644 index 0000000..6d4ee93 --- /dev/null +++ b/client/series_test.go @@ -0,0 +1,28 @@ +package client + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGetSeriesByID(t *testing.T) { + tests := []struct { + name string + seriesID string + wantErr bool + wantSeries *Series + }{ + {"valid series", "xy", false, &Series{ID: "xy"}}, + {"invalid series", "invalid-id", true, nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + series, err := GetSeriesByID(tt.seriesID) + + require.ErrorIs(t, err, ErrNotFound) + require.Equal(t, tt.wantSeries, series, "expected series: %v, got: %v for seriesID %v", tt.wantSeries, series, tt.seriesID) + }) + } +} diff --git a/client/sets_test.go b/client/sets_test.go new file mode 100644 index 0000000..f3e9b98 --- /dev/null +++ b/client/sets_test.go @@ -0,0 +1,28 @@ +package client + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGetSetByID(t *testing.T) { + tests := []struct { + name string + setID string + wantErr bool + wantSet *Set + }{ + {"valid set", "xy1", false, &Set{ID: "xy1"}}, + {"invalid set", "invalid-id", true, nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + set, err := GetSetByID(tt.setID) + + require.ErrorIs(t, err, ErrNotFound) + require.Equal(t, tt.wantSet, set, "expected set: %v, got: %v for setID %v", tt.wantSet, set, tt.setID) + }) + } +}