Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added /location/ endpoints and unit tests
- Loading branch information
Showing
3 changed files
with
183 additions
and
6 deletions.
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,31 @@ | ||
package pokeapi | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mtslzr/pokeapi-go/structs" | ||
) | ||
|
||
// Location returns a single location (by name or ID). | ||
func Location(id string) (result structs.Location, err error) { | ||
err = do(fmt.Sprintf("location/%s", id), &result) | ||
return result, err | ||
} | ||
|
||
// LocationArea returns a single location area (by name or ID). | ||
func LocationArea(id string) (result structs.LocationArea, err error) { | ||
err = do(fmt.Sprintf("location-area/%s", id), &result) | ||
return result, err | ||
} | ||
|
||
// PalParkArea returns a single Pal Park area (by name or ID). | ||
func PalParkArea(id string) (result structs.PalParkArea, err error) { | ||
err = do(fmt.Sprintf("pal-park-area/%s", id), &result) | ||
return result, err | ||
} | ||
|
||
// Region returns a single region (by name or ID). | ||
func Region(id string) (result structs.Region, err error) { | ||
err = do(fmt.Sprintf("region/%s", id), &result) | ||
return result, err | ||
} |
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,80 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
pokeapi "github.com/mtslzr/pokeapi-go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLocation(t *testing.T) { | ||
result, _ := pokeapi.Location("1") | ||
assert.Equal(t, "canalave-city", result.Name, | ||
"Expect to receive Canalave City.") | ||
} | ||
|
||
func TestLocationByName(t *testing.T) { | ||
result, _ := pokeapi.Location("canalave-city") | ||
assert.Equal(t, "canalave-city", result.Name, | ||
"Expect to receive Canalave City.") | ||
} | ||
|
||
func TestLocationFail(t *testing.T) { | ||
result, _ := pokeapi.Location("asdf") | ||
assert.Equal(t, "", result.Name, | ||
"Expect to receive an empty result.") | ||
} | ||
|
||
func TestLocationArea(t *testing.T) { | ||
result, _ := pokeapi.LocationArea("1") | ||
assert.Equal(t, "canalave-city-area", result.Name, | ||
"Expect to receive Canalave City area.") | ||
} | ||
|
||
func TestLocationAreaByName(t *testing.T) { | ||
result, _ := pokeapi.LocationArea("canalave-city-area") | ||
assert.Equal(t, "canalave-city-area", result.Name, | ||
"Expect to receive Canalave City area.") | ||
} | ||
|
||
func TestLocationAreaFail(t *testing.T) { | ||
result, _ := pokeapi.LocationArea("asdf") | ||
assert.Equal(t, "", result.Name, | ||
"Expect to receive an empty result.") | ||
} | ||
|
||
func TestPalParkArea(t *testing.T) { | ||
result, _ := pokeapi.PalParkArea("1") | ||
assert.Equal(t, "forest", result.Name, | ||
"Expect to receive Forest.") | ||
} | ||
|
||
func TestPalParkAreaByName(t *testing.T) { | ||
result, _ := pokeapi.PalParkArea("forest") | ||
assert.Equal(t, "forest", result.Name, | ||
"Expect to receive Forest.") | ||
} | ||
|
||
func TestPalParkAreaFail(t *testing.T) { | ||
result, _ := pokeapi.PalParkArea("asdf") | ||
assert.Equal(t, "", result.Name, | ||
"Expect to receive an empty result.") | ||
} | ||
|
||
func TestRegion(t *testing.T) { | ||
result, _ := pokeapi.Region("1") | ||
assert.Equal(t, "kanto", result.Name, | ||
"Expect to receive Kanto.") | ||
} | ||
|
||
func TestRegionByName(t *testing.T) { | ||
result, _ := pokeapi.Region("kanto") | ||
assert.Equal(t, "kanto", result.Name, | ||
"Expect to receive Kanto.") | ||
} | ||
|
||
func TestRegionFail(t *testing.T) { | ||
result, _ := pokeapi.Region("asdf") | ||
assert.Equal(t, "", result.Name, | ||
"Expect to receive an empty result.") | ||
} |