import { createSpec } from '@wireapp/store-engine/src/main/test/createSpec' ; import { deleteAllSpec } from '@wireapp/store-engine/src/main/test/deleteAllSpec' ; import { deleteSpec } from '@wireapp/store-engine/src/main/test/deleteSpec' ; import { purgeSpec } from '@wireapp/store-engine/src/main/test/purgeSpec' ; import { readAllPrimaryKeysSpec } from '@wireapp/store-engine/src/main/test/readAllPrimaryKeysSpec' ; import { readAllSpec } from '@wireapp/store-engine/src/main/test/readAllSpec' ; import { readSpec } from '@wireapp/store-engine/src/main/test/readSpec' ; import { updateOrCreateSpec } from '@wireapp/store-engine/src/main/test/updateOrCreateSpec' ; import { updateSpec } from '@wireapp/store-engine/src/main/test/updateSpec' ; import * as fs from 'bro-fs' ; import { FileSystemEngine } from './index' ; describe ( 'FileSystemEngine' , ( ) => { const STORE_NAME = 'store-name' ; let engine ; async function initEngine ( shouldCreateNewEngine = true ) { const storeEngine = shouldCreateNewEngine ? new FileSystemEngine ( ) : engine ; await storeEngine . init ( STORE_NAME ) ; return storeEngine ; } beforeEach ( async ( ) => { engine = await initEngine ( ) ; } ) ; afterEach ( ( ) => fs . rmdir ( STORE_NAME ) ) ; describe ( 'init' , ( ) => { it ( 'resolves with a browser-specific URL to the filesystem.' , async ( ) => { const fileSystem = await engine . init ( 'test-store' ) ; expect ( fileSystem . root . toURL ( ) . startsWith ( 'filesystem:' ) ) . toBe ( true ) ; } ) ; } ) ; describe ( 'create' , ( ) => { Object . entries ( createSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'delete' , ( ) => { Object . entries ( deleteSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'deleteAll' , ( ) => { Object . entries ( deleteAllSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'purge' , ( ) => { Object . entries ( purgeSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine , initEngine ) ) ; } ) ; } ) ; describe ( 'readAllPrimaryKeys' , ( ) => { Object . entries ( readAllPrimaryKeysSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'readAll' , ( ) => { Object . entries ( readAllSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'read' , ( ) => { Object . entries ( readSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'updateOrCreate' , ( ) => { Object . entries ( updateOrCreateSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; describe ( 'update' , ( ) => { Object . entries ( updateSpec ) . map ( ( [ description , testFunction ] ) => { it ( description , ( ) => testFunction ( engine ) ) ; } ) ; } ) ; } ) ;