Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbi08 committed Sep 24, 2024
1 parent 88ef386 commit c0c0aad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,32 @@ describe("ShareAttributeRequestItemProcessor", function () {
const sender = testAccount.identity.address;
const recipient = CoreAddress.from("Recipient");

// eslint-disable-next-line jest/no-conditional-in-test
if (testParams.attribute.owner.address === "Sender") {
testParams.attribute.owner = sender;
}

// eslint-disable-next-line jest/no-conditional-in-test
if (testParams.attribute.owner.address === "Recipient") {
testParams.attribute.owner = recipient;
}

let sourceAttribute;

// eslint-disable-next-line jest/no-conditional-in-test
if (testParams.attribute instanceof IdentityAttribute) {
sourceAttribute = await consumptionController.attributes.createAttributeUnsafe({
content: {
...testParams.attribute.toJSON(),
// eslint-disable-next-line jest/no-conditional-in-test
owner: testParams.attribute.owner.equals("") ? sender : testParams.attribute.owner
} as IIdentityAttribute
});
} else {
sourceAttribute = await consumptionController.attributes.createSharedLocalAttribute({
content: {
...testParams.attribute.toJSON(),
// eslint-disable-next-line jest/no-conditional-in-test
owner: testParams.attribute.owner.equals("") ? sender : testParams.attribute.owner
} as IRelationshipAttribute,
peer: aThirdParty,
Expand All @@ -169,12 +174,14 @@ describe("ShareAttributeRequestItemProcessor", function () {
const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: false,
attribute: sourceAttribute.content,
sourceAttributeId: sourceAttribute.id
sourceAttributeId: sourceAttribute.id,
thirdPartyAddress: aThirdParty
});
const request = Request.from({ items: [requestItem] });

const result = await processor.canCreateOutgoingRequestItem(requestItem, request, recipient);

// eslint-disable-next-line jest/no-conditional-in-test
if (testParams.result === "success") {
// eslint-disable-next-line jest/no-conditional-expect
expect(result).successfulValidationResult();
Expand Down Expand Up @@ -861,7 +868,8 @@ describe("ShareAttributeRequestItemProcessor", function () {
const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: false,
attribute: initialRelationshipAttribute.content,
sourceAttributeId: initialRelationshipAttribute.id
sourceAttributeId: initialRelationshipAttribute.id,
thirdPartyAddress: aThirdParty
});
const request = Request.from({ items: [requestItem] });

Expand Down Expand Up @@ -908,7 +916,8 @@ describe("ShareAttributeRequestItemProcessor", function () {
const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: false,
attribute: initialRelationshipAttribute.content,
sourceAttributeId: initialRelationshipAttribute.id
sourceAttributeId: initialRelationshipAttribute.id,
thirdPartyAddress: aThirdParty
});
const request = Request.from({ items: [requestItem] });

Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/src/modules/AttributeListenerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class AttributeListenerModule extends RuntimeModule {
metadata: { attributeListenerId: attributeListener.id }
};

if (attribute.content["@type"] === "RelationshipAttribute" && attributeListener.peer !== attribute.shareInfo?.peer) {
requestItem.thirdPartyAddress = attribute.shareInfo?.peer;
}

const validationResult = await services.consumptionServices.outgoingRequests.canCreate({
content: { items: [requestItem] },
peer: attributeListener.peer
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/test/modules/RequestModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ describe("Handling the rejection and the revocation of a Relationship by the Req
"@type": "ShareAttributeRequestItem",
mustBeAccepted: true,
sourceAttributeId: existingRelationshipAttributeForFurtherSharing.id,
attribute: existingRelationshipAttributeForFurtherSharing.content
attribute: existingRelationshipAttributeForFurtherSharing.content,
thirdPartyAddress: existingRelationshipAttributeForFurtherSharing.shareInfo?.peer
}
],
[{ accept: true }, { accept: true }, { accept: true }]
Expand Down

0 comments on commit c0c0aad

Please sign in to comment.