mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools
Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
* GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
* GET /api/v1/users/me/organizations - User organizations
* POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue
API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules
Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
178 lines
5.3 KiB
Go
178 lines
5.3 KiB
Go
package repository_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"bugulma/backend/internal/testutils"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
"gorm.io/gorm"
|
|
|
|
"bugulma/backend/internal/domain"
|
|
"bugulma/backend/internal/repository"
|
|
)
|
|
|
|
type SiteRepositoryTestSuite struct {
|
|
suite.Suite
|
|
db *gorm.DB
|
|
repo domain.SiteRepository
|
|
orgRepo domain.OrganizationRepository
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) SetupTest() {
|
|
// Setup PostgreSQL test database using pgtestdb
|
|
suite.db = testutils.SetupTestDB(suite.T())
|
|
suite.repo = repository.NewSiteRepository(suite.db)
|
|
suite.orgRepo = repository.NewOrganizationRepository(suite.db)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TearDownTest() {
|
|
// pgtestdb automatically cleans up the database after each test
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestCreate() {
|
|
// Create organization first
|
|
org := &domain.Organization{ID: "org-1", Name: "Test Organization"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org))
|
|
|
|
site := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Test Site",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
|
|
err := suite.repo.Create(context.Background(), site)
|
|
assert.NoError(suite.T(), err)
|
|
|
|
// Verify
|
|
found, err := suite.repo.GetByID(context.Background(), "site-1")
|
|
assert.NoError(suite.T(), err)
|
|
assert.Equal(suite.T(), "Test Site", found.Name)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestGetByID() {
|
|
// Create organization first
|
|
org := &domain.Organization{ID: "org-1", Name: "Test Organization"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org))
|
|
|
|
site := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Test Site",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
err := suite.repo.Create(context.Background(), site)
|
|
suite.Require().NoError(err)
|
|
|
|
found, err := suite.repo.GetByID(context.Background(), "site-1")
|
|
assert.NoError(suite.T(), err)
|
|
assert.Equal(suite.T(), "Test Site", found.Name)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestGetByOrganizationID() {
|
|
// Create organizations first
|
|
org1 := &domain.Organization{ID: "org-1", Name: "Test Organization 1"}
|
|
org2 := &domain.Organization{ID: "org-2", Name: "Test Organization 2"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org1))
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org2))
|
|
|
|
site1 := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Site 1",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
site2 := &domain.Site{
|
|
ID: "site-2",
|
|
Name: "Site 2",
|
|
Latitude: 52.53,
|
|
Longitude: 13.406,
|
|
OwnerOrganizationID: "org-2",
|
|
}
|
|
err := suite.repo.Create(context.Background(), site1)
|
|
suite.Require().NoError(err)
|
|
err = suite.repo.Create(context.Background(), site2)
|
|
suite.Require().NoError(err)
|
|
|
|
sites, err := suite.repo.GetByOrganizationID(context.Background(), "org-1")
|
|
assert.NoError(suite.T(), err)
|
|
assert.Len(suite.T(), sites, 1)
|
|
assert.Equal(suite.T(), "Site 1", sites[0].Name)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestGetWithinRadius() {
|
|
// Create organization first
|
|
org := &domain.Organization{ID: "org-1", Name: "Test Organization"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org))
|
|
|
|
site1 := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Site 1",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
err := suite.repo.Create(context.Background(), site1)
|
|
suite.Require().NoError(err)
|
|
|
|
sites, err := suite.repo.GetWithinRadius(context.Background(), 52.52, 13.405, 10)
|
|
assert.NoError(suite.T(), err)
|
|
assert.Len(suite.T(), sites, 1)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestUpdate() {
|
|
// Create organization first
|
|
org := &domain.Organization{ID: "org-1", Name: "Test Organization"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org))
|
|
|
|
site := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Test Site",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
err := suite.repo.Create(context.Background(), site)
|
|
suite.Require().NoError(err)
|
|
|
|
site.Name = "Updated Site"
|
|
err = suite.repo.Update(context.Background(), site)
|
|
assert.NoError(suite.T(), err)
|
|
|
|
found, err := suite.repo.GetByID(context.Background(), "site-1")
|
|
assert.NoError(suite.T(), err)
|
|
assert.Equal(suite.T(), "Updated Site", found.Name)
|
|
}
|
|
|
|
func (suite *SiteRepositoryTestSuite) TestDelete() {
|
|
// Create organization first
|
|
org := &domain.Organization{ID: "org-1", Name: "Test Organization"}
|
|
suite.Require().NoError(suite.orgRepo.Create(context.Background(), org))
|
|
|
|
site := &domain.Site{
|
|
ID: "site-1",
|
|
Name: "Test Site",
|
|
Latitude: 52.52,
|
|
Longitude: 13.405,
|
|
OwnerOrganizationID: "org-1",
|
|
}
|
|
err := suite.repo.Create(context.Background(), site)
|
|
suite.Require().NoError(err)
|
|
|
|
err = suite.repo.Delete(context.Background(), "site-1")
|
|
assert.NoError(suite.T(), err)
|
|
|
|
_, err = suite.repo.GetByID(context.Background(), "site-1")
|
|
assert.Error(suite.T(), err)
|
|
}
|
|
|
|
func TestSiteRepositoryTestSuite(t *testing.T) {
|
|
suite.Run(t, new(SiteRepositoryTestSuite))
|
|
}
|