diff --git a/modules/covid/cases_test.go b/modules/covid/cases_test.go new file mode 100644 index 00000000..bf12d70e --- /dev/null +++ b/modules/covid/cases_test.go @@ -0,0 +1,24 @@ +package covid + +import ( + "encoding/json" + "testing" +) + +func Test_CasesInclude(t *testing.T) { + // The api does not seem to return the correct recovered numbers + responseBody := `{"latest":{"confirmed":3093619,"deaths":73018,"recovered":0},"locations":[]}` + latestData := Cases{} + _ = json.Unmarshal([]byte(responseBody), &latestData) + expectedConfirmed := 3093619 + expectedDeaths := 73018 + actualConfirmed := latestData.Latest.Confirmed + actualDeaths := latestData.Latest.Deaths + + if expectedConfirmed != actualConfirmed { + t.Errorf("\nexpected: %v\n got: %v", expectedConfirmed, actualConfirmed) + } + if expectedDeaths != actualDeaths { + t.Errorf("\nexpected: %v\n got: %v", expectedDeaths, actualDeaths) + } +} diff --git a/modules/covid/client_test.go b/modules/covid/client_test.go deleted file mode 100644 index d6f46770..00000000 --- a/modules/covid/client_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package covid - -import ( - "testing" -) - -func TestLatestCases(t *testing.T) { - latestCasesToAssert, err := LatestCases() - if err != nil { - t.Error("LatestCases() returned an error") - } - if latestCasesToAssert.Latest.Confirmed == 0 { - t.Error("LatestCases() should return a non 0 integer") - } -} - -func (widget *Widget) TestCountryCases(t *testing.T) { - countryList := []string{"US", "FR"} - c := make([]interface{}, len(countryList)) - for i, v := range countryList { - c[i] = v - } - latestCountryCasesToAssert, err := widget.LatestCountryCases(c) - if err != nil { - t.Error("LatestCountryCases() returned an error") - } - if len(latestCountryCasesToAssert) == 0 { - t.Error("LatestCountryCases() should not be empty") - } - -}