|
1 | 1 | import { ConnectionOptions, AuthenticationMechanism } from '@/index'; |
2 | | -import { getMongoConnectionFromOptions } from '@/utils/connection'; |
| 2 | +import { getMongoConnectionFromOptions, adjustOptionsForSrv } from '@/utils/connection'; |
3 | 3 |
|
4 | 4 | import { expect } from 'chai'; |
5 | 5 |
|
@@ -170,4 +170,47 @@ export default function (): void { |
170 | 170 | expect(result.options).to.deep.equal(expectedOptions); |
171 | 171 | }); |
172 | 172 | }); |
| 173 | + |
| 174 | + describe('Test: adjustOptionsForSrv auxiliary function', function () { |
| 175 | + it(`Should add the uri and remove some elements because of srv`, async function () { |
| 176 | + const options: ConnectionOptions = { |
| 177 | + srv: true, |
| 178 | + host: 'chien.hao.mongodb.net', |
| 179 | + port: 27_017, |
| 180 | + username: 'gabibbo', |
| 181 | + password: 'alteutting' |
| 182 | + }; |
| 183 | + |
| 184 | + const expected: ConnectionOptions = { |
| 185 | + srv: true, |
| 186 | + uri: 'mongodb+srv://gabibbo:alteutting@chien.hao.mongodb.net', |
| 187 | + host: undefined, |
| 188 | + port: undefined, |
| 189 | + username: undefined, |
| 190 | + password: undefined |
| 191 | + }; |
| 192 | + const result = await adjustOptionsForSrv(options); |
| 193 | + expect(result).to.deep.equal(expected); |
| 194 | + }); |
| 195 | + |
| 196 | + it(`Should do nothing because of no srv`, async function () { |
| 197 | + const options: ConnectionOptions = { |
| 198 | + srv: false, |
| 199 | + host: 'chien.hao.mongodb.net', |
| 200 | + port: 27_017, |
| 201 | + username: 'gabibbo', |
| 202 | + password: 'alteutting' |
| 203 | + }; |
| 204 | + |
| 205 | + const expected: ConnectionOptions = { |
| 206 | + srv: false, |
| 207 | + host: 'chien.hao.mongodb.net', |
| 208 | + port: 27_017, |
| 209 | + username: 'gabibbo', |
| 210 | + password: 'alteutting' |
| 211 | + }; |
| 212 | + const result = await adjustOptionsForSrv(options); |
| 213 | + expect(result).to.deep.equal(expected); |
| 214 | + }); |
| 215 | + }); |
173 | 216 | } |
0 commit comments