-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NODE-5274): deprecate write concern options
- Loading branch information
Showing
3 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { WriteConcern } from '../mongodb'; | ||
|
||
describe('WriteConcern', function () { | ||
describe('#constructor', function () { | ||
context('when w is provided', function () { | ||
const writeConcern = new WriteConcern(1); | ||
|
||
it('sets the w property', function () { | ||
expect(writeConcern.w).to.equal(1); | ||
}); | ||
}); | ||
|
||
context('when wtimeoutMS is provided', function () { | ||
const writeConcern = new WriteConcern(1, 50); | ||
|
||
it('sets the wtimeoutMS property', function () { | ||
expect(writeConcern.wtimeoutMS).to.equal(50); | ||
}); | ||
|
||
it('sets the wtimeout property', function () { | ||
expect(writeConcern.wtimeout).to.equal(50); | ||
}); | ||
}); | ||
|
||
context('when journal is provided', function () { | ||
const writeConcern = new WriteConcern(1, 50, true); | ||
|
||
it('sets the journal property', function () { | ||
expect(writeConcern.journal).to.be.true; | ||
}); | ||
|
||
it('sets the j property', function () { | ||
expect(writeConcern.j).to.be.true; | ||
}); | ||
}); | ||
|
||
context('when fsync is provided', function () { | ||
const writeConcern = new WriteConcern(1, 50, false, true); | ||
|
||
it('sets the journal property', function () { | ||
expect(writeConcern.journal).to.be.true; | ||
}); | ||
|
||
it('sets the j property', function () { | ||
expect(writeConcern.j).to.be.true; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.apply', function () { | ||
context('when no options are set', function () { | ||
const document = {}; | ||
const writeConcern = new WriteConcern(); | ||
|
||
it('returns an empty write concern', function () { | ||
expect(WriteConcern.apply(document, writeConcern)).to.deep.equal({ writeConcern: {} }); | ||
}); | ||
}); | ||
|
||
context('when w is in the write concern', function () { | ||
const document = {}; | ||
const writeConcern = new WriteConcern(2); | ||
|
||
it('adds w to the write concern document', function () { | ||
expect(WriteConcern.apply(document, writeConcern)).to.deep.equal({ | ||
writeConcern: { w: 2 } | ||
}); | ||
}); | ||
}); | ||
|
||
context('when wtimeoutMS is in the write concern', function () { | ||
const document = {}; | ||
const writeConcern = new WriteConcern(2, 30); | ||
|
||
it('adds wtimeout to the write concern document', function () { | ||
expect(WriteConcern.apply(document, writeConcern)).to.deep.equal({ | ||
writeConcern: { w: 2, wtimeout: 30 } | ||
}); | ||
}); | ||
}); | ||
|
||
context('when journal is in the write concern', function () { | ||
const document = {}; | ||
const writeConcern = new WriteConcern(2, 30, true); | ||
|
||
it('adds j to the write concern document', function () { | ||
expect(WriteConcern.apply(document, writeConcern)).to.deep.equal({ | ||
writeConcern: { w: 2, wtimeout: 30, j: true } | ||
}); | ||
}); | ||
}); | ||
|
||
context('when fsync is in the write concern', function () { | ||
const document = {}; | ||
const writeConcern = new WriteConcern(2, 30, true, false); | ||
|
||
it('overrites j to the write concern document', function () { | ||
expect(WriteConcern.apply(document, writeConcern)).to.deep.equal({ | ||
writeConcern: { w: 2, wtimeout: 30, j: false } | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |