Skip to content

Commit

Permalink
fix ts type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Jan 16, 2025
1 parent 2c62fd9 commit 3c0f7d4
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('migration add collections for v2 relationships migration', () => {
});

it('should set unique index on the migration fields', async () => {
const relCollection = await db.collection('relationshipMigrationFields');
const relCollection = db.collection('relationshipMigrationFields');
const indexInfo = await relCollection.indexInformation({ full: true });
const uniqueIndex = indexInfo.find(
(index: any) => index.name === 'sourceTemplate_1_relationType_1_targetTemplate_1'
);
expect(uniqueIndex.unique).toBe(true);
expect(uniqueIndex?.unique).toBe(true);
});

it('should check if a reindex is needed', async () => {
Expand Down
4 changes: 2 additions & 2 deletions app/api/odm/specs/DB.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('DB', () => {
beforeEach(async () => {
const uri = config.DBHOST;
await DB.connect(`${uri}_DB_spec_ts`);
db1 = DB.getConnection().useDb('db1').db;
db2 = DB.getConnection().useDb('db2').db;
db1 = DB.getConnection().getClient().db('db1');
db2 = DB.getConnection().getClient().db('db2');
});

afterAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions app/api/odm/specs/model_multi_tenant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe('ODM Model multi-tenant', () => {

beforeAll(async () => {
await testingDB.connect({ defaultTenant: false });
defaultDB = DB.connectionForDB(config.defaultTenant.dbName).db;
db1 = DB.connectionForDB('db1').db;
db2 = DB.connectionForDB('db2').db;
defaultDB = DB.getConnection().getClient().db(config.defaultTenant.dbName);
db1 = DB.getConnection().getClient().db('db1');
db2 = DB.getConnection().getClient().db('db2');
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ describe('PDFSegmentation', () => {

beforeEach(async () => {
segmentPdfs = new PDFSegmentation();
dbOne = DB.connectionForDB(tenantOne.dbName).db;
dbTwo = DB.connectionForDB(tenantTwo.dbName).db;
dbOne = DB.getConnection().getClient().db(tenantOne.dbName);
dbTwo = DB.getConnection().getClient().db(tenantTwo.dbName);

tenants.tenants = { tenantOne };
fileA = await fs.readFile(`app/api/services/pdfsegmentation/specs/uploads/${fixturesPdfNameA}`);
Expand Down
2 changes: 1 addition & 1 deletion app/api/stats/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DB } from 'api/odm';

export default (app: Application) => {
app.get('/api/stats', needsAuthorization(['admin']), async (_req, res, _next) => {
const { db } = DB.connectionForDB(tenants.current().dbName);
const db = DB.getConnection().getClient().db(tenants.current().dbName);
const action = new RetrieveStatsService(db);
const stats = await action.execute();

Expand Down
2 changes: 1 addition & 1 deletion app/api/stats/specs/RetrieveStatsService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('RetrieveStats', () => {
let db: Db;

beforeAll(async () => {
db = (await testingDB.connect()).db;
db = (await testingDB.connect()).db as Db;
});

beforeEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion app/api/tenants/specs/tenantsContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('tenantsContext', () => {
beforeAll(async () => {
await testingDB.connect();
testingEnvironment.setRequestId();
db = DB.connectionForDB(config.SHARED_DB).db;
db = DB.getConnection().getClient().db(config.SHARED_DB);

await db.collection('tenants').deleteMany({});
await db.collection('tenants').insertMany([
Expand Down
2 changes: 1 addition & 1 deletion app/api/tenants/specs/tenantsModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('tenantsModel', () => {
beforeAll(async () => {
await testingDB.connect();
testingEnvironment.setRequestId();
db = DB.connectionForDB(config.SHARED_DB).db;
db = DB.connectionForDB(config.SHARED_DB).getClient().db(config.SHARED_DB);
});

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions app/api/utils/testing_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const testingDB: {
.basename(expect.getState().testPath || '')
.replace(/[.-]/g, '_')}`.substring(0, 63);
await initMongoServer(this.dbName);
mongodb = mongooseConnection.db;
mongodb = mongooseConnection.getClient().db();
this.mongodb = mongodb;

if (options.defaultTenant) {
Expand Down Expand Up @@ -148,7 +148,7 @@ const testingDB: {
await this.connect();
let optionalMongo: Db | null = null;
if (dbName) {
optionalMongo = DB.connectionForDB(dbName).db;
optionalMongo = DB.connectionForDB(dbName).getClient().db(dbName);
}
await fixturer.clearAllAndLoad(optionalMongo || mongodb, fixtures);
await this.createIndices();
Expand Down

0 comments on commit 3c0f7d4

Please sign in to comment.