@@ -3,7 +3,7 @@ import { Create } from "../../src/providers/commands";
3
3
4
4
describe ( "ApiCreate" , ( ) => {
5
5
test ( "FireClient create doc" , async ( ) => {
6
- const client = MakeMockClient ( {
6
+ const client = await MakeMockClient ( {
7
7
logging : true ,
8
8
disableMeta : true ,
9
9
} ) ;
@@ -15,7 +15,7 @@ describe("ApiCreate", () => {
15
15
expect ( first . name ) . toBe ( "John" ) ;
16
16
} , 100000 ) ;
17
17
test ( "FireClient create doc with custom meta" , async ( ) => {
18
- const client = MakeMockClient ( {
18
+ const client = await MakeMockClient ( {
19
19
logging : true ,
20
20
renameMetaFields : {
21
21
updated_by : 'MY_CREATED_BY' ,
@@ -28,4 +28,40 @@ describe("ApiCreate", () => {
28
28
29
29
expect ( first . hasOwnProperty ( 'MY_CREATED_BY' ) ) . toBeTruthy ( ) ;
30
30
} , 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 ) ;
31
67
} ) ;
0 commit comments