feat: Android APP V1 - Experimental Alpha
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
|
||||
import { PlatformService } from '../../core/platform';
|
||||
import { BrowserDatabaseService } from './browser-database.service';
|
||||
import { CapacitorDatabaseService } from './capacitor-database.service';
|
||||
import { DatabaseService } from './database.service';
|
||||
import { ElectronDatabaseService } from './electron-database.service';
|
||||
|
||||
@@ -20,6 +21,10 @@ describe('DatabaseService', () => {
|
||||
getBansForRoom: ReturnType<typeof vi.fn>;
|
||||
initialize: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
let capacitorDatabase: {
|
||||
getBansForRoom: ReturnType<typeof vi.fn>;
|
||||
initialize: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
let electronDatabase: {
|
||||
getBansForRoom: ReturnType<typeof vi.fn>;
|
||||
initialize: ReturnType<typeof vi.fn>;
|
||||
@@ -30,18 +35,23 @@ describe('DatabaseService', () => {
|
||||
getBansForRoom: vi.fn(() => Promise.resolve([])),
|
||||
initialize: vi.fn(() => Promise.resolve())
|
||||
};
|
||||
capacitorDatabase = {
|
||||
getBansForRoom: vi.fn(() => Promise.resolve([])),
|
||||
initialize: vi.fn(() => Promise.resolve())
|
||||
};
|
||||
electronDatabase = {
|
||||
getBansForRoom: vi.fn(() => Promise.resolve([])),
|
||||
initialize: vi.fn(() => Promise.resolve())
|
||||
};
|
||||
});
|
||||
|
||||
function createService(): DatabaseService {
|
||||
function createService(platform: Pick<PlatformService, 'isBrowser' | 'isElectron' | 'isCapacitor'>): DatabaseService {
|
||||
const injector = Injector.create({
|
||||
providers: [
|
||||
DatabaseService,
|
||||
{ provide: PlatformService, useValue: { isBrowser: true, isElectron: false } },
|
||||
{ provide: PlatformService, useValue: platform },
|
||||
{ provide: BrowserDatabaseService, useValue: browserDatabase },
|
||||
{ provide: CapacitorDatabaseService, useValue: capacitorDatabase },
|
||||
{ provide: ElectronDatabaseService, useValue: electronDatabase }
|
||||
]
|
||||
});
|
||||
@@ -49,13 +59,35 @@ describe('DatabaseService', () => {
|
||||
return runInInjectionContext(injector, () => injector.get(DatabaseService));
|
||||
}
|
||||
|
||||
it('initializes the selected backend before the first delegated read', async () => {
|
||||
const service = createService();
|
||||
it('initializes the browser backend before the first delegated read', async () => {
|
||||
const service = createService({ isBrowser: true, isElectron: false, isCapacitor: false });
|
||||
|
||||
await service.getBansForRoom('room-1');
|
||||
|
||||
expect(browserDatabase.initialize).toHaveBeenCalledTimes(1);
|
||||
expect(browserDatabase.getBansForRoom).toHaveBeenCalledWith('room-1');
|
||||
expect(capacitorDatabase.initialize).not.toHaveBeenCalled();
|
||||
expect(service.isReady()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('routes Capacitor shells to native SQLite instead of IndexedDB', async () => {
|
||||
const service = createService({ isBrowser: false, isElectron: false, isCapacitor: true });
|
||||
|
||||
await service.getBansForRoom('room-1');
|
||||
|
||||
expect(capacitorDatabase.initialize).toHaveBeenCalledTimes(1);
|
||||
expect(capacitorDatabase.getBansForRoom).toHaveBeenCalledWith('room-1');
|
||||
expect(browserDatabase.initialize).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('routes Electron shells to the IPC SQLite backend', async () => {
|
||||
const service = createService({ isBrowser: false, isElectron: true, isCapacitor: false });
|
||||
|
||||
await service.getBansForRoom('room-1');
|
||||
|
||||
expect(electronDatabase.initialize).toHaveBeenCalledTimes(1);
|
||||
expect(electronDatabase.getBansForRoom).toHaveBeenCalledWith('room-1');
|
||||
expect(browserDatabase.initialize).not.toHaveBeenCalled();
|
||||
expect(capacitorDatabase.initialize).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user