Skip to content

Commit

Permalink
made the track que and the testing files
Browse files Browse the repository at this point in the history
  • Loading branch information
NahGoKrazy committed Sep 27, 2024
1 parent e74bd9e commit c0e643e
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 182 deletions.
170 changes: 84 additions & 86 deletions server/docs/swagger_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,92 +889,6 @@
]
}
},
"/api/group/{id}/spotify": {
"post": {
"tags": [
"Group"
],
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"spotifyEmail": {
"example": "any"
}
}
}
}
],
"responses": {
"200": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"example": "66e9f064f4b6247a0c26291e"
},
"ownerId": {
"type": "string",
"example": "66e8a2e7f4b6247a0c262910"
},
"name": {
"type": "string",
"example": "group"
},
"spotifyAuthId": {
"type": "string",
"example": "66e9fbbcb14c1ccc11b3d8fd"
}
},
"xml": {
"name": "main"
}
},
"description": "Monitor updated"
},
"400": {
"schema": {
"$ref": "#/definitions/Error400"
},
"description": "Bad request"
},
"404": {
"schema": {
"$ref": "#/definitions/Error404"
},
"description": "Not found"
},
"500": {
"schema": {
"$ref": "#/definitions/Error500"
},
"description": "Internal Server Error"
},
"501": {
"schema": {
"$ref": "#/definitions/Error501"
},
"description": "Not implemented"
}
},
"security": [
{
"Bearer": []
}
]
}
},
"/api/group/{id}/spotify/current-track": {
"get": {
"tags": [
Expand Down Expand Up @@ -1287,6 +1201,90 @@
"Bearer": []
}
]
},
"post": {
"tags": [
"Group"
],
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"spotifyEmail": {
"example": "any"
}
}
}
}
],
"responses": {
"200": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"example": "66e9f064f4b6247a0c26291e"
},
"ownerId": {
"type": "string",
"example": "66e8a2e7f4b6247a0c262910"
},
"name": {
"type": "string",
"example": "group"
},
"spotifyAuthId": {
"type": "string",
"example": "66e9fbbcb14c1ccc11b3d8fd"
}
},
"xml": {
"name": "main"
}
},
"description": "Monitor updated"
},
"400": {
"schema": {
"$ref": "#/definitions/Error400"
},
"description": "Bad request"
},
"404": {
"schema": {
"$ref": "#/definitions/Error404"
},
"description": "Not found"
},
"500": {
"schema": {
"$ref": "#/definitions/Error500"
},
"description": "Internal Server Error"
},
"501": {
"schema": {
"$ref": "#/definitions/Error501"
},
"description": "Not implemented"
}
},
"security": [
{
"Bearer": []
}
]
}
},
"/api/group/groups": {
Expand Down
179 changes: 100 additions & 79 deletions server/services/tests/trackQueue.test.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,107 @@
import { TrackQueueItem } from '../trackQueue'
import { TrackQueue } from '../trackQueue'
import type { Track } from '@spotify/web-api-ts-sdk'
import { TrackQueueItem } from '../trackQueue';
import { TrackQueue } from '../trackQueue';
import type { Track } from '@spotify/web-api-ts-sdk';

describe('TrackQueue Tests', () => {
let queue: TrackQueue;
const sometrack: Track = {
id: '1',
name: 'Test Track',
duration_ms: 300000,
album: {
id: 'album-id',
name: 'Test Album',
album_type: 'album',
album_group: 'album',
artists: [],
available_markets: [],
href: 'https://api.spotify.com/v1/albums/album-id',
images: [],
release_date: '2021-01-01',
release_date_precision: 'day',
total_tracks: 10,
type: 'album',
uri: 'spotify:album:album-id',
copyrights: [
{ text: '© 2021 Test Label', type: 'C' },
{ text: '℗ 2021 Test Label', type: 'P' }
],
external_ids: {
upc: '123456789012',
ean: '1234567890123',
isrc: 'USUM71702776'
},
external_urls: {
spotify: 'https://open.spotify.com/album/album-id'
},
genres: ['pop'],
label: 'Test Label',
popularity: 75
},
external_ids: {
upc: '123456789012',
ean: '1234567890123',
isrc: 'USUM71702776'
},
popularity: 0,
artists: [
{
id: 'artist1',
name: 'Artist 1',
href: '',
external_urls: {
spotify: 'https://open.spotify.com/artist/1'
},
type: 'artist',
uri: 'spotify:artist:1'
}
],
available_markets: [],
disc_number: 1,
episode: false,
explicit: false,
external_urls: {
spotify: 'https://open.spotify.com/track/1'
},
href: 'https://api.spotify.com/v1/tracks/1',
is_local: false,
preview_url: null,
track: true,
track_number: 1,
type: 'track',
uri: 'spotify:track:1'
};

describe('Test TackQue', () => {
const queue = new TrackQueue("testid");
queue.push(sometrack)
it('should push to queue', () => {
beforeEach(() => {
queue = new TrackQueue("testid");
});

it('should push to the queue', () => {
queue.push(sometrack);
expect(queue.peek()).toBe(sometrack);

});

// it('should add tracks and pop in order', () => {})
// it('should not pop track if peeked', () => {})
})
it('should pop tracks in the correct order', () => {
queue.push(sometrack);
const anotherTrack = { ...sometrack, id: '2', name: 'Another Track' };
queue.push(anotherTrack);

expect(queue.pop()).toBe(sometrack);
expect(queue.pop()).toBe(anotherTrack);
});

//sample track
const sometrack: Track = {
id: '1',
name: 'Test Track',
duration_ms: 300000, // The track's duration in milliseconds
album: {
id: 'album-id',
name: 'Test Album',
album_type: 'album',
album_group: 'album',
artists: [],
available_markets: [],
href: 'https://api.spotify.com/v1/albums/album-id',
images: [],
release_date: '2021-01-01',
release_date_precision: 'day',
total_tracks: 10,
type: 'album',
uri: 'spotify:album:album-id',
copyrights: [
{ text: '© 2021 Test Label', type: 'C' },
{ text: '℗ 2021 Test Label', type: 'P' }
],
external_ids: {
upc: '123456789012', // Example UPC
ean: '1234567890123', // Example EAN
isrc: 'USUM71702776' // Example ISRC
},
external_urls: {
spotify: 'https://open.spotify.com/album/album-id'
},
genres: ['pop'],
label: 'Test Label',
popularity: 75
},
external_ids: {
upc: '123456789012', // Required UPC field
ean: '1234567890123', // Required EAN field
isrc: 'USUM71702776' // Required ISRC field
},
popularity: 0,
artists: [
{
id: 'artist1',
name: 'Artist 1',
href: '',
external_urls: {
spotify: 'https://open.spotify.com/artist/1'
},
type: 'artist',
uri: 'spotify:artist:1'
}
],
available_markets: [],
disc_number: 1,
episode: false,
explicit: false,
external_urls: {
spotify: 'https://open.spotify.com/track/1'
},
href: 'https://api.spotify.com/v1/tracks/1',
is_local: false,
preview_url: null,
track: true,
track_number: 1,
type: 'track',
uri: 'spotify:track:1'
};
it('should not pop a track if only peeked', () => {
queue.push(sometrack);
expect(queue.peek()).toBe(sometrack);
expect(queue.peek()).toBe(sometrack); // Queue should remain unchanged
expect(queue.pop()).toBe(sometrack); // Now pop should return the track
});

it('should return undefined when popping an empty queue', () => {
expect(queue.pop()).toBeUndefined();
});

it('should return undefined when peeking an empty queue', () => {
expect(queue.peek()).toBeUndefined();
});
});
Loading

0 comments on commit c0e643e

Please sign in to comment.