-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from COS301-SE-2024/develop
Develop
- Loading branch information
Showing
144 changed files
with
4,745 additions
and
2,674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ dist-ssr | |
*.sln | ||
*.sw? | ||
.prettierrc | ||
|
||
Frontend/coverage | ||
.env | ||
*.base64 | ||
Frontend/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.