Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unit Tests] - orgUser #2209

Closed
tomsmith8 opened this issue Dec 17, 2024 · 2 comments
Closed

[Unit Tests] - orgUser #2209

tomsmith8 opened this issue Dec 17, 2024 · 2 comments

Comments

@tomsmith8
Copy link

Unit Test Coverage for "orgUser"


Stakwork Run


Unit Test Code


File:


package database

import (
  "testing"

  "github.com/stretchr/testify/assert"
  "github.com/stretchr/testify/mock"
)

// Mocking the Database and WorkspaceUsersData for testing
type MockDatabase struct {
  mock.Mock
}

func (m *MockDatabase) DeleteWorkspaceUser(orgUser db.WorkspaceUsersData, org string) db.WorkspaceUsersData {
  args := m.Called(orgUser, org)
  return args.Get(0).(db.WorkspaceUsersData)
}

func TestDeleteWorkspaceUser(t *testing.T) {
  mockDB := new(MockDatabase)

  tests := []struct {
  	name        string
  	orgUser     interface{}
  	org         interface{}
  	expected    db.WorkspaceUsersData
  	expectPanic bool
  }{
  	{
  		name:     "Standard Deletion",
  		orgUser:  db.WorkspaceUsersData{ID: "user1"},
  		org:      "org1",
  		expected: db.WorkspaceUsersData{ID: "user1"},
  	},
  	{
  		name:     "Empty Organization String",
  		orgUser:  db.WorkspaceUsersData{ID: "user2"},
  		org:      "",
  		expected: db.WorkspaceUsersData{ID: "user2"},
  	},
  	{
  		name:     "Minimal User Data",
  		orgUser:  db.WorkspaceUsersData{ID: "user3"},
  		org:      "org2",
  		expected: db.WorkspaceUsersData{ID: "user3"},
  	},
  	{
  		name:        "Null User Data",
  		orgUser:     nil,
  		org:         "org3",
  		expectPanic: true,
  	},
  	{
  		name:        "Invalid Data Type for Organization",
  		orgUser:     db.WorkspaceUsersData{ID: "user4"},
  		org:         12345,
  		expectPanic: true,
  	},
  	{
  		name:        "Invalid User Data Type",
  		orgUser:     "invalidUser",
  		org:         "org4",
  		expectPanic: true,
  	},
  	{
  		name:     "Large User Data",
  		orgUser:  db.WorkspaceUsersData{ID: "largeUser"},
  		org:      "org5",
  		expected: db.WorkspaceUsersData{ID: "largeUser"},
  	},
  	{
  		name:     "Non-Existent User",
  		orgUser:  db.WorkspaceUsersData{ID: "nonExistentUser"},
  		org:      "org6",
  		expected: db.WorkspaceUsersData{ID: "nonExistentUser"},
  	},
  	{
  		name:     "User with Special Characters",
  		orgUser:  db.WorkspaceUsersData{ID: "user!@#$"},
  		org:      "org7",
  		expected: db.WorkspaceUsersData{ID: "user!@#$"},
  	},
  	{
  		name:     "Case Sensitivity in Organization",
  		orgUser:  db.WorkspaceUsersData{ID: "user5"},
  		org:      "Org8",
  		expected: db.WorkspaceUsersData{ID: "user5"},
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		if tt.expectPanic {
  			assert.Panics(t, func() {
  				mockDB.DeleteWorkspaceUser(tt.orgUser.(db.WorkspaceUsersData), tt.org.(string))
  			})
  		} else {
  			mockDB.On("DeleteWorkspaceUser", tt.orgUser, tt.org).Return(tt.expected)
  			result := mockDB.DeleteWorkspaceUser(tt.orgUser.(db.WorkspaceUsersData), tt.org.(string))
  			assert.Equal(t, tt.expected, result)
  		}
  	})
  }
}
@aliraza556
Copy link
Contributor

@tomsmith8 assign me

@MahtabBukhari
Copy link
Contributor

@tomsmith8 Could you please assign me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants