Skip to content

Commit

Permalink
fix(api): leave namespace endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
heiytor committed Nov 6, 2024
1 parent 2d8dae4 commit 7aa2a5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/routes/nsadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const (
GetNamespaceURL = "/namespaces/:tenant"
DeleteNamespaceURL = "/namespaces/:tenant"
EditNamespaceURL = "/namespaces/:tenant"
LeaveNamespaceURL = "/namespaces/:tenant/members"
AddNamespaceMemberURL = "/namespaces/:tenant/members"
RemoveNamespaceMemberURL = "/namespaces/:tenant/members/:uid"
LeaveNamespaceURL = "/namespaces/members"
EditNamespaceMemberURL = "/namespaces/:tenant/members/:uid"
GetSessionRecordURL = "/users/security"
EditSessionRecordStatusURL = "/users/security/:tenant"
Expand Down
12 changes: 7 additions & 5 deletions api/routes/nsadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,16 @@ func TestHandler_LeaveNamespace(t *testing.T) {

cases := []struct {
description string
tenantID string
headers map[string]string
requiredMocks func()
expected int
}{
{
description: "fails to leave the namespace",
tenantID: "00000000-0000-4000-0000-000000000000",
headers: map[string]string{
"X-ID": "000000000000000000000000",
"X-Tenant-ID": "00000000-0000-4000-0000-000000000000",
"X-ID": "000000000000000000000000",
},
requiredMocks: func() {
svcMock.
Expand All @@ -421,6 +422,7 @@ func TestHandler_LeaveNamespace(t *testing.T) {
},
{
description: "success to leave the namespace",
tenantID: "00000000-0000-4000-0000-000000000000",
headers: map[string]string{
"X-ID": "000000000000000000000000",
"X-Tenant-ID": "00000000-0000-4000-0000-000000000000",
Expand All @@ -436,10 +438,10 @@ func TestHandler_LeaveNamespace(t *testing.T) {
}

for _, tc := range cases {
t.Run(tc.description, func(t *testing.T) {
t.Run(tc.description, func(tt *testing.T) {
tc.requiredMocks()

req := httptest.NewRequest(http.MethodDelete, "/api/namespaces/members", nil)
req := httptest.NewRequest(http.MethodDelete, "/api/namespaces/"+tc.tenantID+"/members", nil)
for k, v := range tc.headers {
req.Header.Set(k, v)
}
Expand All @@ -449,7 +451,7 @@ func TestHandler_LeaveNamespace(t *testing.T) {
e := NewRouter(svcMock)
e.ServeHTTP(rec, req)

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/requests/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type NamespaceRemoveMember struct {

type LeaveNamespace struct {
UserID string `header:"X-ID" validate:"required"`
TenantID string `header:"X-Tenant-ID" validate:"required,uuid"`
TenantID string `param:"tenant" validate:"required,uuid"`
}

// SessionEditRecordStatus is the structure to represent the request data for edit session record status endpoint.
Expand Down

0 comments on commit 7aa2a5e

Please sign in to comment.