Reworking api responses
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Failing after 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) Has been skipped
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been skipped
Music Collection CI Workflow / deploy (push) Has been skipped
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Failing after 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) Has been skipped
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been skipped
Music Collection CI Workflow / deploy (push) Has been skipped
This commit is contained in:
parent
4b76b19422
commit
cf2dfae319
@ -30,7 +30,7 @@ describe('AlbumController', () => {
|
|||||||
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("Album updated successfully"),
|
update: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -60,14 +60,14 @@ describe('AlbumController', () => {
|
|||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should return the Album ID', async () => {
|
it('should return the Album ID', async () => {
|
||||||
expect(await controller.create(mockCreateAlbumDto)).toStrictEqual(1);
|
expect(await controller.create(mockCreateAlbumDto)).toStrictEqual(mockAlbum);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update', () => {
|
describe('update', () => {
|
||||||
it('should return the success message', async () => {
|
it('should return the success message', async () => {
|
||||||
mockUpdateAlbumDto.id = 1;
|
mockUpdateAlbumDto.id = 1;
|
||||||
expect(await controller.update(1, mockUpdateAlbumDto)).toStrictEqual("Album updated successfully");
|
expect(await controller.update(1, mockUpdateAlbumDto)).toStrictEqual(mockAlbum);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ export class AlbumController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@UsePipes(new ValidationPipe({ transform: true }))
|
@UsePipes(new ValidationPipe({ transform: true }))
|
||||||
async create(@Body() createAlbumDto: CreateAlbumDto): Promise<number> {
|
async create(@Body() createAlbumDto: CreateAlbumDto): Promise<Album | null> {
|
||||||
return this.albumService.create(createAlbumDto);
|
return this.albumService.create(createAlbumDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@UsePipes(new ValidationPipe({ transform: true }))
|
@UsePipes(new ValidationPipe({ transform: true }))
|
||||||
async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise<string> {
|
async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
|
||||||
return this.albumService.update(id, updateAlbumDto);
|
return this.albumService.update(id, updateAlbumDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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("Album updated successfully"),
|
update: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -56,14 +56,14 @@ describe('AlbumService', () => {
|
|||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should return the Album ID', async () => {
|
it('should return the Album ID', async () => {
|
||||||
expect(await service.create(mockCreateAlbumDto)).toStrictEqual(1);
|
expect(await service.create(mockCreateAlbumDto)).toStrictEqual(mockAlbum);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update', () => {
|
describe('update', () => {
|
||||||
it('should return the success message', async () => {
|
it('should return the success message', async () => {
|
||||||
mockUpdateAlbumDto.id = 1;
|
mockUpdateAlbumDto.id = 1;
|
||||||
expect(await service.update(1, mockUpdateAlbumDto)).toStrictEqual("Album updated successfully");
|
expect(await service.update(1, mockUpdateAlbumDto)).toStrictEqual(mockAlbum);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -32,30 +32,30 @@ export class AlbumService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(createAlbumDto: CreateAlbumDto): Promise<number> {
|
async create(createAlbumDto: CreateAlbumDto): Promise<Album | null> {
|
||||||
const album = this.albumRepository.create({
|
const album = this.albumRepository.create({
|
||||||
title: createAlbumDto.title,
|
title: createAlbumDto.title,
|
||||||
artist: createAlbumDto.artist,
|
artist: createAlbumDto.artist,
|
||||||
genre: createAlbumDto.genre
|
genre: createAlbumDto.genre
|
||||||
});
|
});
|
||||||
const savedAlbum = await this.albumRepository.save(album);
|
const savedAlbum = await this.albumRepository.save(album);
|
||||||
return savedAlbum.id;
|
return savedAlbum;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<string> {
|
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 album = this.albumRepository.findOneBy({ id: updateAlbumDto.id });
|
||||||
if (!album)
|
if (!album)
|
||||||
return "Album not found";
|
return null;
|
||||||
|
|
||||||
await this.albumRepository.update({ id: updateAlbumDto.id }, {
|
const savedAlbum = await this.albumRepository.update({ id: updateAlbumDto.id }, {
|
||||||
title: updateAlbumDto.title,
|
title: updateAlbumDto.title,
|
||||||
artist: updateAlbumDto.artist,
|
artist: updateAlbumDto.artist,
|
||||||
genre: updateAlbumDto.genre
|
genre: updateAlbumDto.genre
|
||||||
});
|
});
|
||||||
return "Album updated successfully";
|
return savedAlbum;
|
||||||
} else {
|
} else {
|
||||||
return "Album ID does not match posted data";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,15 @@ import { SongController } from './song.controller';
|
|||||||
import { SongService } from './song.service';
|
import { SongService } from './song.service';
|
||||||
import { Song } from './song.entity';
|
import { Song } from './song.entity';
|
||||||
import { Album } from '../album/album.entity';
|
import { Album } from '../album/album.entity';
|
||||||
|
import { CreateSongDto } from './dto/create-song.dto';
|
||||||
|
import { UpdateSongDto } from './dto/update-song.dto';
|
||||||
|
import { DeleteResult, Repository } from 'typeorm';
|
||||||
|
|
||||||
const mockSong = new Song();
|
const mockSong = new Song();
|
||||||
const mockAlbum = new Album();
|
const mockAlbum = new Album();
|
||||||
|
const mockCreateSongDto = new CreateSongDto();
|
||||||
|
const mockUpdateSongDto = new UpdateSongDto();
|
||||||
|
const mockDeleteResult = new DeleteResult();
|
||||||
|
|
||||||
describe('SongController', () => {
|
describe('SongController', () => {
|
||||||
let controller: SongController;
|
let controller: SongController;
|
||||||
@ -19,21 +25,25 @@ describe('SongController', () => {
|
|||||||
{
|
{
|
||||||
provide: getRepositoryToken(Song),
|
provide: getRepositoryToken(Song),
|
||||||
useValue: {
|
useValue: {
|
||||||
findAll: jest.fn().mockResolvedValue([mockSong]),
|
find: jest.fn().mockResolvedValue([mockSong]),
|
||||||
findOneById: jest.fn().mockResolvedValue(mockSong),
|
findOne: jest.fn().mockResolvedValue(mockSong),
|
||||||
create: jest.fn().mockResolvedValue(1),
|
findOneBy: jest.fn().mockResolvedValue({ id: 3, title: 'some song', duration: 300, trackNumber: 2, album: mockAlbum }),
|
||||||
update: jest.fn().mockResolvedValue("Song updated successfully"),
|
create: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
remove: jest.fn().mockResolvedValue(null),
|
save: jest.fn().mockResolvedValue({ id: 3, title: 'some song', duration: 300, trackNumber: 2, album: mockAlbum }),
|
||||||
|
update: jest.fn().mockResolvedValue(mockDSong),
|
||||||
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: getRepositoryToken(Album),
|
provide: getRepositoryToken(Album),
|
||||||
useValue: {
|
useValue: {
|
||||||
findAll: jest.fn().mockResolvedValue([mockAlbum]),
|
find: jest.fn().mockResolvedValue([mockAlbum]),
|
||||||
findOneById: jest.fn().mockResolvedValue(mockAlbum),
|
findOne: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
create: jest.fn().mockResolvedValue(1),
|
findOneBy: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
||||||
update: jest.fn().mockResolvedValue("Album updated successfully"),
|
create: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
remove: jest.fn().mockResolvedValue(null),
|
save: jest.fn().mockResolvedValue({ id: 1, title: 'some album', artist: 'some artist', genre: 'some genre' }),
|
||||||
|
update: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -41,11 +41,11 @@ export default function Page() {
|
|||||||
try {
|
try {
|
||||||
console.log(formData);
|
console.log(formData);
|
||||||
if (formData.get('id') === "") {
|
if (formData.get('id') === "") {
|
||||||
|
console.log("Creating Album");
|
||||||
const data = await createAlbum(formData);
|
const data = await createAlbum(formData);
|
||||||
console.log("Created Album", data);
|
|
||||||
} else {
|
} else {
|
||||||
|
console.log("Updating Album");
|
||||||
const data = await updateAlbum(formData);
|
const data = await updateAlbum(formData);
|
||||||
console.log("Updated Album", data);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error creating Album: ", error);
|
console.error("Error creating Album: ", error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user