-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
287 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package integrationtype | ||
|
||
import ( | ||
"context" | ||
_ "github.com/mattn/go-sqlite3" | ||
"github.com/shinobistack/gokakashi/ent/enttest" | ||
"github.com/shinobistack/gokakashi/internal/restapi/v1/integrationtype" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetIntegrationType_ValidID(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
// Seed data | ||
_, _ = client.IntegrationType.Create(). | ||
SetID("linear"). | ||
SetDisplayName("Linear Integration"). | ||
Save(context.Background()) | ||
|
||
// Test case: Valid ID | ||
req := integrationtype.GetIntegrationTypeRequests{ID: "linear"} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.GetIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "linear", res.ID) | ||
assert.Equal(t, "Linear Integration", res.DisplayName) | ||
} | ||
|
||
func TestGetIntegrationType_NonExistentID(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.GetIntegrationTypeRequests{ID: "nonexistent"} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.GetIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "integration type not found") | ||
} | ||
|
||
func TestGetIntegrationType_InvalidIDFormat(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.GetIntegrationTypeRequests{ID: "Invalid ID!"} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.GetIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
req = integrationtype.GetIntegrationTypeRequests{ID: "Inv*ID"} | ||
handler = integrationtype.GetIntegrationType(client) | ||
err = handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
} | ||
|
||
func TestListIntegrationTypes_ValidRequest(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
// Seed data | ||
_, _ = client.IntegrationType.Create(). | ||
SetID("linear"). | ||
SetDisplayName("Linear Integration"). | ||
Save(context.Background()) | ||
_, _ = client.IntegrationType.Create(). | ||
SetID("jira"). | ||
SetDisplayName("Jira Integration"). | ||
Save(context.Background()) | ||
|
||
req := struct{}{} | ||
var res []integrationtype.GetIntegrationTypeResponse | ||
handler := integrationtype.ListIntegrationType(client) | ||
err := handler(context.Background(), req, &res) | ||
|
||
assert.NoError(t, err) | ||
assert.Len(t, res, 2) | ||
} | ||
|
||
func TestListIntegrations_EmptyDB(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
// Prepare response | ||
var res []integrationtype.GetIntegrationTypeResponse | ||
|
||
// Execute ListIntegrations handler | ||
handler := integrationtype.ListIntegrationType(client) | ||
err := handler(context.Background(), struct{}{}, &res) | ||
|
||
// Validate response | ||
assert.NoError(t, err) | ||
assert.Len(t, res, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package integrationtype | ||
|
||
import ( | ||
"context" | ||
"github.com/shinobistack/gokakashi/internal/restapi/v1/integrationtype" | ||
"testing" | ||
|
||
"github.com/shinobistack/gokakashi/ent/enttest" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateIntegrationType_ValidInput(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.CreateIntegrationTypeRequest{ | ||
ID: "linear", | ||
DisplayName: "Linear Integration", | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.CreateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "linear", res.ID) | ||
assert.Equal(t, "Linear Integration", res.DisplayName) | ||
} | ||
|
||
func TestCreateIntegrationType_MissingFields(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.CreateIntegrationTypeRequest{} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.CreateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "missing required fields") | ||
} | ||
|
||
func TestCreateIntegrationType_InvalidIDFormat(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.CreateIntegrationTypeRequest{ | ||
ID: "Invalid ID!", | ||
DisplayName: "Valid Format ", | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.CreateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
req = integrationtype.CreateIntegrationTypeRequest{ | ||
ID: "invalid", | ||
DisplayName: "Valid Format ", | ||
} | ||
handler = integrationtype.CreateIntegrationType(client) | ||
err = handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid id format") | ||
} | ||
|
||
func TestCreateIntegrationType_DuplicateID(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
_, _ = client.IntegrationType.Create(). | ||
SetID("linear"). | ||
SetDisplayName("Linear Integration"). | ||
Save(context.Background()) | ||
|
||
req := integrationtype.CreateIntegrationTypeRequest{ | ||
ID: "linear", | ||
DisplayName: "Linear Integration", | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.CreateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "integration type already exists") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package integrationtype | ||
|
||
import ( | ||
"context" | ||
"github.com/shinobistack/gokakashi/internal/restapi/v1/integrationtype" | ||
"testing" | ||
|
||
"github.com/shinobistack/gokakashi/ent/enttest" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUpdateIntegrationType_ValidUpdate(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
_, _ = client.IntegrationType.Create(). | ||
SetID("linear"). | ||
SetDisplayName("Linear Integration"). | ||
Save(context.Background()) | ||
|
||
req := integrationtype.UpdateIntegrationTypeRequest{ | ||
ID: "linear", | ||
DisplayName: ptr("Updated Linear Integration"), | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.UpdateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "linear", res.ID) | ||
assert.Equal(t, "Updated Linear Integration", res.DisplayName) | ||
} | ||
|
||
func TestUpdateIntegrationType_InvalidIDFormat(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.UpdateIntegrationTypeRequest{ | ||
ID: "Invalid ID!", | ||
DisplayName: ptr("Invalid Format"), | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.UpdateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid id format") | ||
} | ||
|
||
func TestUpdateIntegrationType_NonExistentID(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.UpdateIntegrationTypeRequest{ | ||
ID: "nonexistent", | ||
DisplayName: ptr("Non-existent Integration"), | ||
} | ||
res := &integrationtype.GetIntegrationTypeResponse{} | ||
handler := integrationtype.UpdateIntegrationType(client) | ||
err := handler(context.Background(), req, res) | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "integration type not found") | ||
} | ||
|
||
func TestUpdateIntegrationType_NoFieldsToUpdate(t *testing.T) { | ||
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") | ||
defer client.Close() | ||
|
||
req := integrationtype.UpdateIntegrationTypeRequest{ | ||
ID: "linear", | ||
DisplayName: nil, | ||
} | ||
var res integrationtype.GetIntegrationTypeResponse | ||
handler := integrationtype.UpdateIntegrationType(client) | ||
err := handler(context.Background(), req, &res) | ||
|
||
assert.Error(t, err) | ||
} | ||
|
||
func ptr(value string) *string { | ||
return &value | ||
} |