-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote_test.go
93 lines (87 loc) · 2.43 KB
/
quote_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
91
92
93
package main
import (
"encoding/json"
"log"
"strings"
"testing"
)
const quoter = `{
"code": "1A",
"sumInsured": 12000,
"dateOfBirth" : "14/01/1977",
"premium": 3000,
"parties": [
{
"firstName": "Bhavesh",
"lastName": "Yadav",
"gender": "MALE",
"dateOfBirth": "14/01/1977",
"mobileNumber": "1234567890",
"email": "primary@gmail.com",
"panNumber": "AJBDD12345G",
"aadhaar": 123456789012,
"addressLine1": "ketaki",
"addressLine2": "maneklal",
"addressLine3": "Ghatkopar",
"city": "mumbai",
"pinCode": 400086,
"latitude": 123223232,
"longitude": 12345643,
"relationship": "self",
"isPrimary": true
},
{
"firstName": "Usha",
"lastName": "Patel",
"gender": "FEMALE",
"dateOfBirth": "14/01/1977",
"mobileNumber": "1234567890",
"email": "nominiee@gmail.com",
"panNumber": "AJBDD12345G",
"aadhaar": 123456789012,
"addressLine1": "ketaki",
"addressLine2": "maneklal",
"addressLine3": "Ghatkopar",
"city": "mumbai",
"pincode": 400086,
"latitude": 123223232,
"Longitude": 12345643,
"relationship": "self",
"IsPrimary": false
}
]
}`
func TestQuoteJsonMarshall(t *testing.T) {
body := strings.NewReader(quoter)
q := "ereq{}
err := json.NewDecoder(body).Decode(q)
if err == nil {
t.Errorf("error while unmarshalling %v", err)
}
log.Println(q)
}
func TestValidateReq(t *testing.T) {
var qreq = quotereq{Code: "1A", SumInsured: 123, DateOfBirth: "14/01/1977"}
var parties []*party
for i := range []int{1, 2} {
var party = &party{FirstName: "prashant", Email: "pras.p.in@gmail.com", PinCode: int32(i * 400086), MobileNumber: "asasaa"}
parties = append(parties, party)
}
qreq.Parties = parties
errors := validateReq(qreq)
if errors != nil {
t.Errorf("error in request %v", errors)
}
}
func TestQuoteFromDB(t *testing.T) {
quote, err := quoteFromDB("15")
if err != nil {
t.Errorf("quote not found %v", err)
}
if quote.Premium != 3000 {
t.Errorf("quote premium is %v and not 3000", quote.Premium)
}
if len(quote.Parties) != 2 {
t.Errorf("quote premium is %v and not 2", len(quote.Parties))
}
}