Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/services/server-config.service.spec.ts is written in an unsupported language. File is not indexed.

0001 import { TestBed, waitForAsync } from '@angular/core/testing';
0002 import {HttpClientTestingModule, HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing';
0003 import { ServerConfigService } from './server-config.service';
0004 import {provideHttpClient, withInterceptorsFromDi} from "@angular/common/http";
0005 
0006 describe('ServerConfigService', () => {
0007   let service: ServerConfigService;
0008   let httpMock: HttpTestingController;
0009 
0010   beforeEach(() => {
0011     TestBed.configureTestingModule({
0012       imports: [HttpClientTestingModule],
0013       providers: [ServerConfigService,
0014         provideHttpClient(withInterceptorsFromDi()),
0015         provideHttpClientTesting(),]
0016     });
0017     service = TestBed.inject(ServerConfigService);
0018     httpMock = TestBed.inject(HttpTestingController);
0019   });
0020 
0021   afterEach(() => {
0022     httpMock.verify(); // Ensure that no requests are outstanding.
0023   });
0024 
0025   it('should fetch and parse JSONC data correctly', async () => {
0026     const jsoncData = '{ "apiBaseUrl": "http://localhost:5454", "logLevel": "info" }';
0027 
0028     // Call loadConfig()
0029     const loadPromise = service.loadConfig();
0030 
0031     // Set up the HttpTestingController
0032     const req = httpMock.expectOne(service['configUrl']);
0033     expect(req.request.method).toBe('GET');
0034 
0035     // Mock the HTTP response
0036     req.flush(jsoncData);
0037 
0038     // Wait for loadConfig() to complete
0039     await loadPromise;
0040 
0041     // Verify the config
0042     expect(service.config.apiBaseUrl).toBe("http://localhost:5454");
0043     expect(service.config.logLevel).toBe("info");
0044   });
0045 });