-
Notifications
You must be signed in to change notification settings - Fork 3
/
Product_test.go
90 lines (74 loc) · 2.54 KB
/
Product_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package HologramGo
import (
"github.com/hologram-io/hologram-go"
"encoding/json"
"fmt"
"io/ioutil"
"testing"
)
// func TestGetProducts(t *testing.T) {
// file, e := ioutil.ReadFile("json/device.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")
// }
// var device = (HologramGo.Device)(payload["data"].(map[string]interface{}))
// // Check for expected device id
// expectedFloat := (float64)(1)
// returnedFloat := device.GetDeviceId()
// if expectedFloat != returnedFloat {
// t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
// }
// }
func TestGetProduct(t *testing.T) {
file, e := ioutil.ReadFile("json/product.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")
}
var product = (HologramGo.Product)(payload["data"].(map[string]interface{}))
// Check for expected product id
expectedFloat := (float64)(1)
returnedFloat := product.GetProductId()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
expectedString := "SIM"
returnedString := product.GetProductSku()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "SIM Card"
returnedString = product.GetProductName()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "The Hologram Global SIM Card. Comes in a variety of sizes for any application. (Pick your data plan when you go to activate the SIM.)"
returnedString = product.GetProductDescription()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "5.00"
returnedString = product.GetProductPrice()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "https://dashboard.hologram.io/img/sim_card.jpg"
returnedString = product.GetProductImageUrl()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
expectedString = "Global SIM Card"
returnedString = product.GetProductInvoiceDescription()
if expectedString != returnedString {
t.Fatalf("Expected %s, got %s", expectedString, returnedString)
}
}