@@ -4,6 +4,8 @@ import * as cbl from "@couchbase/lite-js";
44import { beforeEach , test , describe , expect , afterEach } from "vitest" ;
55
66
7+ /* eslint-disable @typescript-eslint/require-await */
8+
79cbl . Database . useIndexedDB ( indexedDB , IDBKeyRange ) ;
810
911
@@ -24,6 +26,11 @@ afterEach( async() => {
2426} ) ;
2527
2628
29+ async function noBlobLoader ( _url : string ) : Promise < cbl . NewBlob > {
30+ throw Error ( "Should not be called" ) ;
31+ }
32+
33+
2734describe ( "Snapshot" , ( ) => {
2835
2936 test ( "doc wasn't created" , async ( ) => {
@@ -34,7 +41,7 @@ describe("Snapshot", () => {
3441 type : 'UPDATE' ,
3542 collection : "red" ,
3643 documentID : cbl . DocID ( "nose" ) ,
37- } ] ) ;
44+ } ] , noBlobLoader ) ;
3845 expect ( response ) . toMatchInlineSnapshot ( `
3946 {
4047 "description": "Document nose in collection red was not found",
@@ -62,7 +69,7 @@ describe("Snapshot", () => {
6269 name : "Santa" ,
6370 reindeer : [ "Dasher" , "Prancer" , "etc." ] ,
6471 } ] ,
65- } ] ) ;
72+ } ] , noBlobLoader ) ;
6673 expect ( response ) . toEqual ( { result : true } ) ;
6774 } ) ;
6875
@@ -83,7 +90,7 @@ describe("Snapshot", () => {
8390 collection : "red" ,
8491 documentID : cbl . DocID ( "nose" ) ,
8592 type : 'DELETE' ,
86- } ] ) ;
93+ } ] , noBlobLoader ) ;
8794 expect ( response ) . toEqual ( { result : true } ) ;
8895 } ) ;
8996
@@ -102,7 +109,7 @@ describe("Snapshot", () => {
102109 collection : "red" ,
103110 documentID : cbl . DocID ( "nose" ) ,
104111 type : 'DELETE' ,
105- } ] ) ;
112+ } ] , noBlobLoader ) ;
106113 expect ( response ) . toEqual ( {
107114 "result" : false ,
108115 "description" : "Document nose in collection red was not deleted" ,
@@ -135,7 +142,7 @@ describe("Snapshot", () => {
135142 name : "Santa" ,
136143 reindeer : [ "Dasher" , "Prancer" , "etc." ] ,
137144 } ] ,
138- } ] ) ;
145+ } ] , noBlobLoader ) ;
139146
140147 expect ( response ) . toEqual ( {
141148 "result" : false ,
@@ -165,6 +172,7 @@ describe("Snapshot", () => {
165172 await snapshot . record ( "red" , cbl . DocID ( "nose" ) ) ;
166173
167174 ( nose . reindeer as string [ ] ) [ 2 ] = "Rudolph" ;
175+ await red . save ( nose ) ;
168176
169177 const response = await snapshot . verify ( [ {
170178 collection : "red" ,
@@ -173,22 +181,41 @@ describe("Snapshot", () => {
173181 updatedProperties : [ {
174182 "reindeer[2]" : "Rudolph" ,
175183 } ] ,
176- } ] ) ;
184+ } ] , noBlobLoader ) ;
177185
178- expect ( response ) . toEqual ( {
179- "result" : false ,
180- "description" : "Document nose in collection red had unexpected properties at .reindeer[2]" ,
181- "expected" : "Rudolph" ,
182- "actual" : "etc." ,
183- "document" : {
184- "name" : "Santa" ,
185- "reindeer" : [
186- "Dasher" ,
187- "Prancer" ,
188- "etc." ,
189- ] ,
190- } ,
186+ expect ( response ) . toEqual ( { "result" : true } ) ;
187+ } ) ;
188+
189+
190+ test ( "doc added a blob" , async ( ) => {
191+ const nose = red . createDocument ( cbl . DocID ( "nose" ) , {
192+ name : "Santa" ,
193+ reindeer : [ "Dasher" , "Prancer" , "etc." ] ,
191194 } ) ;
195+ await red . save ( nose ) ;
196+
197+ const snapshot = new Snapshot ( db ) ;
198+ await snapshot . record ( "red" , cbl . DocID ( "nose" ) ) ;
199+
200+ const hohoho = new TextEncoder ( ) . encode ( "Ho ho ho!" ) ;
201+ nose . hohoho = new cbl . NewBlob ( hohoho , "text/plain" ) ;
202+ await red . save ( nose ) ;
203+
204+ const blobLoader = async ( url : string ) : Promise < cbl . NewBlob > => {
205+ expect ( url ) . toBe ( "x/y/hohoho.txt" ) ;
206+ return new cbl . NewBlob ( hohoho , "text/plain" ) ;
207+ } ;
208+
209+ const response = await snapshot . verify ( [ {
210+ collection : "red" ,
211+ documentID : cbl . DocID ( "nose" ) ,
212+ type : 'UPDATE' ,
213+ updatedBlobs : {
214+ "hohoho" : "x/y/hohoho.txt" ,
215+ } ,
216+ } ] , blobLoader ) ;
217+
218+ expect ( response ) . toEqual ( { "result" : true } ) ;
192219 } ) ;
193220
194221
@@ -210,7 +237,7 @@ describe("Snapshot", () => {
210237 updatedProperties : [ {
211238 "reindeer[2]" : "Rudolph" ,
212239 } ] ,
213- } ] ) ;
240+ } ] , noBlobLoader ) ;
214241
215242 expect ( response ) . toEqual ( {
216243 "result" : false ,
0 commit comments