Skip to content

Commit 3da1d84

Browse files
committed
add test cases
1 parent a84d220 commit 3da1d84

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/extension-driver-canner/test/cannerDataSource.spec.ts

+40
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,55 @@ it('Should return the same pool when the profile and authentication is the same'
350350

351351
it('Should return new user pool if user pool not exist', async () => {
352352
// Arrange
353+
const profile1 = pg.getProfile('profile1');
354+
const database = <string>profile1.connection.database;
353355
mockDataSource = new MockCannerDataSource({}, '', [
354356
pg.getProfile('profile1'),
355357
]);
356358
await mockDataSource.activate();
357359
// Act
358360
const pool1 = mockDataSource.getPool('profile1');
359361
const pool2 = mockDataSource.getPool('profile1', 'my-authentication');
362+
const userPool = mockDataSource.getUserPool('my-authentication', database);
360363
// Assert
361364
expect(pool1 == pool2).toBeFalsy();
365+
expect(userPool === pool2).toBeTruthy();
366+
}, 30000);
367+
368+
it('Should return existing user pool if user pool exist', async () => {
369+
// Arrange
370+
const profile1 = pg.getProfile('profile1');
371+
const database = <string>profile1.connection.database;
372+
mockDataSource = new MockCannerDataSource({}, '', [
373+
pg.getProfile('profile1'),
374+
]);
375+
await mockDataSource.activate();
376+
377+
// Act
378+
const pool = mockDataSource.getPool('profile1', 'my-authentication');
379+
const userPool = mockDataSource.getUserPool('my-authentication', database);
380+
// Assert
381+
expect(userPool === pool).toBeTruthy();
382+
}, 30000);
383+
384+
it('Should return new user pool if user pool exist but not match', async () => {
385+
// Arrange
386+
const profile1 = pg.getProfile('profile1');
387+
const database = <string>profile1.connection.database;
388+
mockDataSource = new MockCannerDataSource({}, '', [
389+
pg.getProfile('profile1'),
390+
]);
391+
await mockDataSource.activate();
392+
393+
// Act
394+
expect(mockDataSource.getUserPool('my-authentication', database)).toBe(
395+
undefined
396+
);
397+
mockDataSource.getPool('profile1', 'my-authentication');
398+
// Assert
399+
expect(
400+
mockDataSource.getUserPool('my-authentication', database)
401+
).toBeDefined();
362402
}, 30000);
363403

364404
it('Should return different pool with different authentication even the profile is the same', async () => {

packages/extension-driver-canner/test/mock/mockCannerDataSource.ts

+10
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ export class MockCannerDataSource extends CannerDataSource {
2222
this.UserPool.set(userPoolKey, pool);
2323
return pool;
2424
}
25+
26+
public setUserPool = (userPool: Pool, password: string, database: string) => {
27+
const userPoolKey = this.getUserPoolKey(password, database);
28+
this.UserPool.set(userPoolKey, userPool);
29+
};
30+
31+
public getUserPool = (password: string, database: string) => {
32+
const userPoolKey = this.getUserPoolKey(password, database);
33+
return this.UserPool.get(userPoolKey);
34+
};
2535
}

0 commit comments

Comments
 (0)