github.com/seeker-insurance/kit@v0.0.13/address/address_test.go (about) 1 package address 2 3 import ( 4 "reflect" 5 "testing" 6 7 "googlemaps.github.io/maps" 8 "gopkg.in/mgo.v2/bson" 9 ) 10 11 func TestFromFactualRecord(t *testing.T) { 12 type args struct { 13 factualRecord bson.M 14 } 15 tests := []struct { 16 name string 17 args args 18 want Address 19 }{ 20 {"hell", args{hellFactualRecord}, hellAddress}, 21 } 22 for _, tt := range tests { 23 t.Run(tt.name, func(t *testing.T) { 24 if got := FromFactualRecord(tt.args.factualRecord); !reflect.DeepEqual(got, tt.want) { 25 t.Errorf("FromFactualRecord() = %v, want %v", got, tt.want) 26 } 27 }) 28 } 29 } 30 31 func TestAddress_String(t *testing.T) { 32 tests := []struct { 33 name string 34 arg Address 35 want string 36 }{ 37 {"hell", hellAddress, "1 S Hell St, #666, Newark, NJ, 66666, us"}, 38 } 39 for _, tt := range tests { 40 t.Run(tt.name, func(t *testing.T) { 41 if got := tt.arg.String(); got != tt.want { 42 t.Errorf("Address.String() = %v, want %v", got, tt.want) 43 } 44 }) 45 } 46 } 47 48 func TestAddress_filterOutComponentsMissingFromReciever(t *testing.T) { 49 type args struct { 50 b Address 51 } 52 tests := []struct { 53 name string 54 reciever Address 55 arg Address 56 want Address 57 }{ 58 {"copy", heavenAddress, hellAddress, hellWithHeavenFieldsOnly}, 59 } 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 argCopy := tt.arg 63 a := tt.reciever 64 if got := a.filterOutComponentsMissingFromReciever(tt.arg); !reflect.DeepEqual(got, tt.want) { 65 t.Errorf("Address.filterOutComponentsMissingFromReciever() = %v, want %v", got, tt.want) 66 } 67 if !reflect.DeepEqual(tt.arg, argCopy) { 68 t.Errorf("should not modify %v", tt.arg) 69 } 70 }) 71 } 72 } 73 74 var hellFactualRecord = bson.M{ 75 "address": "1 S Hell St", 76 "existence": "0.7", 77 "admin_region": nil, 78 "postcode": "66666", 79 "email": "fakeplace@fake.com", 80 "hours_display": nil, 81 "post_town": nil, 82 "name": "TEST DATABSE", 83 "address_extended": "#666", 84 "created_at": `ISODate("2017-09-06T19:18:19.185Z")`, 85 "chain_id": nil, 86 "po_box": nil, 87 "fax": nil, 88 "source": "factual", 89 "matched": false, 90 "hours": nil, 91 "locality": "Newark", 92 "country": "us", 93 "region": "NJ", 94 "chain_name": nil, 95 "tel": "(312) 427-4410", 96 "latitude": 666, 97 "longitude": 666, 98 } 99 100 var hellAddress = Address{ 101 Street: "1 S Hell St", 102 Extension: "#666", 103 POBox: "", 104 Locality: "Newark", 105 Region: "NJ", 106 PostalCode: "66666", 107 Country: "us", 108 } 109 110 var heavenAddress = Address{ 111 Street: "1 N Heaven St", 112 Extension: "#18", 113 Locality: "San Diego", 114 Region: "CA", 115 Country: "us", 116 } 117 118 var hellWithHeavenFieldsOnly = Address{ 119 Street: "1 S Hell St", 120 Extension: "#666", 121 Locality: "Newark", 122 Region: "NJ", 123 Country: "us", 124 } 125 126 func TestFromGoogleAddressComponents(t *testing.T) { 127 type args struct { 128 components []maps.AddressComponent 129 } 130 tests := []struct { 131 name string 132 args args 133 wantAddress Address 134 }{ 135 // TODO: Add test cases. 136 } 137 for _, tt := range tests { 138 t.Run(tt.name, func(t *testing.T) { 139 if gotAddress := FromGoogleAddressComponents(tt.args.components); !reflect.DeepEqual(gotAddress, tt.wantAddress) { 140 t.Errorf("FromGoogleAddressComponents() = %v, want %v", gotAddress, tt.wantAddress) 141 } 142 }) 143 } 144 }