|
3 | 3 | const expect = require('chai').expect;
|
4 | 4 | const loadSpecTests = require('../spec/index').loadSpecTests;
|
5 | 5 | const runUnifiedTest = require('./unified-spec-runner/runner').runUnifiedTest;
|
| 6 | +const ServerApiVersion = require('../../lib/core').ServerApiVersion; |
6 | 7 |
|
7 | 8 | describe('Versioned API', function() {
|
8 |
| - it('should throw an error if serverApi version is provided via the uri with new parser', { |
9 |
| - metadata: { topology: 'single' }, |
10 |
| - test: function(done) { |
| 9 | + describe('client option validation', function() { |
| 10 | + it('is supported as a client option when it is a valid ServerApiVersion string', function() { |
| 11 | + const validVersions = Object.values(ServerApiVersion); |
| 12 | + expect(validVersions.length).to.be.at.least(1); |
| 13 | + for (const version of validVersions) { |
| 14 | + const client = this.configuration.newClient('mongodb://localhost/', { |
| 15 | + serverApi: version |
| 16 | + }); |
| 17 | + expect(client.s.options) |
| 18 | + .to.have.property('serverApi') |
| 19 | + .deep.equal({ version }); |
| 20 | + } |
| 21 | + }); |
| 22 | + |
| 23 | + it('is supported as a client option when it is an object with a valid version property', function() { |
| 24 | + const validVersions = Object.values(ServerApiVersion); |
| 25 | + expect(validVersions.length).to.be.at.least(1); |
| 26 | + for (const version of validVersions) { |
| 27 | + const client = this.configuration.newClient('mongodb://localhost/', { |
| 28 | + serverApi: { version } |
| 29 | + }); |
| 30 | + expect(client.s.options) |
| 31 | + .to.have.property('serverApi') |
| 32 | + .deep.equal({ version }); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + it('is not supported as a client option when it is an invalid string', function() { |
| 37 | + expect(() => |
| 38 | + this.configuration.newClient('mongodb://localhost/', { |
| 39 | + serverApi: 'bad' |
| 40 | + }) |
| 41 | + ).to.throw(/^Invalid server API version=bad;/); |
| 42 | + }); |
| 43 | + |
| 44 | + it('is not supported as a client option when it is a number', function() { |
| 45 | + expect(() => |
| 46 | + this.configuration.newClient('mongodb://localhost/', { |
| 47 | + serverApi: 1 |
| 48 | + }) |
| 49 | + ).to.throw(/^Invalid `serverApi` property;/); |
| 50 | + }); |
| 51 | + |
| 52 | + it('is not supported as a client option when it is an object without a specified version', function() { |
| 53 | + expect(() => |
| 54 | + this.configuration.newClient('mongodb://localhost/', { |
| 55 | + serverApi: {} |
| 56 | + }) |
| 57 | + ).to.throw(/^Invalid `serverApi` property;/); |
| 58 | + }); |
| 59 | + |
| 60 | + it('is not supported as a client option when it is an object with an invalid specified version', function() { |
| 61 | + expect(() => |
| 62 | + this.configuration.newClient('mongodb://localhost/', { |
| 63 | + serverApi: { version: 1 } |
| 64 | + }) |
| 65 | + ).to.throw(/^Invalid server API version=1;/); |
| 66 | + expect(() => |
| 67 | + this.configuration.newClient('mongodb://localhost/', { |
| 68 | + serverApi: { version: 'bad' } |
| 69 | + }) |
| 70 | + ).to.throw(/^Invalid server API version=bad;/); |
| 71 | + }); |
| 72 | + |
| 73 | + it('is not supported as a URI option even when it is a valid ServerApiVersion string', function(done) { |
11 | 74 | const client = this.configuration.newClient({ serverApi: '1' }, { useNewUrlParser: true });
|
12 | 75 | client.connect(err => {
|
13 | 76 | expect(err).to.match(/URI cannot contain `serverApi`, it can only be passed to the client/);
|
14 | 77 | client.close(done);
|
15 | 78 | });
|
16 |
| - } |
| 79 | + }); |
17 | 80 | });
|
18 | 81 |
|
19 | 82 | for (const versionedApiTest of loadSpecTests('versioned-api')) {
|
|
0 commit comments