import { pokedex } from '@magnetarjs/test-utils' ; import test from 'ava' ; import { createMagnetarInstance } from '../helpers/createMagnetarInstance' ; test ( 'delete (document)' , async ( t ) => { const { trainerModule } = createMagnetarInstance ( ) ; t . deepEqual ( trainerModule . data , { age : 10 , name : 'Luca' } ) ; try { await trainerModule . delete ( ) ; } catch ( error ) { t . fail ( JSON . stringify ( error ) ) ; } t . deepEqual ( trainerModule . data , undefined ) ; } ) ; test ( 'delete (collection)' , async ( t ) => { const { pokedexModule } = createMagnetarInstance ( ) ; t . is ( pokedexModule . data . size , 1 ) ; t . deepEqual ( pokedexModule . data . get ( '1' ) , pokedex ( 1 ) ) ; try { await pokedexModule . delete ( '1' ) ; } catch ( error ) { t . fail ( JSON . stringify ( error ) ) ; } t . is ( pokedexModule . data . size , 0 ) ; t . deepEqual ( pokedexModule . data . get ( '1' ) , undefined ) ; } ) ; test ( 'revert: delete (local → remote)' , async ( t ) => { const { trainerModule } = createMagnetarInstance ( ) ; t . deepEqual ( trainerModule . data , { age : 10 , name : 'Luca' } ) ; try { await trainerModule . delete ( 'remote' , { onError : 'revert' , executionOrder : [ 'local' , 'remote' ] } ) ; } catch ( error ) { t . truthy ( error ) ; } t . deepEqual ( trainerModule . data , { age : 10 , name : 'Luca' } ) ; } ) ;