@@ -881,7 +881,7 @@ describe('globals', function() {
881
881
} ;
882
882
883
883
send ( { foo : 'bar' } ) ;
884
- assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] , {
884
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
885
885
project : '2' ,
886
886
logger : 'javascript' ,
887
887
platform : 'javascript' ,
@@ -913,7 +913,7 @@ describe('globals', function() {
913
913
globalUser = { name : 'Matt' } ;
914
914
915
915
send ( { foo : 'bar' } ) ;
916
- assert . deepEqual ( window . makeRequest . lastCall . args , [ {
916
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
917
917
project : '2' ,
918
918
logger : 'javascript' ,
919
919
platform : 'javascript' ,
@@ -929,7 +929,7 @@ describe('globals', function() {
929
929
} ,
930
930
foo : 'bar' ,
931
931
extra : { 'session:duration' : 100 }
932
- } ] ) ;
932
+ } ) ;
933
933
} ) ;
934
934
935
935
it ( 'should merge in global tags' , function ( ) {
@@ -948,7 +948,7 @@ describe('globals', function() {
948
948
949
949
950
950
send ( { tags : { tag2 : 'value2' } } ) ;
951
- assert . deepEqual ( window . makeRequest . lastCall . args , [ {
951
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
952
952
project : '2' ,
953
953
logger : 'javascript' ,
954
954
platform : 'javascript' ,
@@ -961,7 +961,7 @@ describe('globals', function() {
961
961
event_id : 'abc123' ,
962
962
tags : { tag1 : 'value1' , tag2 : 'value2' } ,
963
963
extra : { 'session:duration' : 100 }
964
- } ] ) ;
964
+ } ) ;
965
965
assert . deepEqual ( globalOptions , {
966
966
logger : 'javascript' ,
967
967
tags : { tag1 : 'value1' }
@@ -984,7 +984,7 @@ describe('globals', function() {
984
984
985
985
986
986
send ( { extra : { key2 : 'value2' } } ) ;
987
- assert . deepEqual ( window . makeRequest . lastCall . args , [ {
987
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
988
988
project : '2' ,
989
989
logger : 'javascript' ,
990
990
platform : 'javascript' ,
@@ -996,7 +996,7 @@ describe('globals', function() {
996
996
} ,
997
997
event_id : 'abc123' ,
998
998
extra : { key1 : 'value1' , key2 : 'value2' , 'session:duration' : 100 }
999
- } ] ) ;
999
+ } ) ;
1000
1000
assert . deepEqual ( globalOptions , {
1001
1001
logger : 'javascript' ,
1002
1002
extra : { key1 : 'value1' }
@@ -1018,10 +1018,10 @@ describe('globals', function() {
1018
1018
globalUser = { name : 'Matt' } ;
1019
1019
1020
1020
send ( { foo : 'bar' } ) ;
1021
- assert . deepEqual ( window . makeRequest . lastCall . args , [ {
1021
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
1022
1022
lol : 'ibrokeit' ,
1023
1023
event_id : 'abc123' ,
1024
- } ] ) ;
1024
+ } ) ;
1025
1025
} ) ;
1026
1026
1027
1027
it ( 'should ignore dataCallback if it does not return anything' , function ( ) {
@@ -1041,7 +1041,7 @@ describe('globals', function() {
1041
1041
} ;
1042
1042
1043
1043
send ( { foo : 'bar' } ) ;
1044
- assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] , {
1044
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
1045
1045
project : '2' ,
1046
1046
logger : 'javascript' ,
1047
1047
platform : 'javascript' ,
@@ -1072,7 +1072,7 @@ describe('globals', function() {
1072
1072
} ;
1073
1073
1074
1074
send ( { foo : 'bar' , tags : { } , extra : { } } ) ;
1075
- assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] , {
1075
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
1076
1076
project : '2' ,
1077
1077
logger : 'javascript' ,
1078
1078
platform : 'javascript' ,
@@ -1103,7 +1103,7 @@ describe('globals', function() {
1103
1103
} ;
1104
1104
1105
1105
send ( { foo : 'bar' } ) ;
1106
- assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] , {
1106
+ assert . deepEqual ( window . makeRequest . lastCall . args [ 0 ] . data , {
1107
1107
project : '2' ,
1108
1108
release : 'abc123' ,
1109
1109
logger : 'javascript' ,
@@ -1119,40 +1119,86 @@ describe('globals', function() {
1119
1119
extra : { 'session:duration' : 100 }
1120
1120
} ) ;
1121
1121
} ) ;
1122
- } ) ;
1123
1122
1124
- describe ( 'makeRequest' , function ( ) {
1125
- var imageCache ;
1123
+ it ( 'should pass correct opts to makeRequest' , function ( ) {
1124
+ this . sinon . stub ( window , 'isSetup' ) . returns ( true ) ;
1125
+ this . sinon . stub ( window , 'makeRequest' ) ;
1126
+ this . sinon . stub ( window , 'getHttpData' ) . returns ( {
1127
+ url : 'http://localhost/?a=b' ,
1128
+ headers : { 'User-Agent' : 'lolbrowser' }
1129
+ } ) ;
1126
1130
1127
- beforeEach ( function ( ) {
1128
- imageCache = [ ] ;
1129
- this . sinon . stub ( window , 'newImage' , function ( ) { var img = { } ; imageCache . push ( img ) ; return img ; } ) ;
1130
- } )
1131
+ globalServer = 'http://localhost/store/' ;
1132
+ authQueryString = '?lol'
1133
+
1134
+ globalOptions = {
1135
+ projectId : 2 ,
1136
+ logger : 'javascript' ,
1137
+ release : 'abc123' ,
1138
+ } ;
1139
+
1140
+ send ( { foo : 'bar' } ) ;
1141
+ var args = window . makeRequest . lastCall . args ;
1142
+ assert . equal ( args . length , 1 ) ;
1143
+ var opts = args [ 0 ] ;
1144
+ assert . equal ( opts . url , 'http://localhost/store/?lol' ) ;
1145
+ assert . deepEqual ( opts . data , {
1146
+ project : '2' ,
1147
+ release : 'abc123' ,
1148
+ logger : 'javascript' ,
1149
+ platform : 'javascript' ,
1150
+ request : {
1151
+ url : 'http://localhost/?a=b' ,
1152
+ headers : {
1153
+ 'User-Agent' : 'lolbrowser'
1154
+ }
1155
+ } ,
1156
+ event_id : 'abc123' ,
1157
+ foo : 'bar' ,
1158
+ extra : { 'session:duration' : 100 } ,
1159
+ } ) ;
1160
+ assert . deepEqual ( opts . options , globalOptions ) ;
1161
+ assert . isFunction ( opts . onSuccess ) ;
1162
+ assert . isFunction ( opts . onError ) ;
1163
+ } ) ;
1131
1164
1132
1165
it ( 'should check `isSetup`' , function ( ) {
1133
1166
this . sinon . stub ( window , 'isSetup' ) . returns ( false ) ;
1134
- makeRequest ( { foo : 'bar' } ) ;
1167
+ this . sinon . stub ( window , 'makeRequest' ) ;
1168
+ send ( { foo : 'bar' } ) ;
1135
1169
assert . isTrue ( window . isSetup . called ) ;
1136
1170
} ) ;
1137
1171
1138
- it ( 'should not create the image if `isSetup` is false' , function ( ) {
1172
+ it ( 'should not makeRequest if `isSetup` is false' , function ( ) {
1139
1173
this . sinon . stub ( window , 'isSetup' ) . returns ( false ) ;
1140
- makeRequest ( { foo : 'bar' } ) ;
1141
- assert . isFalse ( window . newImage . called ) ;
1174
+ this . sinon . stub ( window , 'makeRequest' ) ;
1175
+ send ( { foo : 'bar' } ) ;
1176
+ assert . isFalse ( window . makeRequest . called ) ;
1142
1177
} ) ;
1143
1178
1144
1179
it ( 'should log to console' , function ( ) {
1145
1180
this . sinon . stub ( window , 'isSetup' ) . returns ( true ) ;
1146
1181
this . sinon . stub ( window , 'logDebug' ) ;
1147
- makeRequest ( { foo : 'bar' } ) ;
1182
+ this . sinon . stub ( window , 'makeRequest' ) ;
1183
+ send ( { foo : 'bar' } ) ;
1148
1184
assert . isTrue ( window . logDebug . called ) ;
1149
1185
} ) ;
1186
+ } ) ;
1150
1187
1151
- it ( 'should load an Image' , function ( ) {
1152
- authQueryString = '?lol' ;
1153
- globalServer = 'http://localhost/' ;
1188
+ describe ( 'makeRequest' , function ( ) {
1189
+ var imageCache ;
1154
1190
1155
- makeRequest ( { foo : 'bar' } ) ;
1191
+ beforeEach ( function ( ) {
1192
+ imageCache = [ ] ;
1193
+ this . sinon . stub ( window , 'newImage' , function ( ) { var img = { } ; imageCache . push ( img ) ; return img ; } ) ;
1194
+ } )
1195
+
1196
+ it ( 'should load an Image' , function ( ) {
1197
+ makeRequest ( {
1198
+ url : 'http://localhost/?lol' ,
1199
+ data : { foo : 'bar' } ,
1200
+ options : globalOptions
1201
+ } ) ;
1156
1202
assert . equal ( imageCache . length , 1 ) ;
1157
1203
assert . equal ( imageCache [ 0 ] . src , 'http://localhost/?lol&sentry_data=%7B%22foo%22%3A%22bar%22%7D' ) ;
1158
1204
} ) ;
@@ -1161,7 +1207,11 @@ describe('globals', function() {
1161
1207
globalOptions = {
1162
1208
crossOrigin : 'something'
1163
1209
} ;
1164
- makeRequest ( { foo : 'bar' } ) ;
1210
+ makeRequest ( {
1211
+ url : globalServer ,
1212
+ data : { foo : 'bar' } ,
1213
+ options : globalOptions
1214
+ } ) ;
1165
1215
assert . equal ( imageCache . length , 1 ) ;
1166
1216
assert . equal ( imageCache [ 0 ] . crossOrigin , 'something' ) ;
1167
1217
} ) ;
@@ -1170,7 +1220,11 @@ describe('globals', function() {
1170
1220
globalOptions = {
1171
1221
crossOrigin : ''
1172
1222
} ;
1173
- makeRequest ( { foo : 'bar' } ) ;
1223
+ makeRequest ( {
1224
+ url : globalServer ,
1225
+ data : { foo : 'bar' } ,
1226
+ options : globalOptions
1227
+ } ) ;
1174
1228
assert . equal ( imageCache . length , 1 ) ;
1175
1229
assert . equal ( imageCache [ 0 ] . crossOrigin , '' ) ;
1176
1230
} ) ;
@@ -1179,7 +1233,11 @@ describe('globals', function() {
1179
1233
globalOptions = {
1180
1234
crossOrigin : false
1181
1235
} ;
1182
- makeRequest ( { foo : 'bar' } ) ;
1236
+ makeRequest ( {
1237
+ url : globalServer ,
1238
+ data : { foo : 'bar' } ,
1239
+ options : globalOptions
1240
+ } ) ;
1183
1241
assert . equal ( imageCache . length , 1 ) ;
1184
1242
assert . isUndefined ( imageCache [ 0 ] . crossOrigin ) ;
1185
1243
} ) ;
0 commit comments