Skip to content

Commit df28fee

Browse files
test: fix test getCommand srv and add adjust srv test
Signed-off-by: euberdeveloper <euberdeveloper@gmail.com>
1 parent 7493675 commit df28fee

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

test/getCommand/getCommand.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ export default function (): void {
602602
});
603603
const outPath = './exported';
604604

605-
const expected = `mongoexport --uri="mongodb+srv://gabibbo:alteutting@chien.hao.mongodb.net/cars" --db=cars --collection=Ferrari --out=./exported`;
605+
const expected = `mongoexport --uri="mongodb+srv://gabibbo:alteutting@chien.hao.mongodb.net/cars" --collection=Ferrari --out=./exported`;
606606
const result = getCommand(database, collection, options, outPath);
607607
expect(result).to.equal(expected);
608608
});

test/getMongoConnection/getMongoConnection.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ConnectionOptions, AuthenticationMechanism } from '@/index';
2-
import { getMongoConnectionFromOptions } from '@/utils/connection';
2+
import { getMongoConnectionFromOptions, adjustOptionsForSrv } from '@/utils/connection';
33

44
import { expect } from 'chai';
55

@@ -170,4 +170,47 @@ export default function (): void {
170170
expect(result.options).to.deep.equal(expectedOptions);
171171
});
172172
});
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+
});
173216
}

0 commit comments

Comments
 (0)