From c5b94c278ab25964dc1ea448048005ecf957319c Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Fri, 18 Oct 2024 19:53:14 -0400 Subject: [PATCH] complete coverage --- packages/agent/tests/utils.spec.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/agent/tests/utils.spec.ts b/packages/agent/tests/utils.spec.ts index f2c21f34d..3751613e8 100644 --- a/packages/agent/tests/utils.spec.ts +++ b/packages/agent/tests/utils.spec.ts @@ -1,9 +1,18 @@ import { expect } from 'chai'; +import sinon from 'sinon'; -import { DateSort, Message, TestDataGenerator } from '@tbd54566975/dwn-sdk-js'; +import { DateSort, Jws, Message, TestDataGenerator } from '@tbd54566975/dwn-sdk-js'; import { getPaginationCursor, getRecordAuthor, getRecordMessageCid, getRecordProtocolRole } from '../src/utils.js'; describe('Utils', () => { + beforeEach(() => { + sinon.restore(); + }); + + after(() => { + sinon.restore(); + }); + describe('getPaginationCursor', () => { it('should return a PaginationCursor object', async () => { // create a RecordWriteMessage object which is published @@ -107,5 +116,12 @@ describe('Utils', () => { const deleteRole = getRecordProtocolRole(recordsDelete.message); expect(deleteRole).to.be.undefined; }); + + it('returns undefined if decodedObject is undefined', async () => { + sinon.stub(Jws, 'decodePlainObjectPayload').returns(undefined); + const recordsWrite = await TestDataGenerator.generateRecordsWrite(); + const writeRole = getRecordProtocolRole(recordsWrite.message); + expect(writeRole).to.be.undefined; + }); }); }); \ No newline at end of file