1
- import { DataValueFactory , Tracker , UserFactory } from '../../src' ;
1
+ import { error } from 'console' ;
2
+ import { DataValueFactory , ProblemDetailsError , Tracker , UserFactory } from '../../src' ;
2
3
import { test , expect } from '@jest/globals'
3
4
4
5
const { npm_config_API_KEY : API_KEY , npm_config_DATASET_ID : DATASET_ID , npm_config_SERVER_URL : SERVER_URL } = process . env ;
@@ -19,10 +20,10 @@ test('Track Order', async() => {
19
20
productId : '2' ,
20
21
quantity : 1 ,
21
22
variantId : 'v1' ,
22
- } ] ,
23
+ } ] ,
23
24
subtotal : {
24
25
amount : 100 ,
25
- currency : 'DKK' ,
26
+ currency : 'DKK' ,
26
27
} ,
27
28
orderNumber : '' ,
28
29
trackingNumber : '' ,
@@ -50,7 +51,7 @@ test('Track Cart', async() => {
50
51
] ,
51
52
subtotal : {
52
53
amount : 100 ,
53
- currency : 'DKK' ,
54
+ currency : 'DKK' ,
54
55
} ,
55
56
user : UserFactory . anonymous ( ) ,
56
57
data : { 'basketId' : DataValueFactory . string ( 'basketid' ) } ,
@@ -149,15 +150,49 @@ test('Track Search Term', async() => {
149
150
} ) ;
150
151
151
152
test ( 'Track User Update' , async ( ) => {
152
- const user = UserFactory . byTemporaryId ( 'tempId' , {
153
- email : 'integrationtests@relewise.com' ,
153
+ const user = UserFactory . byTemporaryId ( 'tempId' , {
154
+ email : 'integrationtests@relewise.com' ,
154
155
identifiers : {
155
156
'emailIntegrationId' : 'abc' ,
156
- } } ) ;
157
+ } ,
158
+ } ) ;
157
159
158
160
const result = await tracker . trackUserUpdate ( {
159
161
user : user ,
160
162
} ) ;
161
163
162
164
expect ( result ) . toBeUndefined ( ) ;
165
+ } ) ;
166
+
167
+ test ( 'Track Product View with invalid key' , async ( ) => {
168
+
169
+ await new Tracker ( DATASET_ID ! , '12' ) . trackProductView ( {
170
+ productId : '2' ,
171
+ user : UserFactory . anonymous ( ) ,
172
+ } ) . catch ( ( e ) => {
173
+ expect ( e ) . toBeDefined ( ) ;
174
+ expect ( ( e as ProblemDetailsError ) . details ?. title ) . toEqual ( 'Unauthorized' ) ;
175
+ expect ( e . message ) . toEqual ( 'Error when calling the Relewise API. Read more in the details property if there is error response or look in the network tab.' )
176
+ } ) ;
177
+ } ) ;
178
+
179
+ test ( 'Track Product View without id' , async ( ) => {
180
+ await expect ( async ( ) => {
181
+ return await tracker . trackProductView ( {
182
+ productId : null ,
183
+ user : UserFactory . anonymous ( ) ,
184
+ } as any )
185
+ } ) . rejects . toThrow ( ) ;
186
+ } ) ;
187
+
188
+ test ( 'Track Product View without id' , async ( ) => {
189
+ try {
190
+ await tracker . trackProductView ( {
191
+ productId : null ,
192
+ user : UserFactory . anonymous ( ) ,
193
+ } as any ) ;
194
+ }
195
+ catch ( e ) {
196
+ expect ( e ) . toBeDefined ( ) ;
197
+ }
163
198
} ) ;
0 commit comments