diff --git a/app/api/tenants/specs/tenantsContext.spec.ts b/app/api/tenants/specs/tenantsContext.spec.ts index 31041b4381..5378623a4d 100644 --- a/app/api/tenants/specs/tenantsContext.spec.ts +++ b/app/api/tenants/specs/tenantsContext.spec.ts @@ -1,5 +1,10 @@ +import { DB } from 'api/odm/DB'; +import { Db } from 'mongodb'; +import testingDB from 'api/utils/testing_db'; +import { testingEnvironment } from 'api/utils/testingEnvironment'; import { config } from 'api/config'; import { tenants } from '../tenantContext'; +import { tenantsModel } from '../tenantsModel'; describe('tenantsContext', () => { describe('add', () => { @@ -14,4 +19,38 @@ describe('tenantsContext', () => { }, 'test-tenant'); }); }); + + describe('updateTenants', () => { + let db: Db; + + beforeAll(async () => { + await testingDB.connect(); + testingEnvironment.setRequestId(); + db = DB.connectionForDB(config.SHARED_DB).db; + + await db.collection('tenants').deleteMany({}); + await db.collection('tenants').insertMany([ + { + name: 'tenant one', + dbName: 'tenant_one', + }, + { + name: 'tenant two', + dbName: 'tenant_two', + }, + ]); + }); + + afterAll(async () => { + await db.collection('tenants').deleteMany({}); + await testingEnvironment.tearDown(); + }); + + it('should udpate tenants with DB data', async () => { + await tenants.updateTenants(await tenantsModel()); + + expect(tenants.tenants['tenant one'].dbName).toBe('tenant_one'); + expect(tenants.tenants['tenant two'].dbName).toBe('tenant_two'); + }); + }); }); diff --git a/app/api/tenants/tenantContext.ts b/app/api/tenants/tenantContext.ts index 1487de94c2..1b18384bf2 100644 --- a/app/api/tenants/tenantContext.ts +++ b/app/api/tenants/tenantContext.ts @@ -42,7 +42,7 @@ class Tenants { const tenants = await model.get(); tenants.forEach((tenant: TenantDocument) => { - this.add(tenant.toObject()); + this.add(tenant); }); } diff --git a/package.json b/package.json index 22499b0134..6e97c7d59a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uwazi", - "version": "1.177.2", + "version": "1.177.3", "description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.", "keywords": [ "react"