global filter

This commit is contained in:
2026-03-11 18:04:42 +01:00
parent c2bcac58b3
commit 196e8c80d8
25 changed files with 192 additions and 136 deletions

View File

@@ -7,12 +7,18 @@ import {UploadService} from './upload.service';
describe('UploadService', () => {
let service: UploadService;
let fileDataServiceSpy: jasmine.SpyObj<FileDataService>;
type UploadTaskLike = {
on: (event: string, progress: (snapshot: {bytesTransferred: number; totalBytes: number}) => void, error: () => void, success: () => void) => void;
};
type UploadServiceInternals = UploadService & {
startUpload: (path: string, file: File) => UploadTaskLike;
};
beforeEach(() => {
beforeEach(async () => {
fileDataServiceSpy = jasmine.createSpyObj<FileDataService>('FileDataService', ['set']);
fileDataServiceSpy.set.and.resolveTo('file-1');
void TestBed.configureTestingModule({
await TestBed.configureTestingModule({
providers: [
{provide: Storage, useValue: {app: 'test-storage'}},
{provide: FileDataService, useValue: fileDataServiceSpy},
@@ -27,17 +33,16 @@ describe('UploadService', () => {
});
it('should upload the file, update progress and persist file metadata on success', async () => {
const task = {
const task: UploadTaskLike = {
on: (event: string, progress: (snapshot: {bytesTransferred: number; totalBytes: number}) => void, error: () => void, success: () => void) => {
progress({bytesTransferred: 50, totalBytes: 100});
success();
},
};
const uploadSpy = spyOn<any>(service, 'startUpload').and.returnValue(task as never);
const uploadSpy = spyOn(service as UploadServiceInternals, 'startUpload').and.returnValue(task);
const upload = new Upload(new File(['content'], 'test.pdf', {type: 'application/pdf'}));
service.pushUpload('song-1', upload);
await Promise.resolve();
await service.pushUpload('song-1', upload);
expect(uploadSpy).toHaveBeenCalledWith('/attachments/song-1/test.pdf', upload.file);
expect(upload.progress).toBe(50);