mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Split helpers in multiples files
This commit is contained in:
parent
f9554bd128
commit
5d8d5721af
@ -1,4 +1,11 @@
|
|||||||
import Elysia from "elysia";
|
import { Elysia } from "elysia";
|
||||||
|
import { entries } from "./controllers/entries";
|
||||||
|
import { movies } from "./controllers/movies";
|
||||||
|
import { seasonsH } from "./controllers/seasons";
|
||||||
|
import { seed } from "./controllers/seed";
|
||||||
|
import { series } from "./controllers/series";
|
||||||
|
import { videosH } from "./controllers/videos";
|
||||||
|
|
||||||
import type { KError } from "./models/error";
|
import type { KError } from "./models/error";
|
||||||
|
|
||||||
export const base = new Elysia({ name: "base" })
|
export const base = new Elysia({ name: "base" })
|
||||||
@ -30,3 +37,12 @@ export const base = new Elysia({ name: "base" })
|
|||||||
return error;
|
return error;
|
||||||
})
|
})
|
||||||
.as("plugin");
|
.as("plugin");
|
||||||
|
|
||||||
|
export const app = new Elysia()
|
||||||
|
.use(base)
|
||||||
|
.use(movies)
|
||||||
|
.use(series)
|
||||||
|
.use(entries)
|
||||||
|
.use(seasonsH)
|
||||||
|
.use(videosH)
|
||||||
|
.use(seed);
|
@ -1,15 +1,7 @@
|
|||||||
import jwt from "@elysiajs/jwt";
|
import jwt from "@elysiajs/jwt";
|
||||||
import { swagger } from "@elysiajs/swagger";
|
import { swagger } from "@elysiajs/swagger";
|
||||||
import { Elysia } from "elysia";
|
|
||||||
import { base } from "./base";
|
|
||||||
import { entries } from "./controllers/entries";
|
|
||||||
import { movies } from "./controllers/movies";
|
|
||||||
import { seasonsH } from "./controllers/seasons";
|
|
||||||
import { seed } from "./controllers/seed";
|
|
||||||
import { series } from "./controllers/series";
|
|
||||||
import { videosH } from "./controllers/videos";
|
|
||||||
import { migrate } from "./db";
|
import { migrate } from "./db";
|
||||||
import { Image } from "./models/utils";
|
import { app } from "./elysia";
|
||||||
import { comment } from "./utils";
|
import { comment } from "./utils";
|
||||||
|
|
||||||
await migrate();
|
await migrate();
|
||||||
@ -31,8 +23,7 @@ if (!secret) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = new Elysia()
|
app
|
||||||
.use(base)
|
|
||||||
.use(jwt({ secret }))
|
.use(jwt({ secret }))
|
||||||
.use(
|
.use(
|
||||||
swagger({
|
swagger({
|
||||||
@ -70,13 +61,6 @@ const app = new Elysia()
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.model({ image: Image })
|
|
||||||
.use(movies)
|
|
||||||
.use(series)
|
|
||||||
.use(entries)
|
|
||||||
.use(seasonsH)
|
|
||||||
.use(videosH)
|
|
||||||
.use(seed)
|
|
||||||
.listen(3000);
|
.listen(3000);
|
||||||
|
|
||||||
console.log(`Api running at ${app.server?.hostname}:${app.server?.port}`);
|
console.log(`Api running at ${app.server?.hostname}:${app.server?.port}`);
|
||||||
|
5
api/tests/helpers/index.ts
Normal file
5
api/tests/helpers/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export * from "./movies-helper";
|
||||||
|
export * from "./series-helper";
|
||||||
|
export * from "./videos-helper";
|
||||||
|
|
||||||
|
export * from "~/elysia";
|
@ -1,19 +1,6 @@
|
|||||||
import Elysia from "elysia";
|
|
||||||
import { buildUrl } from "tests/utils";
|
import { buildUrl } from "tests/utils";
|
||||||
import { base } from "~/base";
|
import { app } from "~/elysia";
|
||||||
import { movies } from "~/controllers/movies";
|
|
||||||
import { seed } from "~/controllers/seed";
|
|
||||||
import { series } from "~/controllers/series";
|
|
||||||
import { videosH } from "~/controllers/videos";
|
|
||||||
import type { SeedMovie } from "~/models/movie";
|
import type { SeedMovie } from "~/models/movie";
|
||||||
import type { SeedVideo } from "~/models/video";
|
|
||||||
|
|
||||||
export const app = new Elysia()
|
|
||||||
.use(base)
|
|
||||||
.use(movies)
|
|
||||||
.use(series)
|
|
||||||
.use(videosH)
|
|
||||||
.use(seed);
|
|
||||||
|
|
||||||
export const getMovie = async (
|
export const getMovie = async (
|
||||||
id: string,
|
id: string,
|
||||||
@ -72,17 +59,3 @@ export const createMovie = async (movie: SeedMovie) => {
|
|||||||
const body = await resp.json();
|
const body = await resp.json();
|
||||||
return [resp, body] as const;
|
return [resp, body] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createVideo = async (video: SeedVideo | SeedVideo[]) => {
|
|
||||||
const resp = await app.handle(
|
|
||||||
new Request(buildUrl("videos"), {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(Array.isArray(video) ? video : [video]),
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const body = await resp.json();
|
|
||||||
return [resp, body] as const;
|
|
||||||
};
|
|
17
api/tests/helpers/series-helper.ts
Normal file
17
api/tests/helpers/series-helper.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { buildUrl } from "tests/utils";
|
||||||
|
import { app } from "~/elysia";
|
||||||
|
import type { SeedSerie } from "~/models/serie";
|
||||||
|
|
||||||
|
export const createSerie = async (serie: SeedSerie) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl("series"), {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(serie),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
17
api/tests/helpers/videos-helper.ts
Normal file
17
api/tests/helpers/videos-helper.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { buildUrl } from "tests/utils";
|
||||||
|
import { app } from "~/elysia";
|
||||||
|
import type { SeedVideo } from "~/models/video";
|
||||||
|
|
||||||
|
export const createVideo = async (video: SeedVideo | SeedVideo[]) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl("videos"), {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(Array.isArray(video) ? video : [video]),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
@ -6,7 +6,7 @@ import { shows } from "~/db/schema";
|
|||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
import { dune1984 } from "~/models/examples/dune-1984";
|
import { dune1984 } from "~/models/examples/dune-1984";
|
||||||
import { dune } from "~/models/examples/dune-2021";
|
import { dune } from "~/models/examples/dune-2021";
|
||||||
import { app, createMovie, getMovies } from "../helper";
|
import { app, createMovie, getMovies } from "../helpers";
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await db.delete(shows);
|
await db.delete(shows);
|
||||||
@ -14,7 +14,7 @@ beforeAll(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("with a null value", () => {
|
describe("with a null value", () => {
|
||||||
// Those before/after hooks are NOT scopped to the describe due to a bun bug
|
// Those before/after hooks are NOT scoped to the describe due to a bun bug
|
||||||
// instead we just make a new file for those /shrug
|
// instead we just make a new file for those /shrug
|
||||||
// see: https://github.com/oven-sh/bun/issues/5738
|
// see: https://github.com/oven-sh/bun/issues/5738
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -8,7 +8,7 @@ import { dune1984 } from "~/models/examples/dune-1984";
|
|||||||
import { dune } from "~/models/examples/dune-2021";
|
import { dune } from "~/models/examples/dune-2021";
|
||||||
import type { Movie } from "~/models/movie";
|
import type { Movie } from "~/models/movie";
|
||||||
import { isUuid } from "~/models/utils";
|
import { isUuid } from "~/models/utils";
|
||||||
import { getMovies, app } from "../helper";
|
import { getMovies, app } from "../helpers";
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await db.delete(shows);
|
await db.delete(shows);
|
||||||
|
@ -2,7 +2,7 @@ import { beforeAll, describe, expect, it } from "bun:test";
|
|||||||
import { expectStatus } from "tests/utils";
|
import { expectStatus } from "tests/utils";
|
||||||
import { seedMovie } from "~/controllers/seed/movies";
|
import { seedMovie } from "~/controllers/seed/movies";
|
||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
import { getMovie } from "../helper";
|
import { getMovie } from "../helpers";
|
||||||
|
|
||||||
let bubbleId = "";
|
let bubbleId = "";
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { db } from "~/db";
|
|||||||
import { showTranslations, shows, videos } from "~/db/schema";
|
import { showTranslations, shows, videos } from "~/db/schema";
|
||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
import { dune, duneVideo } from "~/models/examples/dune-2021";
|
import { dune, duneVideo } from "~/models/examples/dune-2021";
|
||||||
import { createMovie, createVideo } from "../helper";
|
import { createMovie, createVideo } from "../helpers";
|
||||||
|
|
||||||
describe("Movie seeding", () => {
|
describe("Movie seeding", () => {
|
||||||
it("Can create a movie", async () => {
|
it("Can create a movie", async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user