11import { s } from '../../../json-crdt-patch' ;
22import { Model } from '../../model' ;
33import { File } from '../File' ;
4+ import { JsonDecoder } from '../../../json-pack/json/JsonDecoder' ;
5+ import { CborDecoder } from '../../../json-pack/cbor/CborDecoder' ;
6+
7+ const setup = ( view : unknown ) => {
8+ const model = Model . withServerClock ( ) ;
9+ model . api . root ( view ) ;
10+ const file = File . fromModel ( model ) ;
11+ return { model, file} ;
12+ } ;
413
514test ( 'can create File from new model' , ( ) => {
615 const model = Model . withServerClock ( ) . setSchema (
@@ -18,3 +27,23 @@ test('can create File from new model', () => {
1827
1928test . todo ( 'patches are flushed and stored in memory' ) ;
2029test . todo ( 'can replay history' ) ;
30+
31+ describe ( '.toBinary()' , ( ) => {
32+ describe ( 'can read first value as view' , ( ) => {
33+ test ( '.ndjson' , ( ) => {
34+ const { file} = setup ( { foo : 'bar' } ) ;
35+ const blob = file . toBinary ( { format : 'ndjson' , model : 'compact' , history : 'compact' } ) ;
36+ const decoder = new JsonDecoder ( ) ;
37+ const view = decoder . read ( blob ) ;
38+ expect ( view ) . toEqual ( { foo : 'bar' } ) ;
39+ } ) ;
40+
41+ test ( '.seq.cbor' , ( ) => {
42+ const { file} = setup ( { foo : 'bar' } ) ;
43+ const blob = file . toBinary ( { format : 'seq.cbor' } ) ;
44+ const decoder = new CborDecoder ( ) ;
45+ const view = decoder . read ( blob ) ;
46+ expect ( view ) . toEqual ( { foo : 'bar' } ) ;
47+ } ) ;
48+ } ) ;
49+ } ) ;
0 commit comments