Skip to content

Commit

Permalink
fix: 🐛 convert mediator affirmation expiry to Date and handle expir…
Browse files Browse the repository at this point in the history
…y of `null`
  • Loading branch information
F-OBrien committed Dec 15, 2024
1 parent 669871f commit 9ef679b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/api/entities/Instruction/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1956,9 +1956,10 @@ describe('Instruction class', () => {
describe('method: getMediators', () => {
const mediatorDid1 = 'mediatorDid1';
const mediatorDid2 = 'mediatorDid2';
const mediatorDid3 = 'mediatorDid3';

describe('querying the middleware', () => {
it('should return the instruction mediators', async () => {
it('should return the instruction mediators with affirmation info', async () => {
dsMockUtils.createApolloQueryMock(
instructionsQuery(false, {
id: id.toString(),
Expand All @@ -1967,7 +1968,7 @@ describe('Instruction class', () => {
instructions: {
nodes: [
{
mediators: [mediatorDid1, mediatorDid2],
mediators: [mediatorDid1, mediatorDid2, mediatorDid3],
},
],
},
Expand All @@ -1985,7 +1986,12 @@ describe('Instruction class', () => {
{
identity: mediatorDid2,
status: AffirmStatusEnum.Affirmed,
expiry,
expiry: expiry.toISOString(),
},
{
identity: mediatorDid3,
status: AffirmStatusEnum.Affirmed,
expiry: null,
},
],
},
Expand All @@ -2004,6 +2010,11 @@ describe('Instruction class', () => {
status: AffirmationStatus.Affirmed,
expiry,
},
{
identity: expect.objectContaining({ did: mediatorDid3 }),
status: AffirmationStatus.Affirmed,
expiry: undefined,
},
]);
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/api/entities/Instruction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,14 @@ export class Instruction extends Entity<UniqueIdentifiers, string> {
const getMediatorAffirmationStatus = (
mediatorAffirmation?: MiddlewareInstructionAffirmation
): Omit<MediatorAffirmation, 'identity'> => {
let status = AffirmationStatus.Pending;
if (mediatorAffirmation) {
status = middlewareAffirmStatusToAffirmationStatus(mediatorAffirmation.status);
if (mediatorAffirmation.expiry) {
return { status, expiry: mediatorAffirmation.expiry };
}
const status = middlewareAffirmStatusToAffirmationStatus(mediatorAffirmation.status);
return {
status,
expiry: mediatorAffirmation.expiry ? new Date(mediatorAffirmation.expiry) : undefined,
};
}
return { status };
return { status: AffirmationStatus.Pending };
};

return (mediators as string[]).map(mediator => {
Expand Down

0 comments on commit 9ef679b

Please sign in to comment.