Skip to content

Commit 19cf65e

Browse files
fixed integration tests
1 parent 821a621 commit 19cf65e

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

internal/database/queries.sql

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,22 @@ WITH updated AS (
101101
WHERE eid = $1
102102
RETURNING *
103103
)
104-
SELECT v.* FROM events_with_org_ids v
105-
WHERE v.eid = $1;
104+
SELECT
105+
u.eid,
106+
u.location,
107+
u.event_time,
108+
u.description,
109+
u.date_created,
110+
u.date_modified,
111+
u.title,
112+
COALESCE(hosts.org_ids, ARRAY[]::uuid[]) AS org_ids
113+
FROM updated u
114+
LEFT JOIN (
115+
SELECT eh.eid, ARRAY_AGG(eh.oid)::uuid[] AS org_ids
116+
FROM event_hosting eh
117+
WHERE eh.eid = $1
118+
GROUP BY eh.eid
119+
) hosts ON hosts.eid = u.eid;
106120

107121
-- name: DeleteEvent :exec
108122
DELETE FROM events WHERE eid = $1;

internal/database/queries.sql.go

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/router/router.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func New(h *handler.Handler, queries database.Querier, jwtSecret string, allowed
6969
r.Use(chimiddleware.RequestID)
7070
r.Use(middleware.CORS(allowedOrigins, h.Config.Env == "development"))
7171

72+
// Public link resolution alias.
73+
r.Get("/r/{endpoint_url}", h.ResolveLink)
74+
7275
// API routes
7376
r.Route("/api", func(r chi.Router) {
7477
// Health check (public)

internal/testutils/container.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@ func SetupTestPostgres(t *testing.T) string {
4646
return connStr
4747
}
4848

49-
// SetupTestDB creates a fresh Postgres container, initializes schema.sql, and returns the connection pool.
49+
// SetupTestDB creates a fresh Postgres container, applies all migrations, and returns the connection pool.
5050
func SetupTestDB(t *testing.T) *pgxpool.Pool {
5151
ctx := context.Background()
5252
_, filename, _, _ := runtime.Caller(0)
5353
projectRoot := filepath.Join(filepath.Dir(filename), "../..")
54-
schemaPath := filepath.Join(projectRoot, "schema.sql")
54+
migrationsPath := filepath.Join(projectRoot, "migrations")
5555

5656
pgContainer, err := postgres.Run(ctx,
5757
"postgres:16-alpine",
58-
postgres.WithInitScripts(schemaPath),
5958
postgres.WithDatabase("test_db"),
6059
postgres.WithUsername("test"),
6160
postgres.WithPassword("test"),
@@ -79,6 +78,10 @@ func SetupTestDB(t *testing.T) *pgxpool.Pool {
7978
t.Fatalf("failed to get connection string: %v", err)
8079
}
8180

81+
if err := database.RunMigrations(ctx, connStr, migrationsPath); err != nil {
82+
t.Fatalf("failed to apply migrations: %v", err)
83+
}
84+
8285
pool, err := database.NewPool(ctx, connStr)
8386
if err != nil {
8487
t.Fatalf("failed to connect to database: %v", err)

0 commit comments

Comments
 (0)