@@ -3,7 +3,7 @@ import { Create } from "../../src/providers/commands";
33
44describe ( "ApiCreate" , ( ) => {
55 test ( "FireClient create doc" , async ( ) => {
6- const client = MakeMockClient ( {
6+ const client = await MakeMockClient ( {
77 logging : true ,
88 disableMeta : true ,
99 } ) ;
@@ -15,7 +15,7 @@ describe("ApiCreate", () => {
1515 expect ( first . name ) . toBe ( "John" ) ;
1616 } , 100000 ) ;
1717 test ( "FireClient create doc with custom meta" , async ( ) => {
18- const client = MakeMockClient ( {
18+ const client = await MakeMockClient ( {
1919 logging : true ,
2020 renameMetaFields : {
2121 updated_by : 'MY_CREATED_BY' ,
@@ -28,4 +28,40 @@ describe("ApiCreate", () => {
2828
2929 expect ( first . hasOwnProperty ( 'MY_CREATED_BY' ) ) . toBeTruthy ( ) ;
3030 } , 100000 ) ;
31+ test ( "FireClient create doc with transformToDb function provided" , async ( ) => {
32+ const client = await MakeMockClient ( {
33+ logging : true ,
34+ transformToDb : ( resourceName , document , id ) => {
35+ if ( resourceName === "users" ) {
36+ return {
37+ ...document ,
38+ firstName : document . firstName . toUpperCase ( ) ,
39+ picture : document . picture . src || document . picture ,
40+ } ;
41+ }
42+ return document ;
43+ }
44+ } ) ;
45+
46+ const newUser = {
47+ firstName : "John" ,
48+ lastName : "Last" ,
49+ age : 20 ,
50+ picture : {
51+ src : "http://example.com/pic.png"
52+ } ,
53+ } ;
54+
55+ await Create ( "users" , { data : newUser } , client ) ;
56+ const users = ( await client . fireWrapper . dbGetCollection ( "users" ) . get ( ) ) . docs ;
57+
58+ expect ( users . length ) . toBe ( 1 ) ;
59+ expect ( users [ 0 ] . data ( ) ) . toMatchObject ( {
60+ firstName : "JOHN" ,
61+ lastName : "Last" ,
62+ age : 20 ,
63+ picture : "http://example.com/pic.png" ,
64+ } ) ;
65+
66+ } , 100000 ) ;
3167} ) ;
0 commit comments