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<{ ...@@ -25,3 +25,7 @@ export class EventInfoPublicDid extends BaseEvent<{
export class EventDidcommConnectionsGetAll extends BaseEvent<{ export class EventDidcommConnectionsGetAll extends BaseEvent<{
connections: Array<ConnectionRecord>; connections: Array<ConnectionRecord>;
}> {} }> {}
export class EventDidcommConnectionsGetById extends BaseEvent<{
connection: ConnectionRecord | null;
}> {}
...@@ -11,7 +11,7 @@ describe('AgentController', () => { ...@@ -11,7 +11,7 @@ describe('AgentController', () => {
beforeEach(async () => { beforeEach(async () => {
const moduleRef = await Test.createTestingModule({ const moduleRef = await Test.createTestingModule({
imports: [mockConfigModule(3002)], imports: [mockConfigModule()],
controllers: [AgentController], controllers: [AgentController],
providers: [AgentService], providers: [AgentService],
}).compile(); }).compile();
......
...@@ -13,7 +13,7 @@ describe('ConnectionsController', () => { ...@@ -13,7 +13,7 @@ describe('ConnectionsController', () => {
beforeEach(async () => { beforeEach(async () => {
const moduleRef = await Test.createTestingModule({ const moduleRef = await Test.createTestingModule({
imports: [mockConfigModule(3003), AgentModule], imports: [mockConfigModule(), AgentModule],
controllers: [ConnectionsController], controllers: [ConnectionsController],
providers: [ConnectionsService], providers: [ConnectionsService],
}).compile(); }).compile();
...@@ -34,4 +34,19 @@ describe('ConnectionsController', () => { ...@@ -34,4 +34,19 @@ describe('ConnectionsController', () => {
expect(connectionsEvent.data).toStrictEqual({ connections: result }); 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 { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices'; import { MessagePattern } from '@nestjs/microservices';
import { EventDidcommConnectionsGetAll } from '@ocm/shared'; import {
EventDidcommConnectionsGetById,
EventDidcommConnectionsGetAll,
} from '@ocm/shared';
import { ConnectionsService } from './connections.service.js'; import { ConnectionsService } from './connections.service.js';
...@@ -14,4 +17,15 @@ export class ConnectionsController { ...@@ -14,4 +17,15 @@ export class ConnectionsController {
connections: await this.connectionsService.getAll(), 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 { ...@@ -16,4 +16,8 @@ export class ConnectionsService {
public async getAll(): Promise<Array<ConnectionRecord>> { public async getAll(): Promise<Array<ConnectionRecord>> {
return await this.agent.connections.getAll(); 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 { INestApplication } from '@nestjs/common';
import type { ClientProxy } from '@nestjs/microservices'; 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 { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
...@@ -45,6 +48,15 @@ describe('Connections', () => { ...@@ -45,6 +48,15 @@ describe('Connections', () => {
expect(response.data).toMatchObject({ 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 () => { afterAll(async () => {
await app.close(); await app.close();
client.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