File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed
packages/compass-crud/src/stores Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -1042,6 +1042,34 @@ describe('store', function () {
1042
1042
await listener ;
1043
1043
} ) ;
1044
1044
} ) ;
1045
+
1046
+ context ( 'when the document has invalid bson' , function ( ) {
1047
+ // this is invalid ObjectId
1048
+ const jsonDoc = '{"_id": {"$oid": ""}}' ;
1049
+
1050
+ beforeEach ( function ( ) {
1051
+ store . state . insert . jsonView = true ;
1052
+ store . state . insert . doc = { } ;
1053
+ store . state . insert . jsonDoc = jsonDoc ;
1054
+ } ) ;
1055
+
1056
+ it ( 'does not insert the document and sets the error' , async function ( ) {
1057
+ const listener = waitForState ( store , ( state ) => {
1058
+ expect ( state . docs . length ) . to . equal ( 0 ) ;
1059
+ expect ( state . count ) . to . equal ( 0 ) ;
1060
+ expect ( state . insert . doc ) . to . deep . equal ( { } ) ;
1061
+ expect ( state . insert . jsonDoc ) . to . equal ( jsonDoc ) ;
1062
+ expect ( state . insert . isOpen ) . to . equal ( true ) ;
1063
+ expect ( state . insert . jsonView ) . to . equal ( true ) ;
1064
+ expect ( state . insert . message ) . to . not . equal ( '' ) ;
1065
+ expect ( state . insert . mode ) . to . equal ( 'error' ) ;
1066
+ } ) ;
1067
+
1068
+ store . insertDocument ( ) ;
1069
+
1070
+ await listener ;
1071
+ } ) ;
1072
+ } ) ;
1045
1073
} ) ;
1046
1074
1047
1075
context ( 'when there is an error' , function ( ) {
Original file line number Diff line number Diff line change @@ -1201,14 +1201,14 @@ class CrudStoreImpl
1201
1201
1202
1202
let doc : BSONObject ;
1203
1203
1204
- if ( this . state . insert . jsonView ) {
1205
- doc = HadronDocument . FromEJSON (
1206
- this . state . insert . jsonDoc ?? ''
1207
- ) . generateObject ( ) ;
1208
- } else {
1209
- doc = this . state . insert . doc ! . generateObject ( ) ;
1210
- }
1211
1204
try {
1205
+ if ( this . state . insert . jsonView ) {
1206
+ doc = HadronDocument . FromEJSON (
1207
+ this . state . insert . jsonDoc ?? ''
1208
+ ) . generateObject ( ) ;
1209
+ } else {
1210
+ doc = this . state . insert . doc ! . generateObject ( ) ;
1211
+ }
1212
1212
await this . dataService . insertOne ( this . state . ns , doc ) ;
1213
1213
1214
1214
const payload = {
You can’t perform that action at this time.
0 commit comments