Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/backend/src/handlers/catalog/artist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { artistCreateHandler } from "./create";
import { artistUpdateHandler } from "./update";
import { artistDeleteHandler } from "./delete";
import { artistDetailsHandler } from "./get";
import { artistSearchHandler } from "./search";

export const artistHandler = new Elysia({ name: "artistHandler" })
.use(artistDetailsHandler)
.use(artistCreateHandler)
.use(artistUpdateHandler)
.use(artistDeleteHandler);
.use(artistDeleteHandler)
.use(artistSearchHandler);
25 changes: 25 additions & 0 deletions apps/backend/src/handlers/catalog/artist/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Elysia } from "elysia";
import { artistSearchService } from "@cvsa/core";
import z from "zod";
import { traceTask } from "@/common/trace";

// TODO: add corresponding DTO and response schema
export const artistSearchHandler = new Elysia().get(
"/artists",
async ({ query, status }) => {
const song = await traceTask("artistSearchService.search", async () => {
return await artistSearchService.search(query.q || "");
});
return status(200, song);
},
{
detail: {
summary: "Search for Artists",
description:
"Full-text search across artist names, aliases, and descriptions. Returns a list of matching artists ordered by relevance.",
},
query: z.object({
q: z.string().optional(),
}),
}
);
24 changes: 24 additions & 0 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,35 @@ import { opentelemetry } from "@elysiajs/opentelemetry";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { devHandler } from "./handlers";
import { createOutboxWorker, closeOutboxInfrastructure } from "@cvsa/core";
import { processOutboxEntry } from "@cvsa/core";
import { outboxService } from "@cvsa/core";
import { appLogger } from "@cvsa/logger";

const [host, port] = getBindingInfo();

logStartup(host, port);

const outboxWorker = createOutboxWorker(processOutboxEntry);

outboxService.recoverStaleEntries().catch((e) => {
appLogger.warn(`Failed to recover stale outbox entries: ${e.message}`);
});

process.on("SIGTERM", async () => {
appLogger.info("Received SIGTERM, shutting down gracefully...");
await outboxWorker.close();
await closeOutboxInfrastructure();
process.exit(0);
});

process.on("SIGINT", async () => {
appLogger.info("Received SIGINT, shutting down gracefully...");
await outboxWorker.close();
await closeOutboxInfrastructure();
process.exit(0);
});

export const app = new Elysia({
serve: {
hostname: host,
Expand Down
15 changes: 1 addition & 14 deletions apps/backend/tests/artist.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { treaty } from "@elysiajs/eden";
import { app } from "@/index";
import { prisma } from "@cvsa/db";

const api = treaty(app);

describe("Artist E2E Tests", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.artist.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

async function getAuthToken() {
const signup = await api.v2.user.post({
username: `${Math.random()}`,
Expand Down
53 changes: 3 additions & 50 deletions apps/backend/tests/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { treaty } from "@elysiajs/eden";
import { app } from "@/index";
import { prisma } from "@cvsa/db";

const api = treaty(app);

describe("Registration E2E Tests - POST /v2/user", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

test("should register a new user", async () => {
const payload = {
username: "new_user",
Expand Down Expand Up @@ -55,7 +42,7 @@ describe("Registration E2E Tests - POST /v2/user", () => {
const payload = {
username: "duplicate_user",
password: "password123",
email: "first@example.com",
email: "01_first@example.com",
};

// Create the first user
Expand All @@ -64,7 +51,7 @@ describe("Registration E2E Tests - POST /v2/user", () => {
// Attempt to register with the same username
const { error, status } = await api.v2.user.post({
...payload,
email: "second@example.com",
email: "01_second@example.com",
});

// Should return 409 Conflict
Expand Down Expand Up @@ -113,16 +100,6 @@ describe("Registration E2E Tests - POST /v2/user", () => {
});

describe("Profile E2E Tests - GET /v2/me", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
});

afterAll(async () => {
await prisma.$disconnect();
});

test("should return user profile with valid token", async () => {
// 1. Register to get a token
const signup = await api.v2.user.post({
Expand Down Expand Up @@ -187,18 +164,6 @@ describe("Profile E2E Tests - GET /v2/me", () => {
});

describe("Login E2E Tests - POST /v2/session", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

test("should login with valid credentials", async () => {
const signupPayload = {
username: "login_user",
Expand Down Expand Up @@ -277,18 +242,6 @@ describe("Login E2E Tests - POST /v2/session", () => {
});

describe("Logout E2E Tests - DELETE /v2/session", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

test("should logout with valid token", async () => {
const signupPayload = {
username: "logout_user",
Expand Down
15 changes: 1 addition & 14 deletions apps/backend/tests/engine.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { treaty } from "@elysiajs/eden";
import { app } from "@/index";
import { prisma } from "@cvsa/db";

const api = treaty(app);

describe("Engine E2E Tests", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.svsEngine.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

async function getAuthToken() {
const signup = await api.v2.user.post({
username: `${Math.random()}`,
Expand Down
17 changes: 1 addition & 16 deletions apps/backend/tests/song.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { treaty } from "@elysiajs/eden";
import { app } from "@/index";
import { prisma } from "@cvsa/db";

const api = treaty(app);

describe("Song E2E Tests", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.lyrics.deleteMany();
await prisma.song.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.$disconnect();
});

async function getAuthToken() {
const signup = await api.v2.user.post({
username: `${Math.random()}`,
Expand Down Expand Up @@ -122,7 +108,6 @@ describe("Song E2E Tests", () => {

expect(status).toBe(201);
expect(data).toMatchObject({
id: expect.any(Number),
name: "Lyrics Song",
});

Expand Down
18 changes: 1 addition & 17 deletions apps/backend/tests/songLyrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { treaty } from "@elysiajs/eden";
import { app } from "@/index";
import { prisma } from "@cvsa/db";

const api = treaty(app);

describe("Song Lyrics E2E Tests", () => {
beforeAll(async () => {
await prisma.$connect();
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.lyrics.deleteMany();
await prisma.song.deleteMany();
});

afterAll(async () => {
await prisma.session.deleteMany();
await prisma.user.deleteMany();
await prisma.lyrics.deleteMany();
await prisma.song.deleteMany();
await prisma.$disconnect();
});

async function getAuthToken() {
const signup = await api.v2.user.post({
username: `${Math.random()}`,
Expand Down
Loading