Skip to content

Commit 08ffb74

Browse files
committed
Add new unit test
1 parent 0f585e7 commit 08ffb74

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/Contexts/Shared/infrastructure/MongoClientFactory.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MongoClientFactory } from '../../../../src/Contexts/Shared/infrastructure/persistence/mongo/MongoClientFactory';
22
import { MongoClient } from 'mongodb';
33

4-
describe('MongoClientFactory', () => {
4+
describe('Create a client', () => {
55
const factory = MongoClientFactory;
66
let client: MongoClient;
77

@@ -13,12 +13,24 @@ describe('MongoClientFactory', () => {
1313
await client.close();
1414
});
1515

16-
it('creates a new client if it does not exist', () => {
16+
it('creates a new client with the connection already established', () => {
1717
expect(client).toBeInstanceOf(MongoClient);
18+
expect(client.isConnected()).toBeTruthy();
1819
});
1920

20-
it('creates a new client with existing name should return existing client', async () => {
21+
it('creates a new client if it does not exist a client with the given name', async () => {
22+
const newClient = await factory.createClient('test2');
23+
24+
expect(newClient).not.toBe(client);
25+
26+
await newClient.close();
27+
});
28+
29+
it('returns a client if it already exists', async () => {
2130
const newClient = await factory.createClient('test');
31+
2232
expect(newClient).toBe(client);
33+
34+
await newClient.close();
2335
});
2436
});

0 commit comments

Comments
 (0)