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] - getChat #795

Open
tomsmith8 opened this issue Dec 19, 2024 · 3 comments
Open

[Unit Tests] - getChat #795

tomsmith8 opened this issue Dec 19, 2024 · 3 comments

Comments

@tomsmith8
Copy link

Unit Test Coverage for "getChat"


Stakwork Run


Unit Test Code


File: /tmp/stakwork/sphinx-tribes-frontend/src/store/chat.ts


package chat

import (
  "testing"

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

// Mock Chat structure
type Chat struct {
  ID   string
  Name string
}

// Mock ChatStore structure with a map to simulate the chats collection
type ChatStore struct {
  chats map[string]Chat
}

// Method to get a chat by ID
func (cs *ChatStore) getChat(id string) *Chat {
  if chat, exists := cs.chats[id]; exists {
  	return &chat
  }
  return nil
}

func TestGetChat(t *testing.T) {
  // Initialize a mock ChatStore with some data
  chatStore := &ChatStore{
  	chats: map[string]Chat{
  		"123":    {ID: "123", Name: "Chat 123"},
  		"ABC":    {ID: "ABC", Name: "Chat ABC"},
  		"5000":   {ID: "5000", Name: "Chat 5000"},
  		"チャット": {ID: "チャット", Name: "Unicode Chat"},
  	},
  }

  tests := []struct {
  	name     string
  	id       string
  	expected *Chat
  }{
  	{
  		name:     "Valid ID with Existing Chat",
  		id:       "123",
  		expected: &Chat{ID: "123", Name: "Chat 123"},
  	},
  	{
  		name:     "Valid ID with Non-Existing Chat",
  		id:       "999",
  		expected: nil,
  	},
  	{
  		name:     "Empty String ID",
  		id:       "",
  		expected: nil,
  	},
  	{
  		name:     "ID with Special Characters",
  		id:       "!@#$%^&*()",
  		expected: nil,
  	},
  	{
  		name:     "ID with Maximum Length",
  		id:       "a" + string(make([]byte, 255)),
  		expected: nil,
  	},
  	{
  		name:     "Case Sensitivity",
  		id:       "abc",
  		expected: nil,
  	},
  	{
  		name:     "Whitespace in ID",
  		id:       " 123 ",
  		expected: nil,
  	},
  	{
  		name:     "ID with Internal Whitespace",
  		id:       "12 3",
  		expected: nil,
  	},
  	{
  		name:     "ID with Unicode Characters",
  		id:       "チャット",
  		expected: &Chat{ID: "チャット", Name: "Unicode Chat"},
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		result := chatStore.getChat(tt.id)
  		assert.Equal(t, tt.expected, result)
  	})
  }
}
@aliraza556
Copy link
Contributor

@tomsmith8 assign me?

@MahtabBukhari
Copy link
Contributor

@tomsmith8 assign

@MuhammadUmer44
Copy link
Contributor

@humansinstitute 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

4 participants