Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvanes committed Dec 25, 2023
1 parent 5cf2ed8 commit 540c5ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
43 changes: 0 additions & 43 deletions apps/server/src/nowplaying/nowplaying.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import { getRadioMetaData } from "@mdworld/radio-metadata";
import {
Controller,
Get,
Head,
HttpException,
HttpStatus,
InternalServerErrorException,
Logger,
Query,
StreamableFile,
UseGuards,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
Expand Down Expand Up @@ -84,45 +80,6 @@ export class NowplayingController {
}
} */

// @UseGuards(JwtAuthGuard)
// @Head("radio2embed")
// async getRadio2EmbedHead(): Promise<string> {
// this.logger.verbose("HEAD to /api/nowplaying/radio2embed");

// try {
// const headResponse = await got.head("http://localhost:52998/");
// if (headResponse.statusCode !== 200) {
// throw new InternalServerErrorException(
// HttpStatus.INTERNAL_SERVER_ERROR
// );
// }
// return "OK";
// } catch (error) {
// this.logger.error(error);
// throw new HttpException(
// error as Error,
// HttpStatus.INTERNAL_SERVER_ERROR
// );
// }
// }

// // TODO @UseGuards(JwtAuthGuard) see jukebox.controller.ts getSong()
// @Get("radio2embed")
// async getRadio2Embed(@Query("hash") hash: string): Promise<StreamableFile> {
// this.logger.verbose("GET to /api/nowplaying/radio2embed");

// try {
// const stream$ = got.stream("http://localhost:52998/");
// return new StreamableFile(stream$);
// } catch (error) {
// this.logger.error(error);
// throw new HttpException(
// error as Error,
// HttpStatus.INTERNAL_SERVER_ERROR
// );
// }
// }

@UseGuards(JwtAuthGuard)
@Get("radio2previously")
async getRadio2Previously(): Promise<PreviouslyResponse[] | undefined> {
Expand Down
23 changes: 8 additions & 15 deletions apps/server/src/video-stream/video-stream.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ConfigService } from "@nestjs/config";
import { Test, TestingModule } from "@nestjs/testing";
import got, { CancelableRequest, Response } from "got";
import { mocked } from "jest-mock";
import got from "got";
import { VideoStreamController } from "./video-stream.controller";

jest.mock("got");
const mockGot = mocked(got);
const gotHeadSpy = jest.spyOn(got, "head");

describe("VideoStreamController Controller", () => {
let controller: VideoStreamController;
Expand All @@ -30,24 +29,18 @@ describe("VideoStreamController Controller", () => {
return "http://localhost:123/";
}
});
// jest.spyOn(configService, "get").mockReturnValueOnce("http://some_url");
// jest.spyOn(configService, "get").mockReturnValueOnce("some_username");
});

afterAll(() => {
mockGot.mockRestore();
gotHeadSpy.mockRestore();
});

it("returns video stream hash on /GET", async () => {
// TODO
// mockGot.mockReturnValue({
// json: () => Promise.resolve(""),
// statusCode: 200,
// } as any); // CancelableRequest<Response>);
// mockGot.head.mockReturnValue();
// mockGot.mockResolvedValue({ statusCode: 200 } as any);
// const response = await controller.getHash();
// expect(response).toBe("https://start-player.npo.nl/embed/foo");
const gotHeadSpy = jest.spyOn(got, "head");
gotHeadSpy.mockResolvedValue({ statusCode: 200 });

const response = await controller.getHash();
expect(response).toEqual({ hash: "abc" });
});

// it("returns radio 2 embed fallback on /GET when unrecognized format", async () => {
Expand Down

0 comments on commit 540c5ce

Please sign in to comment.