Skip to content

Commit

Permalink
feat(tenants): expose get all tenants on public API (#1731)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Feb 1, 2024
1 parent 9da02d4 commit f11f8fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/tenants/src/TenantsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ export class TenantsApi<AgentModules extends ModulesMap = DefaultAgentModules> {

return this.tenantRecordService.deleteTenantById(this.agentContext, tenantId)
}

public async getAllTenants() {
this.logger.debug('Getting all tenants')
return this.tenantRecordService.getAllTenants(this.agentContext)
}
}
18 changes: 15 additions & 3 deletions packages/tenants/src/__tests__/TenantsApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('TenantsApi', () => {
key: 'Wallet: TenantsApi: tenant-id',
})

expect(agentContextProvider.getAgentContextForContextCorrelationId).toBeCalledWith('tenant-id')
expect(agentContextProvider.getAgentContextForContextCorrelationId).toHaveBeenCalledWith('tenant-id')
expect(tenantAgent).toBeInstanceOf(TenantAgent)
expect(tenantAgent.context).toBe(tenantAgentContext)

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('TenantsApi', () => {
key: 'Wallet: TenantsApi: tenant-id',
})

expect(agentContextProvider.getAgentContextForContextCorrelationId).toBeCalledWith('tenant-id')
expect(agentContextProvider.getAgentContextForContextCorrelationId).toHaveBeenCalledWith('tenant-id')
expect(tenantAgent).toBeInstanceOf(TenantAgent)
expect(tenantAgent.context).toBe(tenantAgentContext)

Expand Down Expand Up @@ -125,7 +125,7 @@ describe('TenantsApi', () => {
key: 'Wallet: TenantsApi: tenant-id',
})

expect(agentContextProvider.getAgentContextForContextCorrelationId).toBeCalledWith('tenant-id')
expect(agentContextProvider.getAgentContextForContextCorrelationId).toHaveBeenCalledWith('tenant-id')
expect(tenantAgent).toBeInstanceOf(TenantAgent)
expect(tenantAgent.context).toBe(tenantAgentContext)

Expand Down Expand Up @@ -208,4 +208,16 @@ describe('TenantsApi', () => {
expect(tenantRecordService.deleteTenantById).toHaveBeenCalledWith(rootAgent.context, 'tenant-id')
})
})

describe('getAllTenants', () => {
test('calls get all tenants on tenant service', async () => {
const tenantRecords = jest.fn() as unknown as Array<TenantRecord>
mockFunction(tenantRecordService.getAllTenants).mockResolvedValue(tenantRecords)

const actualTenantRecords = await tenantsApi.getAllTenants()

expect(tenantRecordService.getAllTenants).toHaveBeenCalledWith(rootAgent.context)
expect(actualTenantRecords).toBe(tenantRecords)
})
})
})
4 changes: 4 additions & 0 deletions packages/tenants/src/services/TenantRecordService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class TenantRecordService {
return this.tenantRepository.getById(agentContext, tenantId)
}

public async getAllTenants(agentContext: AgentContext) {
return this.tenantRepository.getAll(agentContext)
}

public async deleteTenantById(agentContext: AgentContext, tenantId: string) {
const tenantRecord = await this.getTenantById(agentContext, tenantId)

Expand Down

0 comments on commit f11f8fd

Please sign in to comment.