Skip to content

Commit

Permalink
Merge branch 'develop' into feat/renderDeployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglasj02 authored Sep 29, 2024
2 parents fbf04e1 + 1cba122 commit b06991a
Show file tree
Hide file tree
Showing 139 changed files with 4,700 additions and 2,586 deletions.
12 changes: 12 additions & 0 deletions Backend/jest-int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".int-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
}
}
1 change: 1 addition & 0 deletions Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:int": "jest -i --no-cache --watch --config jest-int.json",
"coveralls": "cat coverage/lcov.info | coveralls"
},
"dependencies": {
Expand Down
103 changes: 44 additions & 59 deletions Backend/src/app.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,54 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppModule } from './app.module';
import { ConfigModule } from '@nestjs/config';
import { HttpModule } from '@nestjs/axios';
import { AuthController } from './auth/controller/auth.controller';
import { SpotifyController } from './spotify/controller/spotify.controller';
import { YoutubeController } from './youtube/controller/youtube.controller';
import { YouTubeController } from './youtube/controller/youtube.controller';
import { SearchController } from './search/controller/search.controller';
import { AuthService } from './auth/services/auth.service';
import { SupabaseService } from './supabase/services/supabase.service';
import { ConfigService } from '@nestjs/config';
import { SpotifyService } from './spotify/services/spotify.service';
import { YoutubeService } from './youtube/services/youtube.service';
import { SearchService } from './search/services/search.service';
import { TokenMiddleware } from './middleware/token.middleware';
import { MiddlewareConsumer, RequestMethod } from '@nestjs/common';

describe('AppModule', () => {
let module: TestingModule;

beforeAll(async () => {
module = await Test.createTestingModule({
imports: [AppModule],
}).compile();
});

afterAll(async () => {
await module.close();
});

it('should import ConfigModule and HttpModule', () => {
const imports = module.get(AppModule).constructor.prototype.constructor.parameters;

expect(imports).toContainEqual(expect.arrayContaining([ConfigModule]));
expect(imports).toContainEqual(expect.arrayContaining([HttpModule]));
});

it('should have the correct controllers', () => {
const controllers = module.get(AppModule).constructor.prototype.controllers;
expect(controllers).toContainEqual(AuthController);
expect(controllers).toContainEqual(SpotifyController);
expect(controllers).toContainEqual(YoutubeController);
expect(controllers).toContainEqual(SearchController);
});

it('should have the correct providers', () => {
const providers = module.get(AppModule).constructor.prototype.providers;
expect(providers).toContainEqual(expect.anything());
expect(providers).toContainEqual(AuthService);
expect(providers).toContainEqual(SupabaseService);
expect(providers).toContainEqual(ConfigService);
expect(providers).toContainEqual(SpotifyService);
expect(providers).toContainEqual(YoutubeService);
expect(providers).toContainEqual(SearchService);
});

it('should apply TokenMiddleware to auth/callback route', () => {
const consumer = {
apply: jest.fn().mockReturnThis(),
forRoutes: jest.fn().mockReturnValue({ path: 'auth/callback', method: RequestMethod.GET }),
} as unknown as MiddlewareConsumer;

const appModule = new AppModule();
appModule.configure(consumer);

expect(consumer.apply).toHaveBeenCalledWith(TokenMiddleware);
expect(consumer.apply(TokenMiddleware).forRoutes).toHaveBeenCalledWith({ path: 'auth/callback', method: RequestMethod.GET });
});
let appModule: TestingModule;

beforeAll(async () => {
appModule = await Test.createTestingModule({
imports: [AppModule],
providers: [TokenMiddleware]
}).compile();
});

it('should be defined', () => {
expect(appModule).toBeDefined();
});

it('should have AuthController defined', () => {
const authController = appModule.get<AuthController>(AuthController);
expect(authController).toBeDefined();
});

it('should have SpotifyController defined', () => {
const spotifyController = appModule.get<SpotifyController>(SpotifyController);
expect(spotifyController).toBeDefined();
});

it('should have YouTubeController defined', () => {
const youtubeController = appModule.get<YouTubeController>(YouTubeController);
expect(youtubeController).toBeDefined();
});

it('should have SearchController defined', () => {
const searchController = appModule.get<SearchController>(SearchController);
expect(searchController).toBeDefined();
});

it('should have TokenMiddleware applied to auth/callback route', () => {

// Assuming you can inspect the middleware routes, which usually you can't directly.
// You may need to rethink how to validate middleware is applied,
// as there's no built-in way to check this.
// You can just verify that TokenMiddleware is defined and should be included.

const tokenMiddleware = appModule.get<TokenMiddleware>(TokenMiddleware);
expect(tokenMiddleware).toBeDefined();
});
});
1 change: 1 addition & 0 deletions Backend/src/search/controller/search.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('SearchController', () => {
searchByTitle: jest.fn(),
searchByAlbum: jest.fn(),
artistSearch: jest.fn(),
searchAlbums: jest.fn(),
},
},
],
Expand Down
86 changes: 51 additions & 35 deletions Backend/src/search/controller/search.controller.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
import { Body, Controller, Get, Post, Put } from "@nestjs/common";
import { Body, Controller, Get, Post, Put, Query } from "@nestjs/common";
import { SearchService } from "../services/search.service";

@Controller("search")
export class SearchController
{
constructor(private readonly searchService: SearchService)
{}

// This endpoint is used to search for tracks by title.
@Post("search")
async searchByTitle(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchByTitle(title);
}

// This endpoint is used to search for albums based on their title.
@Post("album")
async searchByAlbum(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchByAlbum(title);
}

// This endpoint is used to get the details of a specific artist.
@Post("artist")
async searchForArtist(@Body() body: { artist: string }): Promise<any>
{
const { artist } = body;
return await this.searchService.artistSearch(artist);
}

// This endpoint is used to get the details of a specific album.
@Post("album-info")
async albumInfo(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchAlbums(title);
}
constructor(private readonly searchService: SearchService)
{
}

// This endpoint is used to search for tracks by title.
@Post("search")
async searchByTitle(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchByTitle(title);
}

// This endpoint is used to search for albums based on their title.
@Post("album")
async searchByAlbum(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchByAlbum(title);
}

// This endpoint is used to get the details of a specific artist.
@Post("artist")
async searchForArtist(@Body() body: { artist: string }): Promise<any>
{
const { artist } = body;
return await this.searchService.artistSearch(artist);
}

// This endpoint is used to get the details of a specific album.
@Post("album-info")
async albumInfo(@Body() body: { title: string }): Promise<any>
{
const { title } = body;
return await this.searchService.searchAlbums(title);
}

// This endpoint is used to get songs for a specific mood.
@Get("mood")
async getPlaylistByMood(@Query("mood") mood: string): Promise<any>
{
return await this.searchService.getPlaylistSongsByMood(mood);
}

// This endpoint is used to get suggested moods and their corresponding songs.
@Get("suggested-moods")
async getSuggestedMoods(): Promise<any>
{
return await this.searchService.getSuggestedMoods();
}

}
Loading

0 comments on commit b06991a

Please sign in to comment.