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