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

Merge branch 'event-restructuring' into 'main'

feat(shared): base event setup

See merge request !5
parents 69de826c b72698cc
No related branches found
No related tags found
1 merge request!5feat(shared): base event setup
import { BaseEvent, EventDidcommConnectionsGetAll } from './events.js';
describe('check logger', () => {
it('should return module', () => {
jest.requireActual('./events');
});
it('should create a new base event', () => {
const baseEvent = new BaseEvent({ some: 'data' });
expect(typeof baseEvent.id).toStrictEqual('string');
expect(baseEvent.type).toStrictEqual('BaseEvent');
expect(baseEvent.timestamp).toBeInstanceOf(Date);
expect(baseEvent.data).toMatchObject({ some: 'data' });
});
it('should create a new connections get all event', () => {
const getAllConnectionsEvent = new EventDidcommConnectionsGetAll({
connections: [],
});
expect(typeof getAllConnectionsEvent.id).toStrictEqual('string');
expect(getAllConnectionsEvent.type).toStrictEqual(
'EventDidcommConnectionsGetAll',
);
expect(getAllConnectionsEvent.timestamp).toBeInstanceOf(Date);
expect(getAllConnectionsEvent.data).toMatchObject({ connections: [] });
});
});
import { utils, type ConnectionRecord } from '@aries-framework/core';
export class BaseEvent<
T extends Record<string, unknown> = Record<string, unknown>,
> {
public id: string;
public type: string;
public timestamp: Date;
public data: T;
public constructor(data: T) {
this.id = utils.uuid();
this.type = this.constructor.name;
this.timestamp = new Date();
this.data = data;
}
}
export class EventDidcommConnectionsGetAll extends BaseEvent<{
connections: Array<ConnectionRecord>;
}> {}
...@@ -3,3 +3,5 @@ export * from './health/health.controller.js'; ...@@ -3,3 +3,5 @@ export * from './health/health.controller.js';
export * from './logging/logger.js'; export * from './logging/logger.js';
export * from './logging/logAxiosError.js'; export * from './logging/logAxiosError.js';
export * from './events/events.js';
...@@ -29,7 +29,9 @@ describe('ConnectionsController', () => { ...@@ -29,7 +29,9 @@ describe('ConnectionsController', () => {
.spyOn(connectionsService, 'getAll') .spyOn(connectionsService, 'getAll')
.mockImplementation(() => Promise.resolve(result)); .mockImplementation(() => Promise.resolve(result));
expect(await connectionsController.getAll()).toBe(result); const connectionsEvent = await connectionsController.getAll();
expect(connectionsEvent.data).toStrictEqual({ connections: 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 { ConnectionsService } from './connections.service.js'; import { ConnectionsService } from './connections.service.js';
...@@ -8,7 +9,9 @@ export class ConnectionsController { ...@@ -8,7 +9,9 @@ export class ConnectionsController {
public constructor(private connectionsService: ConnectionsService) {} public constructor(private connectionsService: ConnectionsService) {}
@MessagePattern('didcomm.connections.getAll') @MessagePattern('didcomm.connections.getAll')
public async getAll() { public async getAll(): Promise<EventDidcommConnectionsGetAll> {
return await this.connectionsService.getAll(); return new EventDidcommConnectionsGetAll({
connections: await this.connectionsService.getAll(),
});
} }
} }
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 { ClientsModule, Transport } from '@nestjs/microservices'; import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
...@@ -36,12 +37,12 @@ describe('Connections', () => { ...@@ -36,12 +37,12 @@ describe('Connections', () => {
}); });
it('didcomm.connections.getAll', async () => { it('didcomm.connections.getAll', async () => {
const response$: Observable<unknown> = client.send( const response$: Observable<EventDidcommConnectionsGetAll> = client.send(
'didcomm.connections.getAll', 'didcomm.connections.getAll',
{}, {},
); );
const response = await firstValueFrom(response$); const response = await firstValueFrom(response$);
expect(response).toMatchObject([]); expect(response.data).toMatchObject({ connections: [] });
}); });
afterAll(async () => { afterAll(async () => {
......
...@@ -36,8 +36,8 @@ importers: ...@@ -36,8 +36,8 @@ importers:
specifier: ^5.0.1 specifier: ^5.0.1
version: 5.0.1(eslint-config-prettier@9.0.0)(eslint@8.54.0)(prettier@3.1.0) version: 5.0.1(eslint-config-prettier@9.0.0)(eslint@8.54.0)(prettier@3.1.0)
eslint-plugin-workspaces: eslint-plugin-workspaces:
specifier: ^0.9.0 specifier: ^0.10.0
version: 0.9.0 version: 0.10.0
husky: husky:
specifier: ^8.0.0 specifier: ^8.0.0
version: 8.0.3 version: 8.0.3
...@@ -7869,10 +7869,10 @@ packages: ...@@ -7869,10 +7869,10 @@ packages:
synckit: 0.8.5 synckit: 0.8.5
dev: true dev: true
   
/eslint-plugin-workspaces@0.9.0: /eslint-plugin-workspaces@0.10.0:
resolution: {integrity: sha512-krMuZ+yZgzwv1oTBfz50oamNVPDIm7CDyot3i1GRKBqMD2oXAwnXHLQWH7ctpV8k6YVrkhcaZhuV9IJxD8OPAQ==} resolution: {integrity: sha512-H692yRZFczzzyde0Sq3nmRDlyywv6foYJnmsxO3slWImJdCf4g5D+gzdWeRpmfitgUsFZxXVJdvW4OS6yY4M9g==}
dependencies: dependencies:
find-workspaces: 0.2.0 find-workspaces: 0.3.0
dev: true dev: true
   
/eslint-scope@5.1.1: /eslint-scope@5.1.1:
...@@ -8608,8 +8608,8 @@ packages: ...@@ -8608,8 +8608,8 @@ packages:
semver-regex: 4.0.5 semver-regex: 4.0.5
dev: true dev: true
   
/find-workspaces@0.2.0: /find-workspaces@0.3.0:
resolution: {integrity: sha512-OTHryv88yjzwvbXHGi0+XRFu7Jqe5pFuIR2mhqdatDJQOBJd7MFJOPFJv4EbNo8n1BNM/13Y2KcyDpFQYf0ETw==} resolution: {integrity: sha512-sHdt3vbddcDuN0CYnKoG/b77jrOkSYPlxoM7ve7/vEvAd29XC7u/qE2zavRzJv4eD1sbTvDnRNZskdy/e0v83A==}
dependencies: dependencies:
fast-glob: 3.3.2 fast-glob: 3.3.2
pkg-types: 1.0.3 pkg-types: 1.0.3
......
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