Skip to content

Commit

Permalink
update route, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Jul 24, 2023
1 parent 864112e commit fb5d98b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
amdOwnerMw := owner.AftermarketDevice(pdb, usersClient, &logger)
apOwner := v1Auth.Group("/autopi/unit/:serial", amdOwnerMw)
// same as above but AftermarketDevice
amdOwner := v1Auth.Group("/aftermarket/device/hw/:serial", amdOwnerMw)
amdOwner := v1Auth.Group("/aftermarket/device/by-serial/:serial", amdOwnerMw)

apOwner.Get("/", userDeviceController.GetAutoPiUnitInfo)
amdOwner.Get("/", userDeviceController.GetAutoPiUnitInfo)
Expand Down
10 changes: 5 additions & 5 deletions docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"basePath": "/v1",
"paths": {
"/aftermarket/device/hw/:serial": {
"/aftermarket/device/by-serial/:serial": {
"get": {
"security": [
{
Expand Down Expand Up @@ -40,7 +40,7 @@
}
}
},
"/aftermarket/device/hw/:serial/commands/claim": {
"/aftermarket/device/by-serial/:serial/commands/claim": {
"get": {
"security": [
{
Expand Down Expand Up @@ -104,7 +104,7 @@
}
}
},
"/aftermarket/device/hw/:serial/commands/unclaim": {
"/aftermarket/device/by-serial/:serial/commands/unclaim": {
"post": {
"security": [
{
Expand All @@ -131,7 +131,7 @@
}
}
},
"/aftermarket/device/hw/:serial/update": {
"/aftermarket/device/by-serial/:serial/update": {
"post": {
"security": [
{
Expand Down
8 changes: 4 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ paths:
description: Not Found
tags:
- nfts
/aftermarket/device/hw/:serial:
/aftermarket/device/by-serial/:serial:
get:
description: gets the information about the aftermarket device by the hw serial
parameters:
Expand All @@ -1046,7 +1046,7 @@ paths:
- BearerAuth: []
tags:
- integrations
/aftermarket/device/hw/:serial/commands/claim:
/aftermarket/device/by-serial/:serial/commands/claim:
get:
description: Return the EIP-712 payload to be signed for Aftermarket device
claiming.
Expand Down Expand Up @@ -1087,7 +1087,7 @@ paths:
description: No Content
security:
- BearerAuth: []
/aftermarket/device/hw/:serial/commands/unclaim:
/aftermarket/device/by-serial/:serial/commands/unclaim:
post:
description: |-
Dev-only endpoint for removing a claim. Removes the flag on-chain and clears
Expand All @@ -1105,7 +1105,7 @@ paths:
description: No Content
security:
- BearerAuth: []
/aftermarket/device/hw/:serial/update:
/aftermarket/device/by-serial/:serial/update:
post:
description: checks to see if aftermarket device needs to be updated, and starts
update process if so.
Expand Down
10 changes: 5 additions & 5 deletions internal/controllers/user_integrations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (udc *UserDevicesController) OpenFrunk(c *fiber.Ctx) error {
// @Param serial path string true "autopi unit id or macaron serial"
// @Success 200 {object} controllers.AutoPiDeviceInfo
// @Security BearerAuth
// @Router /aftermarket/device/hw/:serial [get]
// @Router /aftermarket/device/by-serial/:serial [get]
func (udc *UserDevicesController) GetAutoPiUnitInfo(c *fiber.Ctx) error {
const minimumAutoPiRelease = "v1.22.8" // correct semver has leading v

Expand Down Expand Up @@ -567,7 +567,7 @@ func (udc *UserDevicesController) GetAutoPiUnitInfo(c *fiber.Ctx) error {
// @Param serial path string true "autopi unit id", ie. physical barcode
// @Success 200 {object} services.AutoPiTask
// @Security BearerAuth
// @Router /aftermarket/device/hw/:serial/update [post]
// @Router /aftermarket/device/by-serial/:serial/update [post]
func (udc *UserDevicesController) StartAutoPiUpdateTask(c *fiber.Ctx) error {
unitID := c.Locals("serial").(string)
userID := helpers.GetUserID(c)
Expand Down Expand Up @@ -610,7 +610,7 @@ func (udc *UserDevicesController) StartAutoPiUpdateTask(c *fiber.Ctx) error {
// @Param serial path string true "AutoPi unit id"
// @Success 200 {object} signer.TypedData
// @Security BearerAuth
// @Router /aftermarket/device/hw/:serial/commands/claim [get]
// @Router /aftermarket/device/by-serial/:serial/commands/claim [get]
func (udc *UserDevicesController) GetAutoPiClaimMessage(c *fiber.Ctx) error {
userID := helpers.GetUserID(c)

Expand Down Expand Up @@ -1340,7 +1340,7 @@ type AutoPiPairRequest struct {
// @Param serial path string true "AutoPi unit id"
// @Success 204
// @Security BearerAuth
// @Router /aftermarket/device/hw/:serial/commands/unclaim [post]
// @Router /aftermarket/device/by-serial/:serial/commands/unclaim [post]
func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error {
userID := helpers.GetUserID(c)
unitID := c.Params("serial")
Expand Down Expand Up @@ -1394,7 +1394,7 @@ func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error {
// @Param claimRequest body controllers.AutoPiClaimRequest true "Signatures from the user and AutoPi"
// @Success 204
// @Security BearerAuth
// @Router /aftermarket/device/hw/:serial/commands/claim [post]
// @Router /aftermarket/device/by-serial/:serial/commands/claim [post]
func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error {
userID := helpers.GetUserID(c)
unitID := c.Params("serial")
Expand Down
17 changes: 9 additions & 8 deletions internal/controllers/user_integrations_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
logger := zerolog.Nop()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
Expand All @@ -608,7 +608,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
}, nil)

// act
request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "")
request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "")
response, err := app.Test(request)
require.NoError(s.T(), err)
// assert
Expand All @@ -629,7 +629,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate()
c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
logger := zerolog.Nop()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
Expand All @@ -646,7 +646,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate()
}, nil)

// act
request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "")
request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "")
response, err := app.Test(request)
require.NoError(s.T(), err)
// assert
Expand All @@ -664,7 +664,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda
c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
logger := zerolog.Nop()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
Expand All @@ -681,7 +681,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda
}, nil)

// act
request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "")
request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "")
response, err := app.Test(request)
require.NoError(s.T(), err)
// assert
Expand All @@ -692,6 +692,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda
assert.Equal(s.T(), "1.23.1", gjson.GetBytes(body, "releaseVersion").String())
assert.Equal(s.T(), false, gjson.GetBytes(body, "shouldUpdate").Bool())
}

func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpdate_Semver() {
// as of jun 12 23, versions are now correctly semverd starting with "v", so test for this too
const environment = "prod" // shouldUpdate only applies in prod
Expand All @@ -700,7 +701,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
logger := zerolog.Nop()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
Expand All @@ -717,7 +718,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
}, nil)

// act
request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "")
request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "")
response, err := app.Test(request)
require.NoError(s.T(), err)
// assert
Expand Down

0 comments on commit fb5d98b

Please sign in to comment.