Skip to content

Commit

Permalink
test: Re-register the instance of CacheModuleConfig with a fresh cach…
Browse files Browse the repository at this point in the history
…e before each test

Signed-off-by: Sagar Khole <sagar.khole@ayanworks.com>
  • Loading branch information
sagarkhole4 committed Sep 9, 2024
1 parent 6c32543 commit b3cf22a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/tenants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"dependencies": {
"@credo-ts/core": "workspace:*",
"async-mutex": "^0.4.0"
"async-mutex": "^0.4.0",
"tsyringe": "^4.8.0"
},
"devDependencies": {
"@credo-ts/node": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ describe('TenantAgentContextProvider', () => {
jest.clearAllMocks()
})

beforeEach(() => {
// Re-register the instance of CacheModuleConfig with a fresh cache before each test
container.registerInstance(
CacheModuleConfig,
new CacheModuleConfig({
cache: new InMemoryLruCache({ limit: 100 }), // Fresh cache for each test
})
)
})

describe('getAgentContextForContextCorrelationId', () => {
test('retrieves the tenant and calls tenant session coordinator', async () => {
const tenantRecord = new TenantRecord({
Expand All @@ -63,13 +73,6 @@ describe('TenantAgentContextProvider', () => {

const tenantAgentContext = jest.fn() as unknown as AgentContext

container.registerInstance(
CacheModuleConfig,
new CacheModuleConfig({
cache: new InMemoryLruCache({ limit: 100 }),
})
)

mockFunction(tenantRecordService.getTenantById).mockResolvedValue(tenantRecord)
mockFunction(tenantSessionCoordinator.getContextForSession).mockResolvedValue(tenantAgentContext)

Expand Down

0 comments on commit b3cf22a

Please sign in to comment.