Fixing tests
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Successful in 51s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Failing after 1m29s
Music Collection CI Workflow / deploy (push) Has been skipped
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Successful in 51s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Failing after 1m29s
Music Collection CI Workflow / deploy (push) Has been skipped
This commit is contained in:
parent
e687852cfa
commit
4f389f70af
@ -59,15 +59,15 @@ describe('AlbumController', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should return the Album ID', async () => {
|
it('should return the Album', async () => {
|
||||||
expect(await controller.create(mockCreateAlbumDto)).toStrictEqual(mockAlbum);
|
expect(await controller.create(mockCreateAlbumDto)).toStrictEqual({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' });
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update', () => {
|
describe('update', () => {
|
||||||
it('should return the success message', async () => {
|
it('should return the Album', async () => {
|
||||||
mockUpdateAlbumDto.id = 1;
|
mockUpdateAlbumDto.id = 1;
|
||||||
expect(await controller.update(1, mockUpdateAlbumDto)).toStrictEqual(mockAlbum);
|
expect(await controller.update(1, mockUpdateAlbumDto)).toStrictEqual({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' });
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ describe('AlbumService', () => {
|
|||||||
findOneBy: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
findOneBy: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
||||||
create: jest.fn().mockResolvedValue(mockAlbum),
|
create: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
save: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
save: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
||||||
update: jest.fn().mockResolvedValue(mockAlbum),
|
update: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
||||||
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -55,15 +55,15 @@ describe('AlbumService', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should return the Album ID', async () => {
|
it('should return the Album', async () => {
|
||||||
expect(await service.create(mockCreateAlbumDto)).toStrictEqual(mockAlbum);
|
expect(await service.create(mockCreateAlbumDto)).toStrictEqual({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' });
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update', () => {
|
describe('update', () => {
|
||||||
it('should return the success message', async () => {
|
it('should return the Album', async () => {
|
||||||
mockUpdateAlbumDto.id = 1;
|
mockUpdateAlbumDto.id = 1;
|
||||||
expect(await service.update(1, mockUpdateAlbumDto)).toStrictEqual(mockAlbum);
|
expect(await service.update(1, mockUpdateAlbumDto)).toStrictEqual({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' });
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -44,15 +44,14 @@ export class AlbumService {
|
|||||||
|
|
||||||
async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
|
async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
|
||||||
if (id === updateAlbumDto.id) {
|
if (id === updateAlbumDto.id) {
|
||||||
const album = this.albumRepository.findOneBy({ id: updateAlbumDto.id });
|
const albumToUpdate = await this.albumRepository.findOneBy({ id: updateAlbumDto.id });
|
||||||
if (!album)
|
if (!albumToUpdate)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
const savedAlbum = await this.albumRepository.update({ id: updateAlbumDto.id }, {
|
albumToUpdate.title = updateAlbumDto.title;
|
||||||
title: updateAlbumDto.title,
|
albumToUpdate.artist = updateAlbumDto.artist;
|
||||||
artist: updateAlbumDto.artist,
|
albumToUpdate.genre = updateAlbumDto.genre;
|
||||||
genre: updateAlbumDto.genre
|
const savedAlbum = await this.albumRepository.save(albumToUpdate);
|
||||||
});
|
|
||||||
return savedAlbum;
|
return savedAlbum;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,13 +22,13 @@ export class SongController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@UsePipes(new ValidationPipe({ transform: true }))
|
@UsePipes(new ValidationPipe({ transform: true }))
|
||||||
async create(@Body() createSongDto: CreateSongDto): Promise<number> {
|
async create(@Body() createSongDto: CreateSongDto): Promise<Song | null> {
|
||||||
return this.songService.create(createSongDto);
|
return this.songService.create(createSongDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@UsePipes(new ValidationPipe({ transform: true }))
|
@UsePipes(new ValidationPipe({ transform: true }))
|
||||||
async update(@Param('id') id: number, @Body() updateSongDto: UpdateSongDto): Promise<string> {
|
async update(@Param('id') id: number, @Body() updateSongDto: UpdateSongDto): Promise<Song | null> {
|
||||||
return this.songService.update(id, updateSongDto);
|
return this.songService.update(id, updateSongDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export class SongService {
|
|||||||
return this.songRepository.findOneBy({ id: id });
|
return this.songRepository.findOneBy({ id: id });
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(createSongDto: CreateSongDto): Promise<number> {
|
async create(createSongDto: CreateSongDto): Promise<Song | null> {
|
||||||
const album = await this.albumRepository.findOneBy({id: createSongDto.albumId});
|
const album = await this.albumRepository.findOneBy({id: createSongDto.albumId});
|
||||||
if (album) {
|
if (album) {
|
||||||
const song = new Song();
|
const song = new Song();
|
||||||
@ -36,28 +36,28 @@ export class SongService {
|
|||||||
song.trackNumber = createSongDto.trackNumber;
|
song.trackNumber = createSongDto.trackNumber;
|
||||||
song.album = album;
|
song.album = album;
|
||||||
const savedSong = await this.songRepository.save(song);
|
const savedSong = await this.songRepository.save(song);
|
||||||
return savedSong.id;
|
return savedSong;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unable to find Album with ID ${createSongDto.albumId}`);
|
throw new Error(`Unable to find Album with ID ${createSongDto.albumId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, updateSongDto: UpdateSongDto): Promise<string> {
|
async update(id: number, updateSongDto: UpdateSongDto): Promise<Song | null> {
|
||||||
if (id === updateSongDto.id) {
|
if (id === updateSongDto.id) {
|
||||||
const album = await this.albumRepository.findOneBy({id: updateSongDto.albumId});
|
const album = await this.albumRepository.findOneBy({id: updateSongDto.albumId});
|
||||||
const songToUpdate = await this.songRepository.findOneBy({ id: updateSongDto.id });
|
const songToUpdate = await this.songRepository.findOneBy({ id: updateSongDto.id });
|
||||||
if (!songToUpdate || !album)
|
if (!songToUpdate || !album)
|
||||||
return "Song not found";
|
return null;
|
||||||
|
|
||||||
songToUpdate.id = updateSongDto.id;
|
songToUpdate.id = updateSongDto.id;
|
||||||
songToUpdate.title = updateSongDto.title;
|
songToUpdate.title = updateSongDto.title;
|
||||||
songToUpdate.duration = updateSongDto.duration;
|
songToUpdate.duration = updateSongDto.duration;
|
||||||
songToUpdate.trackNumber = updateSongDto.trackNumber;
|
songToUpdate.trackNumber = updateSongDto.trackNumber;
|
||||||
songToUpdate.album = album;
|
songToUpdate.album = album;
|
||||||
await this.songRepository.update({ id: updateSongDto.id }, songToUpdate);
|
const song = await this.songRepository.save(songToUpdate);
|
||||||
return "Song updated successfully";
|
return song;
|
||||||
} else {
|
} else {
|
||||||
return "Song ID does not match posted data"
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user