WIP: Keep writing projectS
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
@@ -7,20 +7,127 @@ import (
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/repository"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestProjectsRepository_Success(t *testing.T) {
|
||||
func TestIntegrationProjectsCreate_Success(t *testing.T) {
|
||||
createdBy := uuid.NewString()
|
||||
_ = &repository.ProjectData{
|
||||
project := &repository.ProjectData{
|
||||
UUID: uuid.NewString(),
|
||||
Name: "test-1",
|
||||
Slug: "test_1",
|
||||
Slug: uuid.NewString(),
|
||||
Description: "Test Project Number 1",
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
ArchivedAt: sql.NullTime{Time: time.Now()},
|
||||
ClosedAt: sql.NullTime{Time: time.Now()},
|
||||
Blocked: false,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedBy: createdBy,
|
||||
}
|
||||
|
||||
assert.NoError(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project))
|
||||
}
|
||||
|
||||
func TestIntegrationProjectsCreate_CheckFailed(t *testing.T) {
|
||||
createdBy := uuid.NewString()
|
||||
project := &repository.ProjectData{
|
||||
UUID: uuid.NewString(),
|
||||
Name: "test-2",
|
||||
Slug: "test_2",
|
||||
Description: "Test Project Number 1",
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
ClosedAt: sql.NullTime{Time: time.Now()},
|
||||
Blocked: false,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedBy: createdBy,
|
||||
}
|
||||
assert.Error(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project), repository.ErrCheckNotPassed)
|
||||
}
|
||||
|
||||
func TestIntegrationProjectsCreate_AlreadyExistsFail(t *testing.T) {
|
||||
createdBy := uuid.NewString()
|
||||
project := &repository.ProjectData{
|
||||
UUID: uuid.NewString(),
|
||||
Name: "test-3",
|
||||
Slug: uuid.NewString(),
|
||||
Description: "Test Project Number 1",
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
ClosedAt: sql.NullTime{Time: time.Now()},
|
||||
Blocked: false,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedBy: createdBy,
|
||||
}
|
||||
|
||||
assert.NoError(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project))
|
||||
assert.Error(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project), repository.ErrAlreadyExists)
|
||||
}
|
||||
|
||||
func TestIntegrationProjectsCreateAndGet_Success(t *testing.T) {
|
||||
createdBy := uuid.NewString()
|
||||
project := &repository.ProjectData{
|
||||
UUID: uuid.NewString(),
|
||||
Name: "test-4",
|
||||
Slug: uuid.NewString(),
|
||||
Description: "Test Project Number 1",
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
Blocked: false,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedBy: createdBy,
|
||||
}
|
||||
|
||||
assert.NoError(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project))
|
||||
data, err := repository.GetProjectByID(t.Context(), newTestDBConnection(t.Context()), project.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, project.Name, data.Name)
|
||||
assert.Equal(t, project.Slug, data.Slug)
|
||||
assert.Equal(t, project.Description, data.Description)
|
||||
assert.Equal(t, project.CreatedBy, data.CreatedBy)
|
||||
assert.Equal(t, project.ClosedAt.Time.Truncate(time.Second), data.ClosedAt.Time.Truncate(time.Second))
|
||||
assert.Equal(t, project.CreatedAt.Truncate(time.Second), data.CreatedAt.Truncate(time.Second))
|
||||
}
|
||||
|
||||
func TestIntegrationProjectsCreateAndGet_NotFound(t *testing.T) {
|
||||
data, err := repository.GetProjectByID(t.Context(), newTestDBConnection(t.Context()), uuid.NewString())
|
||||
assert.ErrorIs(t, err, repository.ErrNotFound)
|
||||
assert.Nil(t, data)
|
||||
}
|
||||
|
||||
func TestIntegrationProjectsCreateUpdateAndGet_Success(t *testing.T) {
|
||||
createdBy := uuid.NewString()
|
||||
project := &repository.ProjectData{
|
||||
UUID: uuid.NewString(),
|
||||
Name: "test-5",
|
||||
Slug: uuid.NewString(),
|
||||
Description: "Test Project Number 1",
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
Blocked: false,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedBy: createdBy,
|
||||
}
|
||||
|
||||
assert.NoError(t, repository.CreateProject(t.Context(), newTestDBConnection(t.Context()), project))
|
||||
data, err := repository.GetProjectByID(t.Context(), newTestDBConnection(t.Context()), project.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, project.Name, data.Name)
|
||||
assert.Equal(t, project.Slug, data.Slug)
|
||||
assert.Equal(t, project.Description, data.Description)
|
||||
assert.Equal(t, project.CreatedBy, data.CreatedBy)
|
||||
assert.Equal(t, project.ClosedAt.Time.Truncate(time.Second), data.ClosedAt.Time.Truncate(time.Second))
|
||||
assert.Equal(t, project.CreatedAt.Truncate(time.Second), data.CreatedAt.Truncate(time.Second))
|
||||
|
||||
project.UpdatedBy = uuid.NewString()
|
||||
project.UpdatedAt = time.Now()
|
||||
project.Description = "Updated description"
|
||||
project.Name = "update name"
|
||||
|
||||
assert.NoError(t, repository.UpdateProject(t.Context(), newTestDBConnection(t.Context()), project))
|
||||
data, err = repository.GetProjectByID(t.Context(), newTestDBConnection(t.Context()), project.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, project.Name, data.Name)
|
||||
assert.Equal(t, project.Slug, data.Slug)
|
||||
assert.Equal(t, project.Description, data.Description)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user