-
Notifications
You must be signed in to change notification settings - Fork 3
/
ProductOption_test.go
53 lines (44 loc) · 1.43 KB
/
ProductOption_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
51
52
53
package HologramGo
import (
"github.com/hologram-io/hologram-go"
"encoding/json"
"fmt"
"io/ioutil"
"testing"
)
// TODO: Add product options and categories.
func TestGetProductOptions(t *testing.T) {
file, e := ioutil.ReadFile("json/product_options.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 productOptions = (payload["data"].([]interface{}))
var productOption = (HologramGo.ProductOption)(productOptions[1].(map[string]interface{}))
// Check for expected product id
expectedFloat := (float64)(2)
returnedFloat := productOption.GetProductIdFromOption()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
expectedString := "5DASH"
returnedString := productOption.GetProductOptionAppendSku()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "0.00"
returnedString = productOption.GetProductOptionPriceChange()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "5 Dashes"
returnedString = productOption.GetProductOptionInvoiceDescription()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
}