-
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.
Query event types: add http handler (#73)
* update setup instructions of web and server * add http handler to query event types * remove envid * Query event types: implement repo (#74) * wip * implement repo and add integration tests * add component test (#75)
- Loading branch information
1 parent
70f59db
commit a6d4e42
Showing
16 changed files
with
614 additions
and
90 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
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,56 @@ | ||
package psql_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/subscribeddotdev/subscribed/server/internal/app/query" | ||
"github.com/subscribeddotdev/subscribed/server/internal/domain" | ||
"github.com/subscribeddotdev/subscribed/server/internal/domain/iam" | ||
"github.com/subscribeddotdev/subscribed/server/tests" | ||
"github.com/subscribeddotdev/subscribed/server/tests/fixture" | ||
) | ||
|
||
func TestEventTypesRepository_FindAll(t *testing.T) { | ||
ff := fixture.NewFactory(t, ctx, db) | ||
org := ff.NewOrganization().Save() | ||
|
||
eventTypesFixtureCount := 20 | ||
for i := 0; i < eventTypesFixtureCount; i++ { | ||
ff.NewEventType().WithOrgID(org.ID).Save() | ||
} | ||
|
||
t.Run("return_an_empty_slice_when_page_is_out_of_bounds", func(t *testing.T) { | ||
result, err := eventTypeRepo.FindAll( | ||
ctx, | ||
iam.OrgID(org.ID), | ||
query.NewPaginationParams(tests.ToPtr(30), tests.ToPtr(5)), | ||
) | ||
require.NoError(t, err) | ||
require.Empty(t, result.Data) | ||
require.Equal(t, 0, result.PerPage) | ||
}) | ||
|
||
t.Run("iteratively_query_event_types_from_different_pages", func(t *testing.T) { | ||
perPage := 5 | ||
totalPages := eventTypesFixtureCount / 5 | ||
queriedAppIDs := make(map[string]domain.EventType) | ||
|
||
for i := 0; i < totalPages; i++ { | ||
currentPage := i + 1 | ||
result, err := eventTypeRepo.FindAll(ctx, iam.OrgID(org.ID), query.NewPaginationParams(¤tPage, &perPage)) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, result.Data) | ||
require.Equal(t, perPage, result.PerPage) | ||
require.Equal(t, currentPage, result.CurrentPage) | ||
require.Equal(t, eventTypesFixtureCount, result.Total) | ||
require.Equal(t, totalPages, result.TotalPages) | ||
|
||
for _, app := range result.Data { | ||
_, exists := queriedAppIDs[app.ID().String()] | ||
require.Falsef(t, exists, "event type must not have already been returned: app id '%s'", app.ID()) | ||
queriedAppIDs[app.ID().String()] = app | ||
} | ||
} | ||
}) | ||
} |
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,31 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/subscribeddotdev/subscribed/server/internal/domain" | ||
"github.com/subscribeddotdev/subscribed/server/internal/domain/iam" | ||
) | ||
|
||
type AllEventTypes struct { | ||
PaginationParams | ||
OrgID string | ||
} | ||
|
||
type eventTypesFinder interface { | ||
FindAll(ctx context.Context, orgID iam.OrgID, pagination PaginationParams) (Paginated[[]domain.EventType], error) | ||
} | ||
|
||
type allEventTypesHandler struct { | ||
eventTypesFinder eventTypesFinder | ||
} | ||
|
||
func NewAllEventTypesHandler(eventTypesFinder eventTypesFinder) allEventTypesHandler { | ||
return allEventTypesHandler{ | ||
eventTypesFinder: eventTypesFinder, | ||
} | ||
} | ||
|
||
func (h allEventTypesHandler) Execute(ctx context.Context, q AllEventTypes) (Paginated[[]domain.EventType], error) { | ||
return h.eventTypesFinder.FindAll(ctx, iam.OrgID(q.OrgID), q.PaginationParams) | ||
} |
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
Oops, something went wrong.