More tests, more debugging
All checks were successful
Music Collection CI Workflow / test (./backend) (push) Successful in 31s
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) Successful in 1m49s
Music Collection CI Workflow / deploy (push) Successful in 26s
All checks were successful
Music Collection CI Workflow / test (./backend) (push) Successful in 31s
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) Successful in 1m49s
Music Collection CI Workflow / deploy (push) Successful in 26s
This commit is contained in:
parent
4efc0bb610
commit
4b76b19422
@ -2,11 +2,18 @@ import { Test, TestingModule } from '@nestjs/testing';
|
|||||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
import { AlbumService } from './album.service';
|
import { AlbumService } from './album.service';
|
||||||
import { Album } from './album.entity';
|
import { Album } from './album.entity';
|
||||||
|
import { CreateAlbumDto } from './dto/create-album.dto';
|
||||||
|
import { UpdateAlbumDto } from './dto/update-album.dto';
|
||||||
|
import { DeleteResult, Repository } from 'typeorm';
|
||||||
|
|
||||||
const mockAlbum = new Album();
|
const mockAlbum = new Album();
|
||||||
|
const mockCreateAlbumDto = new CreateAlbumDto();
|
||||||
|
const mockUpdateAlbumDto = new UpdateAlbumDto();
|
||||||
|
const mockDeleteResult = new DeleteResult();
|
||||||
|
|
||||||
describe('AlbumService', () => {
|
describe('AlbumService', () => {
|
||||||
let service: AlbumService;
|
let service: AlbumService;
|
||||||
|
let repository: Repository<Album>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
@ -15,20 +22,54 @@ describe('AlbumService', () => {
|
|||||||
{
|
{
|
||||||
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' }),
|
||||||
|
create: jest.fn().mockResolvedValue(mockAlbum),
|
||||||
|
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("Album updated successfully"),
|
||||||
remove: jest.fn().mockResolvedValue(null),
|
delete: jest.fn().mockResolvedValue(mockDeleteResult),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
service = module.get<AlbumService>(AlbumService);
|
service = module.get<AlbumService>(AlbumService);
|
||||||
|
repository = module.get<Repository<Album>>(getRepositoryToken(Album));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('findAll', () => {
|
||||||
|
it('should return an array of Albums', async () => {
|
||||||
|
expect(await service.findAll()).toStrictEqual([mockAlbum]);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('findOneById', () => {
|
||||||
|
it('should return an Album', async () => {
|
||||||
|
expect(await service.findOneById(1)).toStrictEqual(mockAlbum);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('create', () => {
|
||||||
|
it('should return the Album ID', async () => {
|
||||||
|
expect(await service.create(mockCreateAlbumDto)).toStrictEqual(1);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('update', () => {
|
||||||
|
it('should return the success message', async () => {
|
||||||
|
mockUpdateAlbumDto.id = 1;
|
||||||
|
expect(await service.update(1, mockUpdateAlbumDto)).toStrictEqual("Album updated successfully");
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('remove', () => {
|
||||||
|
it('should return a DeleteResult', async () => {
|
||||||
|
expect(await service.remove(1)).toStrictEqual(mockDeleteResult);
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
@ -42,10 +42,10 @@ export default function Page() {
|
|||||||
console.log(formData);
|
console.log(formData);
|
||||||
if (formData.get('id') === "") {
|
if (formData.get('id') === "") {
|
||||||
const data = await createAlbum(formData);
|
const data = await createAlbum(formData);
|
||||||
console.log(data);
|
console.log("Created Album", data);
|
||||||
} else {
|
} else {
|
||||||
const data = await updateAlbum(formData);
|
const data = await updateAlbum(formData);
|
||||||
console.log(data);
|
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