diff --git a/AGENTS.md b/AGENTS.md index 4835452f..17c748d2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -32,6 +32,12 @@ - handlers and routes for Portal part of the server are setup in `pkg/portal/server.go` and `pkg/portal/server_enterprise.go` - maintenance jobs are defined in `pkg/maintenance/` package and scheduled in `cmd/server/main.go` +### Frontend + +- All frontend code (HTML, CSS, JavaScript) for Portal is in `web/` directory +- We use htmx and Alpine.js libraries for frontend. For styles we use Tailwind CSS v3.4 (config is in `web/tailwind.config.js`) +- Frontend code is formatted using Golang templates (with our additional functions) with entrypoint in `web/portal/templates.go`. Our templates use a similar system to Hugo static site generator where custom pages always get used with "base" templates in `web/layouts/_default` for rendering, so we can reuse functionality. + ## Environment setup - Use `make init` to initialize everything for development @@ -44,7 +50,7 @@ ## Testing instructions -- To run all Go unit tests, run `make test-unit` +- To run all Go unit tests, run `make test-unit` (unit tests always run with "enterprise" tag) - To run JS widget tests, run `make test-widget-unit` - To run a single Go integration test, run `make test-docker-light TEST_NAME=` (prefer running a single test for debugging). Docker is required. - To run all Go integration tests, run `make test-docker-light`. Docker is required. diff --git a/pkg/portal/audit_enterprise_test.go b/pkg/portal/audit_enterprise_test.go deleted file mode 100644 index 66dbafd4..00000000 --- a/pkg/portal/audit_enterprise_test.go +++ /dev/null @@ -1,57 +0,0 @@ -//go:build enterprise - -package portal - -import ( - "context" - "testing" -) - -func TestAuditLogsDaysFromParam(t *testing.T) { - ctx := context.Background() - - tests := []struct { - input string - expected int - }{ - {"14", 14}, - {"30", 30}, - {"90", 90}, - {"180", 180}, - {"365", 365}, - {"", 14}, - {"invalid", 14}, - {"7", 14}, - {"100", 14}, - {"-1", 14}, - } - - for _, tc := range tests { - t.Run(tc.input, func(t *testing.T) { - result := auditLogsDaysFromParam(ctx, tc.input) - if result != tc.expected { - t.Errorf("auditLogsDaysFromParam(%q) = %d, want %d", tc.input, result, tc.expected) - } - }) - } -} - -func TestMaxAuditLogsForDays(t *testing.T) { - tests := []struct { - days int - expected int - }{ - {14, 1400}, - {30, 3000}, - {90, 9000}, - {180, 18000}, - {365, 36500}, - } - - for _, tc := range tests { - result := maxAuditLogsForDays(tc.days) - if result != tc.expected { - t.Errorf("maxAuditLogsForDays(%d) = %d, want %d", tc.days, result, tc.expected) - } - } -} diff --git a/pkg/portal/audit_test.go b/pkg/portal/audit_test.go index 8557e5b5..332b0d30 100644 --- a/pkg/portal/audit_test.go +++ b/pkg/portal/audit_test.go @@ -90,7 +90,7 @@ func TestUserAuditLogInitFromOrg(t *testing.T) { wantErr: false, }, { - name: "org creation", + name: "org creation", oldValue: nil, newValue: &db.AuditLogOrg{ ID: 1, @@ -142,7 +142,7 @@ func TestUserAuditLogInitFromSubscription(t *testing.T) { wantErr: false, }, { - name: "subscription creation", + name: "subscription creation", oldValue: nil, newValue: &db.AuditLogSubscription{ Source: "external", @@ -176,7 +176,7 @@ func TestUserAuditLogInitFromOrgUser(t *testing.T) { wantErr bool }{ { - name: "org user creation", + name: "org user creation", oldValue: nil, newValue: &db.AuditLogOrgUser{ OrgName: "Test Org", @@ -249,7 +249,7 @@ func TestUserAuditLogInitFromProperty(t *testing.T) { wantErr: false, }, { - name: "property creation", + name: "property creation", oldValue: nil, newValue: &db.AuditLogProperty{ Name: "New Property", @@ -294,7 +294,7 @@ func TestUserAuditLogInitFromAPIKey(t *testing.T) { wantErr: false, }, { - name: "api key creation", + name: "api key creation", oldValue: nil, newValue: &db.AuditLogAPIKey{ Name: "New Key", @@ -787,3 +787,52 @@ func TestInitFromAPIKeyPeriodChange(t *testing.T) { t.Errorf("Expected Property to be 'Period', got '%s'", ul.Property) } } + +func TestAuditLogsDaysFromParam(t *testing.T) { + ctx := context.Background() + + tests := []struct { + input string + expected int + }{ + {"14", 14}, + {"30", 30}, + {"90", 90}, + {"180", 180}, + {"365", 365}, + {"", 14}, + {"invalid", 14}, + {"7", 14}, + {"100", 14}, + {"-1", 14}, + } + + for _, tc := range tests { + t.Run(tc.input, func(t *testing.T) { + result := auditLogsDaysFromParam(ctx, tc.input) + if result != tc.expected { + t.Errorf("auditLogsDaysFromParam(%q) = %d, want %d", tc.input, result, tc.expected) + } + }) + } +} + +func TestMaxAuditLogsForDays(t *testing.T) { + tests := []struct { + days int + expected int + }{ + {14, 1400}, + {30, 3000}, + {90, 9000}, + {180, 18000}, + {365, 36500}, + } + + for _, tc := range tests { + result := maxAuditLogsForDays(tc.days) + if result != tc.expected { + t.Errorf("maxAuditLogsForDays(%d) = %d, want %d", tc.days, result, tc.expected) + } + } +}