Skip to content

Commit 745bf66

Browse files
author
Grace Chong
committed
refactor: fix misspelled key and add default validation setting and test, remove .only
1 parent 4591622 commit 745bf66

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/cmap/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ export class BinMsg {
838838
const promoteValues = options.promoteValues ?? this.opts.promoteValues;
839839
const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
840840
const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
841-
const validation = options.validation ?? { utf8: { writeError: false } };
841+
const validation = options.validation ?? { utf8: { writeErrors: false } };
842842

843843
// Set up the options
844844
const _options: BSONSerializeOptions = {

test/unit/commands.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,23 @@ const invalidUtf8InOtherKeyJSON = {
7070
ok: 1
7171
};
7272

73-
describe.only('BinMsg', function () {
73+
describe('BinMsg', function () {
7474
it('should not throw invalid utf8 error when validation disabled for writeErrors', function () {
75-
const binMsgValidWriteError = new BinMsg(
75+
const binMsgInvalidUtf8ErrorMsg = new BinMsg(
7676
Buffer.alloc(0),
7777
msgHeader,
78-
msgBodyInvalidUtf8WriteErrors,
79-
{
80-
validation: { utf8: { writeErrors: false } }
81-
}
78+
msgBodyInvalidUtf8WriteErrors
8279
);
8380
expect(() =>
84-
binMsgValidWriteError.parse({ validation: { utf8: { writeErrors: false } } })
81+
binMsgInvalidUtf8ErrorMsg.parse({ validation: { utf8: { writeErrors: false } } })
8582
).to.not.throw();
8683
expect(
8784
BSON.deserialize(badutf8inputtodeserialize, { validation: { utf8: { writeErrors: false } } })
8885
).to.deep.equals(invalidUtf8InWriteErrorsJSON);
8986
});
9087

91-
it('should throw invalid utf8 error when validation not specified or enabled for writeErrors', function () {
92-
const binMsgValidWriteError = new BinMsg(
88+
it('should by default disable validation for writeErrors if no validation specified', function () {
89+
const binMsgInvalidUtf8ErrorMsg = new BinMsg(
9390
Buffer.alloc(0),
9491
msgHeader,
9592
msgBodyInvalidUtf8WriteErrors
@@ -100,12 +97,17 @@ describe.only('BinMsg', function () {
10097
promoteLongs: true,
10198
promoteValues: true
10299
};
103-
expect(() => binMsgValidWriteError.parse(options)).to.throw(
104-
BSONError,
105-
'Invalid UTF-8 string in BSON document'
100+
expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw();
101+
});
102+
103+
it('should throw invalid utf8 error when validation enabled for writeErrors', function () {
104+
const binMsgInvalidUtf8ErrorMsg = new BinMsg(
105+
Buffer.alloc(0),
106+
msgHeader,
107+
msgBodyInvalidUtf8WriteErrors
106108
);
107109
expect(() =>
108-
binMsgValidWriteError.parse({ validation: { utf8: { writeErrors: true } } })
110+
binMsgInvalidUtf8ErrorMsg.parse({ validation: { utf8: { writeErrors: true } } })
109111
).to.throw(BSONError, 'Invalid UTF-8 string in BSON document');
110112
});
111113

0 commit comments

Comments
 (0)