WIP. A little custom music server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

started working on m4a tests

+33 -9
+6
backend/src/m4a/errors.ts
··· 1 + import { Schema } from "effect"; 2 + 3 + export class M4aUnsupportedFileError extends Schema.TaggedError<M4aUnsupportedFileError>()("M4aUnsupportedFileError", { 4 + message: Schema.NonEmptyString, 5 + // cause: Schema.Defect, 6 + }) {}
+13 -6
backend/src/m4a/service.test.ts
··· 1 - import { Effect, Layer } from "effect"; 1 + import { Effect, Exit, Layer } from "effect"; 2 2 import { BunContext } from "@effect/platform-bun"; 3 3 import { M4aService } from "./service"; 4 4 import { expect, it } from "vitest"; ··· 10 10 it(label, () => Effect.runSync(effect())); 11 11 }; 12 12 13 - test("smoke", () => 13 + 14 + test("readMetadata should throw an error if the file is not an m4a", () => 14 15 Effect.gen(function* () { 15 - yield* Effect.log("smoke"); 16 - expect(true).toBe(true); 17 - })); 16 + const m4aService = yield* M4aService; 17 + const input = "/Users/johnb/boombox-test-data/01 - hover.mp3"; 18 + const actual = yield* Effect.exit(m4aService.readMetadata(input)); 19 + expect(Exit.isFailure(actual)).toBe(true); 20 + }).pipe(Effect.provide(layers))); 18 21 19 22 test("readMetadata should return album, artist and title", () => 20 23 Effect.gen(function* () { 21 24 const m4aService = yield* M4aService; 22 25 const input = "/Users/johnb/boombox-test-data/'15 Downtown.m4a'"; 23 26 const actual = yield* m4aService.readMetadata(input); 24 - expect(actual).toHaveProperty("album", "test"); 27 + expect(actual.album).toBe("Torches X"); 28 + expect(actual.artists).toContain("Foster The People"); 29 + expect(actual.title).toBe("Downtown"); 30 + expect(actual.trackNumber).toBe(15); 25 31 }).pipe(Effect.provide(layers))); 26 32 33 +
+8 -3
backend/src/m4a/service.ts
··· 2 2 import { FileSystem } from "@effect/platform"; 3 3 import { BunFileSystem } from "@effect/platform-bun"; 4 4 import type { MetadataWithFilepathSchema } from "~/metadata"; 5 + import { M4aUnsupportedFileError } from "./errors"; 5 6 6 - type readMetadata = (path:string) => Effect.Effect<Partial<typeof MetadataWithFilepathSchema.Type>, never> 7 7 8 8 export class M4aService extends Effect.Service<M4aService>()("@boombox/backend/m4a/service/M4aService", { 9 9 dependencies: [BunFileSystem.layer], ··· 11 11 const fs = yield* FileSystem.FileSystem; 12 12 13 13 14 - const readMetadata: readMetadata = Effect.fn("m4a-readMetadata")(function* (path: string) { 14 + const checkSignature = Effect.fn("m4a-checkSignature")(function* (path: string) { 15 + 16 + yield* M4aUnsupportedFileError.make({ message: "Invalid signature"}); 17 + }); 15 18 19 + const readMetadata = Effect.fn("m4a-readMetadata")(function* (path: string) { 20 + yield* checkSignature(path); 16 21 return yield* Effect.succeed({ 17 - }); 22 + } as Partial<typeof MetadataWithFilepathSchema.Type>); 18 23 }); 19 24 20 25 return {
+6
backend/vitest.config.ts
··· 1 + import { defineConfig } from "vitest/config"; 2 + import tsconfigPaths from "vite-tsconfig-paths"; 3 + 4 + export default defineConfig({ 5 + plugins: [tsconfigPaths()] 6 + });