Skip to content

Commit

Permalink
NAS-134329: Show core.download job errors
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft committed Mar 4, 2025
1 parent 560f0a7 commit a22b1a8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/app/services/download.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { HttpClient } from '@angular/common/http';
import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator/jest';
import { Store } from '@ngrx/store';
import { of } from 'rxjs';
import { mockApi, mockCall } from 'app/core/testing/utils/mock-api.utils';
import { JobState } from 'app/enums/job-state.enum';
import { ApiService } from 'app/modules/websocket/api.service';
import { DownloadService } from 'app/services/download.service';

describe('DownloadService', () => {
Expand All @@ -9,6 +14,9 @@ describe('DownloadService', () => {
service: DownloadService,
providers: [
mockProvider(HttpClient),
mockApi([
mockCall('core.download', [123, 'http://localhost/download.file']),
]),
],
});

Expand Down Expand Up @@ -56,4 +64,29 @@ describe('DownloadService', () => {
.toHaveBeenCalledWith(new Blob([content], { type: 'text/plain' }), filename);
});
});

describe('coreDownload', () => {
it('calls core.download, waits for job to complete and then downloads the file', () => {
jest.spyOn(spectator.inject(Store), 'select').mockReturnValue(of({
id: 123,
time_finished: {
$date: (new Date()).getTime(),
},
state: JobState.Finished,
}));
jest.spyOn(spectator.service, 'downloadUrl').mockReturnValue(of(new Blob()));

spectator.service.coreDownload({
fileName: 'test.csr',
method: 'filesystem.get',
arguments: ['argument'],
mimeType: 'application/x-x509-user-cert',
}).subscribe();

expect(spectator.inject(ApiService).call)
.toHaveBeenCalledWith('core.download', ['filesystem.get', ['argument'], 'test.csr']);
expect(spectator.inject(DownloadService).downloadUrl)
.toHaveBeenCalledWith('http://localhost/download.file', 'test.csr', 'application/x-x509-user-cert');
});
});
});

0 comments on commit a22b1a8

Please sign in to comment.