-
Notifications
You must be signed in to change notification settings - Fork 3
/
ProductCategory_test.go
50 lines (40 loc) · 1.3 KB
/
ProductCategory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package HologramGo
import (
"github.com/hologram-io/hologram-go"
"encoding/json"
"fmt"
"io/ioutil"
"testing"
)
func TestGetProductCategories(t *testing.T) {
file, e := ioutil.ReadFile("json/product_categories.json")
if e != nil {
fmt.Printf("Error opening file: %v\n", e)
}
var payload = HologramGo.Placeholder{}
err := json.Unmarshal(file, &payload)
if err != nil {
fmt.Println("Unable to parse file")
}
// Test the first product
var productCategories = (payload["data"].([]interface{}))
var productCategory = (HologramGo.ProductCategory)(productCategories[0].(map[string]interface{}))
// Check for expected category.
expectedString := "accessories"
returnedString := productCategory.GetProductCategoryName()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
// Check for expected category.
//expectedIntSlice := []int{15, 19, 11, 10, 9, 8, 7, 23}
//returnedIntSlice := productCategory.GetProductIdsFromCategory()
//// Length check
//if len(expectedIntSlice) != len(returnedIntSlice) {
// t.Fatalf("Expected length %s, got %s", expectedString, returnedString)
//}
//for i := range expectedIntSlice {
// if expectedIntSlice[i] != returnedIntSlice[i] {
// t.Fatalf("Expected %s, got %s", expectedString, returnedString)
// }
//}
}