File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,6 +48,29 @@ describe('Users Requests', () => {
4848 expect ( response . data . msg ) . toBe ( 'hello' ) ;
4949 } ) ;
5050
51+ it ( 'should respect a caller-provided preferUserId of false for updateCart' , async ( ) => {
52+ mockRequest . onPost ( '/commerce/updateCart' ) . reply ( 200 , {
53+ msg : 'hello'
54+ } ) ;
55+
56+ const response = await updateCart ( {
57+ user : {
58+ preferUserId : false
59+ } ,
60+ items : [
61+ {
62+ id : 'fdsafds' ,
63+ name : 'banana' ,
64+ quantity : 2 ,
65+ price : 12
66+ }
67+ ]
68+ } ) ;
69+
70+ expect ( JSON . parse ( response . config . data ) . user . preferUserId ) . toBe ( false ) ;
71+ expect ( response . data . msg ) . toBe ( 'hello' ) ;
72+ } ) ;
73+
5174 it ( 'should reject updateCart on bad params' , async ( ) => {
5275 try {
5376 await updateCart ( {
@@ -93,6 +116,23 @@ describe('Users Requests', () => {
93116 expect ( response . data . msg ) . toBe ( 'hello' ) ;
94117 } ) ;
95118
119+ it ( 'should respect a caller-provided preferUserId of false for trackPurchase' , async ( ) => {
120+ mockRequest . onPost ( '/commerce/trackPurchase' ) . reply ( 200 , {
121+ msg : 'hello'
122+ } ) ;
123+
124+ const response = await trackPurchase ( {
125+ user : {
126+ preferUserId : false
127+ } ,
128+ items : [ ] ,
129+ total : 100
130+ } ) ;
131+
132+ expect ( JSON . parse ( response . config . data ) . user . preferUserId ) . toBe ( false ) ;
133+ expect ( response . data . msg ) . toBe ( 'hello' ) ;
134+ } ) ;
135+
96136 it ( 'should not allow a passed userId or email for API methods' , async ( ) => {
97137 mockRequest . onPost ( '/commerce/trackPurchase' ) . reply ( 200 , {
98138 msg : 'hello'
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ export const updateCart = (payload: UpdateCartRequestParams) => {
2626 ...payload ,
2727 user : {
2828 ...payload . user ,
29- preferUserId : true
29+ /* default to true, but allow the caller to override */
30+ preferUserId : payload . user ?. preferUserId ?? true
3031 }
3132 } ,
3233 validation : {
@@ -54,7 +55,8 @@ export const trackPurchase = (payload: TrackPurchaseRequestParams) => {
5455 ...payload ,
5556 user : {
5657 ...payload . user ,
57- preferUserId : true
58+ /* default to true, but allow the caller to override */
59+ preferUserId : payload . user ?. preferUserId ?? true
5860 }
5961 } ,
6062 validation : {
Original file line number Diff line number Diff line change @@ -504,7 +504,8 @@ export class UnknownUserEventManager {
504504 ...payload ,
505505 user : {
506506 ...payload . user ,
507- preferUserId : true
507+ /* default to true, but allow the caller to override */
508+ preferUserId : payload . user ?. preferUserId ?? true
508509 }
509510 } ,
510511 validation : {
@@ -520,7 +521,8 @@ export class UnknownUserEventManager {
520521 ...payload ,
521522 user : {
522523 ...payload . user ,
523- preferUserId : true
524+ /* default to true, but allow the caller to override */
525+ preferUserId : payload . user ?. preferUserId ?? true
524526 }
525527 } ,
526528 validation : {
@@ -535,7 +537,8 @@ export class UnknownUserEventManager {
535537 url : ENDPOINTS . users_update . route ,
536538 data : {
537539 ...payload ,
538- preferUserId : true
540+ /* default to true, but allow the caller to override */
541+ preferUserId : payload . preferUserId ?? true
539542 } ,
540543 validation : {
541544 data : updateUserSchema
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export interface GetUserResponse {
1212
1313export interface UpdateUserParams {
1414 dataFields ?: Record < string , any > ;
15+ preferUserId ?: boolean ;
1516 mergeNestedObjects ?: boolean ;
1617}
1718
Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ describe('Users Requests', () => {
3636 expect ( response && response . data . msg ) . toBe ( 'hello' ) ;
3737 } ) ;
3838
39+ it ( 'should respect a caller-provided preferUserId of false for updateUser' , async ( ) => {
40+ mockRequest . onPost ( '/users/update' ) . reply ( 200 , {
41+ msg : 'hello'
42+ } ) ;
43+
44+ const response = await updateUser ( {
45+ dataFields : { } ,
46+ preferUserId : false
47+ } ) ;
48+
49+ expect ( JSON . parse ( response && response . config . data ) . preferUserId ) . toBe (
50+ false
51+ ) ;
52+ expect ( response && response . data . msg ) . toBe ( 'hello' ) ;
53+ } ) ;
54+
3955 it ( 'should reject updateUser on bad params' , async ( ) => {
4056 try {
4157 await updateUser ( {
@@ -52,6 +68,11 @@ describe('Users Requests', () => {
5268 ' If "null" is intended as an empty value be sure to mark the schema as `.nullable()`' ,
5369 field : 'dataFields'
5470 } ,
71+ {
72+ error :
73+ 'preferUserId must be a `boolean` type, but the final value was: `"string"`.' ,
74+ field : 'preferUserId'
75+ } ,
5576 {
5677 error :
5778 'mergeNestedObjects must be a `boolean` type, but the final value was: `"string"`.' ,
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ export const updateUser = (payloadParam: UpdateUserParams = {}) => {
3838 url : ENDPOINTS . users_update . route ,
3939 data : {
4040 ...payload ,
41- preferUserId : true
41+ /* default to true, but allow the caller to override */
42+ preferUserId : payload . preferUserId ?? true
4243 } ,
4344 validation : {
4445 data : updateUserSchema
You can’t perform that action at this time.
0 commit comments