@@ -96,6 +96,115 @@ describe("CachingLayer", function() {
9696 } ) ;
9797 } ) ;
9898
99+ describe ( "#delete" , function ( ) {
100+ describe ( "when connected" , function ( ) {
101+ beforeEach ( async function ( ) {
102+ this . rs . remote . connected = true ;
103+ this . rs . remote . online = true ;
104+ this . rs . caching . enable ( "/foo/" ) ;
105+
106+ await this . rs . local . setNodes ( {
107+ "/foo/" : {
108+ path : "/foo/" ,
109+ common : {
110+ itemsMap : {
111+ "one" : true ,
112+ "two" : true
113+ } ,
114+ contentType : "application/ld+json" ,
115+ timestamp : new Date ( ) . getTime ( ) ,
116+ revision : "oldie-but-goodie"
117+ }
118+ } ,
119+ "/foo/one" : {
120+ path : "/foo/one" ,
121+ common : {
122+ body : "some data" ,
123+ contentType : "text/plain" ,
124+ timestamp : new Date ( ) . getTime ( ) ,
125+ revision : "123456"
126+ }
127+ } ,
128+ "/foo/two" : {
129+ path : "/foo/two" ,
130+ common : {
131+ body : "some other data" ,
132+ contentType : "text/plain" ,
133+ timestamp : new Date ( ) . getTime ( ) ,
134+ revision : "abcdef"
135+ }
136+ }
137+ } ) ;
138+
139+ await this . rs . local . delete ( '/foo/one' , this . rs . remote . connected ) ;
140+ } ) ;
141+
142+ it ( "marks the node for deletion" , async function ( ) {
143+ const nodes = await this . rs . local . getNodes ( [ "/foo/" , "/foo/one" ] ) ;
144+ const folder = nodes [ "/foo/" ] ;
145+ const node = nodes [ "/foo/one" ] ;
146+
147+ expect ( Object . keys ( folder . common . itemsMap ) ) . to . deep . equal ( [ "one" , "two" ] ) ;
148+ expect ( Object . keys ( folder . local . itemsMap ) ) . to . deep . equal ( [ "two" ] ) ;
149+ expect ( node . local . body ) . to . be . false ;
150+ expect ( node . push . body ) . to . be . false ;
151+ } ) ;
152+ } ) ;
153+
154+ describe ( "when disconnected" , function ( ) {
155+ beforeEach ( async function ( ) {
156+ this . rs . remote . connected = false ;
157+ this . rs . remote . online = false ;
158+ this . rs . caching . enable ( "/foo/" ) ;
159+
160+ await this . rs . local . setNodes ( {
161+ "/foo/" : {
162+ path : "/foo/" ,
163+ local : {
164+ itemsMap : {
165+ "one" : true ,
166+ "two" : true
167+ } ,
168+ contentType : "application/ld+json" ,
169+ timestamp : new Date ( ) . getTime ( ) ,
170+ revision : "oldie-but-goodie"
171+ }
172+ } ,
173+ "/foo/one" : {
174+ path : "/foo/one" ,
175+ local : {
176+ body : "some data" ,
177+ contentType : "text/plain" ,
178+ timestamp : new Date ( ) . getTime ( ) ,
179+ revision : "123456"
180+ }
181+ } ,
182+ "/foo/two" : {
183+ path : "/foo/two" ,
184+ local : {
185+ body : "some other data" ,
186+ contentType : "text/plain" ,
187+ timestamp : new Date ( ) . getTime ( ) ,
188+ revision : "abcdef"
189+ }
190+ }
191+ } ) ;
192+
193+ await this . rs . local . delete ( '/foo/one' , this . rs . remote . connected ) ;
194+ } ) ;
195+
196+ it ( "deletes the node immediately" , async function ( ) {
197+ const nodes = await this . rs . local . getNodes ( [ "/foo/" , "/foo/one" , "/foo/two" ] ) ;
198+ const folder = nodes [ "/foo/" ] ;
199+
200+ expect ( folder . common ) . to . be . undefined ;
201+ expect ( Object . keys ( folder . local . itemsMap ) ) . to . deep . equal ( [ "two" ] ) ;
202+ expect ( nodes [ "/foo/one" ] ) . to . be . undefined ;
203+ expect ( nodes [ "/foo/two" ] . local . revision ) . to . equal ( "abcdef" ) ;
204+ } ) ;
205+ } ) ;
206+ } ) ;
207+
99208 describe ( "#_emitChangeEvents" , function ( ) {
100209 it ( "broadcasts the change to other browser tabs" , function ( done ) {
101210 this . rs . local . broadcastChannel = {
0 commit comments