Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Jul 20, 2023
1 parent c2f9245 commit 7097c00
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
8 changes: 4 additions & 4 deletions internal/controllers/user_devices_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (s *UserDevicesControllerTestSuite) TestGetMyUserDevices() {
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "F150", 2020, integration)
ud := test.SetupCreateUserDevice(s.T(), s.testUserID, dd[0].DeviceDefinitionId, nil, "", s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

addr := "67B94473D81D0cd00849D563C94d0432Ac988B49"
Expand Down Expand Up @@ -507,7 +507,7 @@ func (s *UserDevicesControllerTestSuite) TestGetMyUserDevicesNoDuplicates() {
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "F150", 2020, integration)
ud := test.SetupCreateUserDeviceWithDeviceID(s.T(), userID, deviceID, dd[0].DeviceDefinitionId, nil, "", s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), userID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), userID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

addr := "67B94473D81D0cd00849D563C94d0432Ac988B49"
Expand Down Expand Up @@ -650,7 +650,7 @@ func (s *UserDevicesControllerTestSuite) TestNameValidate() {
func (s *UserDevicesControllerTestSuite) TestPatchName() {
ud := test.SetupCreateUserDevice(s.T(), s.testUserID, ksuid.New().String(), nil, "", s.pdb)
deviceID := uuid.New().String()
apunit := test.SetupCreateAftermarketDevice(s.T(), s.testUserID, uuid.NewString(), &deviceID, s.pdb)
apunit := test.SetupCreateAftermarketDevice(s.T(), s.testUserID, nil, uuid.NewString(), &deviceID, s.pdb)
autoPiIntID := ksuid.New().String()
vehicleID := 3214
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), apunit.Serial, deviceID, ud.ID, autoPiIntID, s.pdb)
Expand Down Expand Up @@ -804,7 +804,7 @@ func (s *UserDevicesControllerTestSuite) TestGetRange() {
ddID := ksuid.New().String()
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
smartCarIntegration := test.BuildIntegrationGRPC(constants.SmartCarVendor, 10, 0)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, autoPiUnitID, &autoPiDeviceID, s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, autoPiUnitID, &autoPiDeviceID, s.pdb)

gddir := []*grpc.GetDeviceDefinitionItemResponse{
{
Expand Down
30 changes: 15 additions & 15 deletions internal/controllers/user_integrations_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPostAutoPiBlockedForDuplicateD
deviceID = "1dd96159-3bb2-9472-91f6-72fe9211cfeb"
unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

req := fmt.Sprintf(`{
Expand Down Expand Up @@ -564,7 +564,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPostAutoPiBlockedForDuplicateD
deviceID = "1dd96159-3bb2-9472-91f6-72fe9211cfeb"
unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
// test user
ud2 := test.SetupCreateUserDevice(s.T(), testUser2, dd[0].DeviceDefinitionId, nil, "", s.pdb)

Expand Down Expand Up @@ -594,7 +594,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -632,7 +632,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: true,
UnitID: unitID,
Expand Down Expand Up @@ -667,7 +667,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -703,7 +703,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -770,23 +770,23 @@ func (s *UserIntegrationsControllerTestSuite) TestPairAftermarketNoLegacy() {
}
s.Require().NoError(vnft.Insert(s.ctx, s.pdb.DBS().Writer, boil.Infer()))

apUnit := test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, &deviceID, s.pdb)
apUnit.TokenID = types.NewNullDecimal(decimal.New(5, 0))
apUnit.EthereumAddress = common.BigToAddress(big.NewInt(2)).Bytes()
apUnit.OwnerAddress = null.BytesFrom(userAddr.Bytes())
_, err = apUnit.Update(s.ctx, s.pdb.DBS().Writer, boil.Infer())
s.Require().NoError(err)
aftermarketDevice := test.SetupCreateAftermarketDevice(s.T(), testUserID, common.BigToAddress(big.NewInt(2)).Bytes(), unitID, &deviceID, s.pdb)
aftermarketDevice.TokenID = types.NewNullDecimal(decimal.New(5, 0))
aftermarketDevice.OwnerAddress = null.BytesFrom(userAddr.Bytes())
row, errAMD := aftermarketDevice.Update(s.ctx, s.pdb.DBS().Writer, boil.Infer())
s.Assert().Equal(int64(1), row)
s.Require().NoError(errAMD)

app := fiber.New()
app.Use(test.AuthInjectorTestHandler(userID))
app.Get("/:userDeviceID/pair", c.GetAutoPiPairMessage)
app.Post("/:userDeviceID/pair", c.PostPairAutoPi)

req := test.BuildRequest("GET", "/"+ud.ID+"/pair?external_id="+unitID, "")
req := test.BuildRequest("GET", "/"+ud.ID+"/pair?external_id="+aftermarketDevice.Serial, "")

res, err := app.Test(req)
s.Require().NoError(err)
s.Require().Equal(fiber.StatusOK, res.Status) // todo issue - this is returning 409 instead of 200? due to change in how get unit?
s.Require().Equal(fiber.StatusOK, res.StatusCode) // todo issue - this is returning 409 instead of 200? due to change in how get unit?
defer res.Body.Close()

var td signer.TypedData
Expand All @@ -800,7 +800,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPairAftermarketNoLegacy() {
userSig[64] += 27

in := map[string]any{
"externalId": apUnit.Serial,
"externalId": aftermarketDevice.Serial,
"signature": hexutil.Bytes(userSig).String(),
}

Expand Down
2 changes: 1 addition & 1 deletion internal/services/autopi_api_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *AutoPiAPIServiceTestSuite) TestCommandRaw() {
apiURL = "https://mock.town"
jobID = "321"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
// http client mock
httpmock.Activate()
defer httpmock.DeactivateAndReset()
Expand Down
7 changes: 4 additions & 3 deletions internal/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ func SetupCreateUserDeviceWithDeviceID(t *testing.T, testUserID string, deviceID
return ud
}

func SetupCreateAftermarketDevice(t *testing.T, userID, unitID string, deviceID *string, pdb db.Store) *models.AftermarketDevice {
func SetupCreateAftermarketDevice(t *testing.T, userID string, bytes []byte, unitID string, deviceID *string, pdb db.Store) *models.AftermarketDevice {
amd := models.AftermarketDevice{
Serial: unitID,
UserID: null.StringFrom(userID),
EthereumAddress: bytes, // pkey
Serial: unitID,
UserID: null.StringFrom(userID),
}
if deviceID != nil {
amdMD := map[string]any{"autoPiDeviceId": *deviceID}
Expand Down

0 comments on commit 7097c00

Please sign in to comment.