Skip to content
Snippets Groups Projects
Verified Commit 91336d97 authored by Berend Sliedrecht's avatar Berend Sliedrecht Committed by Konstantin Tsabolov
Browse files

feat: get all tenant ids


Signed-off-by: default avatarBerend Sliedrecht <berend@animo.id>
parent ede9cb95
No related branches found
No related tags found
1 merge request!40End to end run preparation
......@@ -21,21 +21,28 @@ describe('TenantsController', () => {
tenantsController = moduleRef.get(TenantsController);
});
describe('resolve', () => {
it('should resolve a basic did', async () => {
const result = new TenantRecord({
config: {
label: 'my-label',
walletConfig: { key: 'some-key', id: 'some-id' },
},
});
jest.spyOn(tenantsService, 'create').mockResolvedValue(result);
const event = await tenantsController.create({
it('create', async () => {
const result = new TenantRecord({
config: {
label: 'my-label',
});
walletConfig: { key: 'some-key', id: 'some-id' },
},
});
jest.spyOn(tenantsService, 'create').mockResolvedValue(result);
expect(event.data).toStrictEqual(result);
const event = await tenantsController.create({
label: 'my-label',
});
expect(event.data).toStrictEqual(result);
});
it('get All', async () => {
const result = ['some-id', 'another-id'];
jest.spyOn(tenantsService, 'getAllTenantIds').mockResolvedValue(result);
const event = await tenantsController.getAllTenantIds();
expect(event.data).toStrictEqual(result);
});
});
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { EventTenantsCreate, EventTenantsCreateInput } from '@ocm/shared';
import {
EventTenantsCreate,
EventTenantsCreateInput,
EventTenantsGetAllTenantIds,
} from '@ocm/shared';
import { TenantsService } from './tenants.service.js';
......@@ -9,11 +13,19 @@ export class TenantsController {
public constructor(private tenantsService: TenantsService) {}
@MessagePattern(EventTenantsCreate.token)
public async create({
label,
}: EventTenantsCreateInput): Promise<EventTenantsCreate> {
public async create(
options: EventTenantsCreateInput,
): Promise<EventTenantsCreate> {
return new EventTenantsCreate(
await this.tenantsService.create(label),
await this.tenantsService.create(options),
undefined,
);
}
@MessagePattern(EventTenantsGetAllTenantIds.token)
public async getAllTenantIds(): Promise<EventTenantsGetAllTenantIds> {
return new EventTenantsGetAllTenantIds(
await this.tenantsService.getAllTenantIds(),
undefined,
);
}
......
import type { AppAgent } from '../agent.service.js';
import type {
EventTenantsCreate,
EventTenantsCreateInput,
EventTenantsGetAllTenantIds,
} from '@ocm/shared';
import { TenantRepository } from '@aries-framework/tenants/build/repository/TenantRepository.js';
import { Injectable } from '@nestjs/common';
import { AgentService } from '../agent.service.js';
......@@ -12,7 +18,18 @@ export class TenantsService {
this.agent = agentService.agent;
}
public async create(label: string) {
public async create({
label,
}: EventTenantsCreateInput): Promise<EventTenantsCreate['data']> {
return await this.agent.modules.tenants.createTenant({ config: { label } });
}
public async getAllTenantIds(): Promise<EventTenantsGetAllTenantIds['data']> {
const tenantRepository =
this.agent.dependencyManager.resolve(TenantRepository);
const tenantRecords = await tenantRepository.getAll(this.agent.context);
return tenantRecords.map((t) => t.id);
}
}
import type { INestApplication } from '@nestjs/common';
import type { ClientProxy } from '@nestjs/microservices';
import type { EventTenantsCreateInput } from '@ocm/shared';
import type {
EventTenantsCreateInput,
EventTenantsGetAllTenantIdsInput,
} from '@ocm/shared';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
import { EventTenantsCreate } from '@ocm/shared';
import { EventTenantsGetAllTenantIds, EventTenantsCreate } from '@ocm/shared';
import { firstValueFrom } from 'rxjs';
import { AgentModule } from '../src/agent/agent.module.js';
......@@ -62,4 +65,25 @@ describe('Tenants', () => {
},
});
});
it(EventTenantsGetAllTenantIds.token, async () => {
const createResponse$ = client.send<
EventTenantsCreate,
EventTenantsCreateInput
>(EventTenantsCreate.token, {
label: 'my-new-tenant',
});
await firstValueFrom(createResponse$);
const response$ = client.send<
EventTenantsGetAllTenantIds,
EventTenantsGetAllTenantIdsInput
>(EventTenantsGetAllTenantIds.token, {});
const response = await firstValueFrom(response$);
const eventInstance = EventTenantsGetAllTenantIds.fromEvent(response);
expect(eventInstance.instance.length).toBeGreaterThanOrEqual(1);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment