Files
cloud-services/pkg/common/mobile_tx_test.go

205 lines
4.4 KiB
Go

package common_test
import (
"testing"
"time"
"github.com/fiskerinc/cloud-services/pkg/common"
"github.com/fiskerinc/cloud-services/pkg/common/dbbasemodel"
"github.com/fiskerinc/cloud-services/pkg/testhelper"
"github.com/google/uuid"
"github.com/fiskerinc/cloud-services/pkg/utils/elptr"
)
func TestMobileTXMessages(t *testing.T) {
schema := "file://" + testhelper.GetSchemaDirPath() + "/mobile/TXMessage.json"
now := time.Now()
tests := []testhelper.SchemaTest{
{
Name: "TestTRexRemoteCommand",
Object: common.Message{
Handler: "remote_command",
Data: common.RemoteCommandRequest{
VIN: "1F15K3R45N1234567",
RemoteCommandSource: common.RemoteCommandSource{
Command: "temp_cabin",
Data: elptr.ElPtr("20"),
Start: elptr.ElPtr(time.Date(
2020, 1, 1,
0, 0, 0, 0, time.UTC)),
End: elptr.ElPtr(time.Date(
2020, 1, 1,
0, 0, 0, 0, time.UTC)),
},
},
},
},
{
Name: "TestMobileCarLocationsRequest",
Object: common.Message{
Handler: "car_locations",
Data: nil,
},
},
{
Name: "TestMobileDigitalTwinRequest",
Object: common.Message{
Handler: "digital_twin",
Data: common.DigitalTwinRequest{
VIN: "1F15K3R45N1234567",
},
},
},
{
Name: "TestMobileMapDestinationRequest",
Object: common.Message{
Handler: "map_destination",
Data: common.MapDestinationRequest{
VIN: "1F15K3R45N1234567",
Name: "Fisker Inc",
Address: &common.TomTomAddress{
StreetNumber: "3030",
StreetName: "17th St",
LocalName: "San Francisco",
PostalCode: "94110",
CountrySubdivisionName: "California",
CountryCodeIso3: "USA",
},
Coordinates: common.MapCoordinates{
Latitude: 37.0,
Longitude: -122.0,
},
},
},
},
{
Name: "TestMobileMapRouteRequest",
Object: common.Message{
Handler: "map_route",
Data: common.MapRouteRequest{
VIN: "1F15K3R45N1234567",
Waypoints: []common.MapWaypoint{
{
Type: "Restaurant",
Title: "Test Restaurant",
MapCoordinates: common.MapCoordinates{
Latitude: 111,
Longitude: 222,
},
},
{
Type: "Park",
Title: "Test Park",
MapCoordinates: common.MapCoordinates{
Latitude: 333.333,
Longitude: 444.444,
},
},
},
Route: []common.MapCoordinates{
{
Latitude: 123,
Longitude: 456,
},
{
Latitude: 999,
Longitude: 888,
},
},
},
},
},
{
Name: "TestMobileProfilesRequest",
Object: common.Message{
Handler: "profiles",
Data: nil,
},
},
{
Name: "TestMobileSettingsUpdate",
Object: common.Message{
Handler: "settings_update",
Data: common.MobileSettingsUpdate{
VIN: "1F15K3R45N1234567",
Settings: []common.CarSetting{{
Name: "TESTSETTING",
Value: "TESTVALUE",
Type: "string",
DBModelBase: dbbasemodel.DBModelBase{
UpdatedAt: &now,
},
}},
},
},
},
{
Name: "TestStoreInventoryRequest",
Object: common.Message{
Handler: "store_inventory",
Data: nil,
},
},
{
Name: "TestMobileStorePurchase",
Object: common.Message{
Handler: "store_purchase",
Data: common.StorePurchases{
VIN: "1F15K3R45N1234567",
Purchases: []common.StorePurchaseItem{{
ID: uuid.New(),
}},
},
},
},
{
Name: "TestHMIPOIs",
Object: common.Message{
Handler: "user_pois_get",
},
},
{
Name: "TestHMIPOICreate",
Object: common.Message{
Handler: "user_poi_create",
Data: common.PointOfInterest{
Name: "TestPOI",
Location: common.POILocation{
Latitude: 1.23,
Longitude: 4.56,
},
},
},
},
{
Name: "TestMobilePOIEdit",
Object: common.Message{
Handler: "user_poi_edit",
Data: common.MobilePOIEditMessage{
OldName: "TestPOI",
UserPOI: common.PointOfInterest{
Name: "TestPOI",
Location: common.POILocation{
Latitude: 8.88,
Longitude: 9.99,
},
},
},
},
},
{
Name: "TestMobilePOIDelete",
Object: common.Message{
Handler: "user_poi_delete",
Data: common.MobilePOIDeleteMessage{
Name: "TestPOI",
},
},
},
}
testhelper.NewSchemaTestHelper(t, schema).
RunSchemaTests(tests)
}