Skip to content

Commit

Permalink
git push add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Apr 9, 2024
1 parent fc54150 commit bc5577d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/iden3comm/handlers/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class AbstractMessageHandler implements IProtocolMessageHandler
}

export class MessageHandler {
private messageHandler?: AbstractMessageHandler;
public messageHandler?: AbstractMessageHandler;

constructor(
private readonly _params: {
Expand Down
27 changes: 25 additions & 2 deletions tests/iden3comm/message-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import {
AuthHandler,
AuthorizationRequestMessage,
BasicMessage,
CircuitId,
CredentialRequest,
CredentialStatusResolverRegistry,
Expand All @@ -17,7 +18,10 @@ import {
RHSResolver,
byteEncoder
} from '../../src';
import { MessageHandler } from '../../src/iden3comm/handlers/message-handler';
import {
AbstractMessageHandler,
MessageHandler
} from '../../src/iden3comm/handlers/message-handler';
import { DID } from '@iden3/js-iden3-core';
import {
MOCK_STATE_STORAGE,
Expand Down Expand Up @@ -49,6 +53,15 @@ describe('MessageHandler', () => {
const kms = registerBJJIntoInMemoryKMS();
const dataStorage = getInMemoryDataStorage(MOCK_STATE_STORAGE);

const dummyHandler = {
handle: async (msg: BasicMessage) => {
if (msg.type === 'msg-type-req') {
return {
type: 'msg-type-resp'
};
}
}
} as unknown as AbstractMessageHandler;
const resolvers = new CredentialStatusResolverRegistry();
resolvers.register(
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
Expand Down Expand Up @@ -186,7 +199,7 @@ describe('MessageHandler', () => {
expect(issuerAuthCredential).not.to.be.undefined;

const messageHandler = new MessageHandler({
messageHandlers: [authHandler],
messageHandlers: [authHandler, dummyHandler],
packageManager: packageMgr
});

Expand Down Expand Up @@ -263,5 +276,15 @@ describe('MessageHandler', () => {
await messageHandler.handleMessage(authResp!, {
request: authReq
});

const dummyHandlerResponseMsg = await dummyHandler.handle(
{
type: 'msg-type-req'
} as BasicMessage,
{}
);

expect(dummyHandlerResponseMsg).not.to.be.null;
expect(dummyHandlerResponseMsg!.type).to.be.eq('msg-type-resp');
});
});

0 comments on commit bc5577d

Please sign in to comment.