This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
7 changed files
with
128 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -24,6 +24,9 @@ var ( | |
TeamReefID = uuid.MustParse("00000000-0000-0000-0000-000000000004") | ||
TeamReefName = "Reef" | ||
|
||
GroupNameReef = "reef" | ||
GroupEmailReef = "[email protected]" | ||
|
||
UserOneName = "User Userson" | ||
UserOneEmail = "[email protected]" | ||
UserTwoName = "Another Userson" | ||
|
@@ -79,6 +82,15 @@ const fakeMetabaseSA = `{ | |
} | ||
` | ||
|
||
func StorageCreateNaisConsoleTeamsAndProjects(t *testing.T, storage service.NaisConsoleStorage, teams map[string]string) { | ||
t.Helper() | ||
|
||
err := storage.UpdateAllTeamProjects(context.Background(), teams) | ||
if err != nil { | ||
t.Fatalf("creating teams and projects: %v", err) | ||
} | ||
} | ||
|
||
func StorageCreateProductAreasAndTeams(t *testing.T, storage service.ProductAreaStorage) { | ||
t.Helper() | ||
|
||
|
@@ -112,13 +124,13 @@ func StorageCreateProductAreasAndTeams(t *testing.T, storage service.ProductArea | |
} | ||
} | ||
|
||
func NewDataProductBiofuelProduction() service.NewDataproduct { | ||
func NewDataProductBiofuelProduction(group string, teamID uuid.UUID) service.NewDataproduct { | ||
return service.NewDataproduct{ | ||
Name: "Biofuel Production", | ||
Description: strToStrPtr("Using seagrass as a feedstock to create renewable biofuels"), | ||
Group: GroupEmailNada, | ||
Group: group, | ||
ProductAreaID: &ProductAreaOceanicID, | ||
TeamID: &TeamSeagrassID, | ||
TeamID: &teamID, | ||
} | ||
} | ||
|
||
|
@@ -157,33 +169,33 @@ func NewDatasetBiofuelConsumptionRates(dataProductID uuid.UUID) service.NewDatas | |
} | ||
} | ||
|
||
func NewDataProductAquacultureFeed() service.NewDataproduct { | ||
func NewDataProductAquacultureFeed(group string, teamID uuid.UUID) service.NewDataproduct { | ||
return service.NewDataproduct{ | ||
Name: "Aquaculture Feed", | ||
Description: strToStrPtr("Producing high-nutrient feed for aquaculture industries from processed seagrass"), | ||
Group: GroupEmailNada, | ||
Group: group, | ||
ProductAreaID: &ProductAreaOceanicID, | ||
TeamID: &TeamSeagrassID, | ||
TeamID: &teamID, | ||
} | ||
} | ||
|
||
func NewDataProductReefMonitoring() service.NewDataproduct { | ||
func NewDataProductReefMonitoring(group string, teamID uuid.UUID) service.NewDataproduct { | ||
return service.NewDataproduct{ | ||
Name: "Reef Monitoring Equipment", | ||
Description: strToStrPtr("Advanced sensors and monitoring devices for continuous assessment"), | ||
Group: GroupEmailNada, | ||
Group: group, | ||
ProductAreaID: &ProductAreaCostalID, | ||
TeamID: &TeamReefID, | ||
TeamID: &teamID, | ||
} | ||
} | ||
|
||
func NewDataProductProtectiveBarriers() service.NewDataproduct { | ||
func NewDataProductProtectiveBarriers(group string, teamID uuid.UUID) service.NewDataproduct { | ||
return service.NewDataproduct{ | ||
Name: "Protective Barriers", | ||
Description: strToStrPtr("Physical barriers to protect coral reefs from human activity"), | ||
Group: GroupEmailNada, | ||
Group: group, | ||
ProductAreaID: &ProductAreaCostalID, | ||
TeamID: &TeamReefID, | ||
TeamID: &teamID, | ||
} | ||
} | ||
|
||
|
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,95 @@ | ||
package integration | ||
|
||
import ( | ||
"github.com/navikt/nada-backend/pkg/config/v2" | ||
"github.com/navikt/nada-backend/pkg/database" | ||
"github.com/navikt/nada-backend/pkg/service" | ||
"github.com/navikt/nada-backend/pkg/service/core" | ||
"github.com/navikt/nada-backend/pkg/service/core/handlers" | ||
"github.com/navikt/nada-backend/pkg/service/core/routes" | ||
"github.com/navikt/nada-backend/pkg/service/core/storage" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestUserDataService(t *testing.T) { | ||
log := zerolog.New(os.Stdout) | ||
c := NewContainers(t, log) | ||
defer c.Cleanup() | ||
|
||
pgCfg := c.RunPostgres(NewPostgresConfig()) | ||
|
||
repo, err := database.New( | ||
pgCfg.ConnectionURL(), | ||
10, | ||
10, | ||
) | ||
assert.NoError(t, err) | ||
|
||
r := TestRouter(log) | ||
|
||
stores := storage.NewStores(repo, config.Config{}, log) | ||
|
||
StorageCreateProductAreasAndTeams(t, stores.ProductAreaStorage) | ||
StorageCreateNaisConsoleTeamsAndProjects(t, stores.NaisConsoleStorage, map[string]string{GroupNameNada: GroupNameNada, GroupNameReef: GroupEmailReef}) | ||
fuel := StorageCreateDataproduct(t, stores.DataProductsStorage, NewDataProductBiofuelProduction(GroupEmailNada, TeamSeagrassID)) | ||
barriers := StorageCreateDataproduct(t, stores.DataProductsStorage, NewDataProductProtectiveBarriers(GroupEmailReef, TeamReefID)) | ||
feed := StorageCreateDataproduct(t, stores.DataProductsStorage, NewDataProductAquacultureFeed(GroupEmailNada, TeamSeagrassID)) | ||
reef := StorageCreateDataproduct(t, stores.DataProductsStorage, NewDataProductReefMonitoring(GroupEmailReef, TeamReefID)) | ||
|
||
{ | ||
s := core.NewUserService(stores.AccessStorage, stores.TokenStorage, stores.StoryStorage, stores.DataProductsStorage, | ||
stores.InsightProductStorage, stores.NaisConsoleStorage, log) | ||
h := handlers.NewUserHandler(s) | ||
e := routes.NewUserEndpoints(log, h) | ||
f := routes.NewUserRoutes(e, injectUser(&service.User{ | ||
Email: "[email protected]", | ||
GoogleGroups: []service.Group{ | ||
{ | ||
Name: GroupNameNada, | ||
Email: GroupEmailNada, | ||
}, | ||
{ | ||
Name: GroupNameReef, | ||
Email: GroupEmailReef, | ||
}, | ||
}, | ||
})) | ||
f(r) | ||
} | ||
|
||
server := httptest.NewServer(r) | ||
defer server.Close() | ||
// Would prefer to sort by dp.tema_name, but it is always null | ||
t.Run("User data products are sorted alphabetically by group_name and dp_name", func(t *testing.T) { | ||
got := &service.UserInfo{} | ||
expect := []service.Dataproduct{ | ||
{ID: feed.ID, Name: feed.Name, Owner: &service.DataproductOwner{Group: GroupEmailNada}}, | ||
{ID: fuel.ID, Name: fuel.Name, Owner: &service.DataproductOwner{Group: GroupEmailNada}}, | ||
{ID: barriers.ID, Name: barriers.Name, Owner: &service.DataproductOwner{Group: GroupEmailReef}}, | ||
{ID: reef.ID, Name: reef.Name, Owner: &service.DataproductOwner{Group: GroupEmailReef}}, | ||
} | ||
|
||
NewTester(t, server).Get("/api/userData"). | ||
HasStatusCode(http.StatusOK).Value(got) | ||
|
||
if len(got.Dataproducts) != len(expect) { | ||
t.Fatalf("got %d, expected %d", len(got.Dataproducts), len(expect)) | ||
} | ||
for i := 0; i < len(got.Dataproducts); i++ { | ||
if got.Dataproducts[i].ID != expect[i].ID { | ||
t.Errorf("got %s, expected %s", got.Dataproducts[i].ID, expect[i].ID) | ||
} | ||
if got.Dataproducts[i].Name != expect[i].Name { | ||
t.Errorf("got %s, expected %s", got.Dataproducts[i].Name, expect[i].Name) | ||
} | ||
if got.Dataproducts[i].Owner.Group != expect[i].Owner.Group { | ||
t.Errorf("got %s, expected %s", got.Dataproducts[i].Owner.Group, expect[i].Owner.Group) | ||
} | ||
} | ||
}) | ||
} |