Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions openapi/spec/cloud-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ paths:
$ref: paths/admin@api@devices.yaml
/admin/api/devices/{uid}:
$ref: paths/admin@api@devices@{uid}.yaml
/admin/api/devices/{uid}/{status}:
$ref: paths/admin@api@devices@{uid}@{status}.yaml
/admin/api/firewall/rules:
$ref: paths/admin@api@firewall@rules.yaml
/admin/api/firewall/rules/{id}:
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions openapi/spec/components/schemas/deviceStatusAction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: Status change to apply to a device
type: string
enum:
- accept
- reject
- pending
example: accept
2 changes: 0 additions & 2 deletions openapi/spec/enterprise-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ paths:
$ref: paths/admin@api@devices.yaml
/admin/api/devices/{uid}:
$ref: paths/admin@api@devices@{uid}.yaml
/admin/api/devices/{uid}/{status}:
$ref: paths/admin@api@devices@{uid}@{status}.yaml
/admin/api/firewall/rules:
$ref: paths/admin@api@firewall@rules.yaml
/admin/api/firewall/rules/{id}:
Expand Down
2 changes: 0 additions & 2 deletions openapi/spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ paths:
$ref: paths/admin@api@devices.yaml
/admin/api/devices/{uid}:
$ref: paths/admin@api@devices@{uid}.yaml
/admin/api/devices/{uid}/{status}:
$ref: paths/admin@api@devices@{uid}@{status}.yaml
/admin/api/firewall/rules:
$ref: paths/admin@api@firewall@rules.yaml
/admin/api/firewall/rules/{id}:
Expand Down
27 changes: 0 additions & 27 deletions openapi/spec/paths/admin@api@devices@{uid}@{status}.yaml

This file was deleted.

8 changes: 1 addition & 7 deletions openapi/spec/paths/api@containers@{uid}@{status}.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ patch:
- name: status
description: Container's status
schema:
type: string
enum:
- accept
- reject
- pending
- unused
example: accept
$ref: ../components/schemas/deviceStatusAction.yaml
required: true
in: path
responses:
Expand Down
8 changes: 1 addition & 7 deletions openapi/spec/paths/api@devices@{uid}@{status}.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ patch:
- name: status
description: Device's status
schema:
type: string
enum:
- accept
- reject
- pending
- unused
example: accept
$ref: ../components/schemas/deviceStatusAction.yaml
required: true
in: path
responses:
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/requests/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type DeviceLookup struct {
type DeviceUpdateStatus struct {
TenantID string `header:"X-Tenant-ID"`
UID string `param:"uid" validate:"required"`
Status string `param:"status" validate:"required,oneof=accepted pending rejected"`
Status string `param:"status" validate:"required"`
}

// DeviceCreateTag is the structure to represent the request data for device create tag endpoint.
Expand Down
1 change: 0 additions & 1 deletion server/api/routes/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func (h *Handler) UpdateDeviceStatus(c *gateway.Context) error {
"accept": string(models.DeviceStatusAccepted),
"reject": string(models.DeviceStatusRejected),
"pending": string(models.DeviceStatusPending),
"unused": string(models.DeviceStatusUnused),
}

req.Status = status[req.Status]
Expand Down
66 changes: 66 additions & 0 deletions server/api/routes/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,72 @@ func TestRenameDevice(t *testing.T) {
}
}

func TestUpdateDeviceStatus(t *testing.T) {
cases := []struct {
title string
path string
expectedStatus models.DeviceStatus
expectedCode int
}{
{
title: "accept sets the device accepted",
path: "/api/devices/uid/accept",
expectedStatus: models.DeviceStatusAccepted,
expectedCode: http.StatusOK,
},
{
title: "reject sets the device rejected",
path: "/api/devices/uid/reject",
expectedStatus: models.DeviceStatusRejected,
expectedCode: http.StatusOK,
},
{
title: "pending sets the device pending",
path: "/api/devices/uid/pending",
expectedStatus: models.DeviceStatusPending,
expectedCode: http.StatusOK,
},
{
title: "the container route sets the device accepted",
path: "/api/containers/uid/accept",
expectedStatus: models.DeviceStatusAccepted,
expectedCode: http.StatusOK,
},
{
title: "unused is rejected",
path: "/api/devices/uid/unused",
expectedCode: http.StatusBadRequest,
},
{
title: "a model status is rejected",
path: "/api/devices/uid/accepted",
expectedCode: http.StatusBadRequest,
},
}

for _, tc := range cases {
t.Run(tc.title, func(t *testing.T) {
mock := mocks.NewMockService(t)
if tc.expectedStatus != "" {
mock.On("UpdateDeviceStatus", gomock.Anything, &requests.DeviceUpdateStatus{
TenantID: "tenant-id",
UID: "uid",
Status: string(tc.expectedStatus),
}).Return(nil).Once()
}

req := httptest.NewRequestWithContext(t.Context(), http.MethodPatch, tc.path, nil)
req.Header.Set("X-Role", authorizer.RoleOwner.String())
req.Header.Set("X-Tenant-ID", "tenant-id")
rec := httptest.NewRecorder()

NewRouter(mock).ServeHTTP(rec, req)

assert.Equal(t, tc.expectedCode, rec.Result().StatusCode)
})
}
}

func TestGetDeviceList(t *testing.T) {
mock := mocks.NewMockService(t)

Expand Down
Loading