Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Oct 15, 2024
1 parent 2e1723b commit 167e5ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
29 changes: 16 additions & 13 deletions firebird-ng/src/app/services/server-config.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { ServerConfigService } from './server-config.service';
import * as jsoncParser from 'jsonc-parser';

describe('FirebirdConfigService', () => {
describe('ServerConfigService', () => {
let service: ServerConfigService;
let httpMock: HttpTestingController;

Expand All @@ -19,21 +18,25 @@ describe('FirebirdConfigService', () => {
afterEach(() => {
httpMock.verify(); // Ensure that no requests are outstanding.
});
//
it('should fetch and parse JSONC data correctly', () => {
const dummyConfig = { apiBaseUrl: "http://localhost:5454" };
const jsoncData = '{ "key": "value" // comment }';

it('should fetch and parse JSONC data correctly', async () => {
const jsoncData = '{ "apiBaseUrl": "http://localhost:5454", "logLevel": "info" }';

// Call loadConfig()
const loadPromise = service.loadConfig();

// Set up the HttpTestingController
const req = httpMock.expectOne(service['configUrl']);
expect(req.request.method).toBe('GET');
req.flush('{ "apiBaseUrl": "http://localhost:5454", "logLevel": "info" }'); // Mock the HTTP response

service.loadConfig().then(()=>{
expect(service.config.apiBaseUrl).toBe("http://localhost:5454");
});
// Mock the HTTP response
req.flush(jsoncData);

// Wait for loadConfig() to complete
await loadPromise;

// Verify the config
expect(service.config.apiBaseUrl).toBe("http://localhost:5454");
expect(service.config.logLevel).toBe("info");
});
});


15 changes: 13 additions & 2 deletions firebird-ng/src/app/services/user-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('UrlService', () => {

const mockServerConfigService = {
config: {
servedByPyrobird: false,
apiBaseUrl: 'http:/localhost:4545'
servedByPyrobird: true,
apiBaseUrl: 'http://localhost:5454'
}
};

Expand Down Expand Up @@ -68,8 +68,13 @@ describe('UrlService', () => {

it('should handle relative URL without protocol when backend is not available (Case 1.2)', () => {
// Ensure backend is not available
serverConfigService.config.servedByPyrobird = false;
userConfigService.localServerUseApi.subject.next(false);

// Manually trigger the service to update its config
(service as any).updateServerConfig();


const inputUrl = '/path/to/file.root';
const resolvedUrl = service.resolveDownloadUrl(inputUrl);
expect(resolvedUrl).toBe(inputUrl);
Expand Down Expand Up @@ -120,8 +125,14 @@ describe('UrlService', () => {

it('should return input URL when backend is not available', () => {
// Ensure backend is not available
// Ensure backend is not available
serverConfigService.config.servedByPyrobird = false;
userConfigService.localServerUseApi.subject.next(false);

// Manually trigger the service to update its config
(service as any).updateServerConfig();


const inputUrl = 'https://example.com/file.root';
const fileType = 'edm4eic';
const entries = 'all';
Expand Down

0 comments on commit 167e5ca

Please sign in to comment.