Skip to content
Snippets Groups Projects
Commit 1c8e7047 authored by Berend Sliedrecht's avatar Berend Sliedrecht
Browse files

feat(ssi): get connection by id


Signed-off-by: default avatarBerend Sliedrecht <berend@animo.id>
parent 037b5a6c
No related branches found
No related tags found
1 merge request!6feat(ssi): added public did and event
......@@ -25,3 +25,7 @@ export class EventInfoPublicDid extends BaseEvent<{
export class EventDidcommConnectionsGetAll extends BaseEvent<{
connections: Array<ConnectionRecord>;
}> {}
export class EventDidcommConnectionsGetById extends BaseEvent<{
connection: ConnectionRecord | null;
}> {}
......@@ -11,7 +11,7 @@ describe('AgentController', () => {
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [mockConfigModule(3002)],
imports: [mockConfigModule()],
controllers: [AgentController],
providers: [AgentService],
}).compile();
......
......@@ -13,7 +13,7 @@ describe('ConnectionsController', () => {
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [mockConfigModule(3003), AgentModule],
imports: [mockConfigModule(), AgentModule],
controllers: [ConnectionsController],
providers: [ConnectionsService],
}).compile();
......@@ -34,4 +34,19 @@ describe('ConnectionsController', () => {
expect(connectionsEvent.data).toStrictEqual({ connections: result });
});
});
describe('get by id', () => {
it('should get a connection record by id', async () => {
const result: ConnectionRecord | null = null;
jest
.spyOn(connectionsService, 'getById')
.mockImplementation(() => Promise.resolve(result));
const connectionsEvent = await connectionsController.getById({
id: 'id',
});
expect(connectionsEvent.data).toStrictEqual({ connection: result });
});
});
});
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { EventDidcommConnectionsGetAll } from '@ocm/shared';
import {
EventDidcommConnectionsGetById,
EventDidcommConnectionsGetAll,
} from '@ocm/shared';
import { ConnectionsService } from './connections.service.js';
......@@ -14,4 +17,15 @@ export class ConnectionsController {
connections: await this.connectionsService.getAll(),
});
}
@MessagePattern('didcomm.connections.getById')
public async getById({
id,
}: {
id: string;
}): Promise<EventDidcommConnectionsGetById> {
return new EventDidcommConnectionsGetById({
connection: await this.connectionsService.getById(id),
});
}
}
......@@ -16,4 +16,8 @@ export class ConnectionsService {
public async getAll(): Promise<Array<ConnectionRecord>> {
return await this.agent.connections.getAll();
}
public async getById(id: string): Promise<ConnectionRecord | null> {
return await this.agent.connections.findById(id);
}
}
import type { INestApplication } from '@nestjs/common';
import type { ClientProxy } from '@nestjs/microservices';
import type { EventDidcommConnectionsGetAll } from '@ocm/shared';
import type {
EventDidcommConnectionsGetById,
EventDidcommConnectionsGetAll,
} from '@ocm/shared';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
......@@ -45,6 +48,15 @@ describe('Connections', () => {
expect(response.data).toMatchObject({ connections: [] });
});
it('didcomm.connections.getById', async () => {
const response$: Observable<EventDidcommConnectionsGetById> = client.send(
'didcomm.connections.getById',
{ id: 'some-id' },
);
const response = await firstValueFrom(response$);
expect(response.data).toMatchObject({ connection: null });
});
afterAll(async () => {
await app.close();
client.close();
......
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