add unit tests

This commit is contained in:
2026-03-10 00:05:08 +01:00
parent db6a230696
commit 7170e4a08e
17 changed files with 862 additions and 50 deletions

View File

@@ -1,16 +1,40 @@
import {TestBed} from '@angular/core/testing';
import {of} from 'rxjs';
import {DbService} from './db.service';
import {ConfigService} from './config.service';
describe('ConfigService', () => {
let service: ConfigService;
let dbServiceSpy: jasmine.SpyObj<DbService>;
beforeEach(() => {
void TestBed.configureTestingModule({});
dbServiceSpy = jasmine.createSpyObj<DbService>('DbService', ['doc$']);
dbServiceSpy.doc$.and.returnValue(of({copyright: 'CCLI'}) as never);
void TestBed.configureTestingModule({
providers: [{provide: DbService, useValue: dbServiceSpy}],
});
service = TestBed.inject(ConfigService);
});
it('should be created', () => {
void expect(service).toBeTruthy();
expect(service).toBeTruthy();
});
it('should read the global config document once on creation', () => {
expect(dbServiceSpy.doc$).toHaveBeenCalledTimes(1);
expect(dbServiceSpy.doc$).toHaveBeenCalledWith('global/config');
});
it('should expose the shared config stream via get$', done => {
service.get$().subscribe(config => {
expect(config).toEqual({copyright: 'CCLI'} as never);
done();
});
});
it('should resolve the current config via get()', async () => {
await expectAsync(service.get()).toBeResolvedTo({copyright: 'CCLI'} as never);
});
});