Skip to content

Commit

Permalink
Rename TestIdentities (#405)
Browse files Browse the repository at this point in the history
* refactor: use more descriptive names for TestIdentities

* test: update test names

* refactor: write recipient lowercase

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Milena-Czierlinski and mergify[bot] authored Jan 29, 2025
1 parent 1d896bc commit de2c672
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class Context {

public translateTestIdentity(testIdentity: CoreAddress): CoreAddress | undefined {
switch (testIdentity.toString()) {
case TestIdentity.SENDER.toString():
case TestIdentity.CURRENT_IDENTITY.toString():
return this.accountController.identity.address;
case TestIdentity.RECIPIENT.toString():
case TestIdentity.PEER.toString():
return this.peerAddress;
case TestIdentity.EMPTY.toString():
return CoreAddress.from("");
Expand Down Expand Up @@ -230,7 +230,7 @@ export class WhenSteps {
await this.context.consumptionController.attributes.updateAttributeUnsafe(attribute);
}

public async iCallCanCreateOutgoingRequestItemWith(partialRequestItem: Partial<CreateAttributeRequestItem>, recipient: CoreAddress = TestIdentity.RECIPIENT): Promise<void> {
public async iCallCanCreateOutgoingRequestItemWith(partialRequestItem: Partial<CreateAttributeRequestItem>, recipient: CoreAddress = TestIdentity.PEER): Promise<void> {
partialRequestItem.mustBeAccepted ??= true;
partialRequestItem.attribute ??= TestObjectFactory.createIdentityAttribute({
owner: this.context.accountController.identity.address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ describe("CreateAttributeRequestItemProcessor", function () {
});

describe("canCreateOutgoingRequestItem", function () {
test("returns Success when passing an IdentityAttribute with owner={{Recipient}}", async function () {
test("returns Success when passing an IdentityAttribute with owner={{Peer}}", async function () {
const identityAttributeOfRecipient = TestObjectFactory.createIdentityAttribute({
owner: TestIdentity.RECIPIENT
owner: TestIdentity.PEER
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: identityAttributeOfRecipient });
await Then.theCanCreateResultShouldBeASuccess();
});

test("returns an Error when passing an IdentityAttribute with owner={{Sender}}", async function () {
test("returns an Error when passing an IdentityAttribute with owner={{CurrentIdentity}}", async function () {
const identityAttributeOfSender = TestObjectFactory.createIdentityAttribute({
owner: TestIdentity.SENDER
owner: TestIdentity.CURRENT_IDENTITY
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: identityAttributeOfSender });
Expand Down Expand Up @@ -72,7 +72,7 @@ describe("CreateAttributeRequestItemProcessor", function () {
});
});

test("returns Success when passing an IdentityAttribute with owner={{SomeoneElse}}, but no Recipient", async function () {
test("returns Success when passing an IdentityAttribute with owner={{SomeoneElse}}, but no recipient", async function () {
const identityAttributeOfSomeoneElse = TestObjectFactory.createIdentityAttribute({
owner: TestIdentity.SOMEONE_ELSE
});
Expand All @@ -84,18 +84,18 @@ describe("CreateAttributeRequestItemProcessor", function () {
});
});

test("returns Success when passing a RelationshipAttribute with owner={{Recipient}}", async function () {
test("returns Success when passing a RelationshipAttribute with owner={{Peer}}", async function () {
const relationshipAttributeOfRecipient = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.RECIPIENT
owner: TestIdentity.PEER
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfRecipient });
await Then.theCanCreateResultShouldBeASuccess();
});

test("returns Success when passing a RelationshipAttribute with owner={{Sender}}", async function () {
test("returns Success when passing a RelationshipAttribute with owner={{CurrentIdentity}}", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER
owner: TestIdentity.CURRENT_IDENTITY
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfSender });
Expand Down Expand Up @@ -123,7 +123,7 @@ describe("CreateAttributeRequestItemProcessor", function () {
});
});

test("returns Success when passing a RelationshipAttribute with owner={{SomeoneElse}}, but no Recipient", async function () {
test("returns Success when passing a RelationshipAttribute with owner={{SomeoneElse}}, but no recipient", async function () {
const relationshipAttributeOfSomeoneElse = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SOMEONE_ELSE
});
Expand All @@ -138,28 +138,28 @@ describe("CreateAttributeRequestItemProcessor", function () {

test("returns Error when passing a RelationshipAttribute with same key as an already existing RelationshipAttribute of this Relationship", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "uniqueKey"
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);

const relationshipAttributeWithSameKey = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "uniqueKey"
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKey }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKey }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeAnErrorWith({
code: "error.consumption.requests.invalidRequestItem",
message:
"The creation of the provided RelationshipAttribute cannot be requested because there is already a RelationshipAttribute in the context of this Relationship with the same key 'uniqueKey', owner and value type."
});
});

test("returns Error on violation of key uniqueness even if the owner of the provided RelationshipAttribute is an empty string as long as the Recipient is known", async function () {
test("returns Error on violation of key uniqueness even if the owner of the provided RelationshipAttribute is an empty string as long as the recipient is known", async function () {
const relationshipAttributeOfRecipient = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.RECIPIENT,
owner: TestIdentity.PEER,
key: "uniqueKey"
});

Expand All @@ -170,7 +170,7 @@ describe("CreateAttributeRequestItemProcessor", function () {
key: "uniqueKey"
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKeyAndEmptyOwner }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKeyAndEmptyOwner }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeAnErrorWith({
code: "error.consumption.requests.invalidRequestItem",
message:
Expand All @@ -180,80 +180,80 @@ describe("CreateAttributeRequestItemProcessor", function () {

test("returns Success when passing a RelationshipAttribute with same key but different owner", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "ownerSpecificUniqueKey"
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);

const relationshipAttributeOfRecipient = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.RECIPIENT,
owner: TestIdentity.PEER,
key: "ownerSpecificUniqueKey"
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfRecipient }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfRecipient }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeASuccess();
});

test("returns Success when passing a RelationshipAttribute with same key but different value type", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "valueTypeSpecificUniqueKey",
value: ProprietaryString.from({ title: "aTitle", value: "aProprietaryStringValue" })
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);

const relationshipAttributeOfRecipient = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "valueTypeSpecificUniqueKey",
value: ProprietaryInteger.from({ title: "aTitle", value: 1 })
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfRecipient }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfRecipient }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeASuccess();
});

test("returns Success when passing a RelationshipAttribute with same key as a RelationshipAttribute in deletion", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "persistenceSpecificUniqueKey"
});

const createdAttribute = await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);
await When.iMarkMyAttributeAsToBeDeleted(createdAttribute);

const relationshipAttributeWithSameKey = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "persistenceSpecificUniqueKey"
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKey }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeWithSameKey }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeASuccess();
});

test("returns Success when passing a RelationshipAttribute with same key as an already existing ThirdPartyRelationshipAttribute", async function () {
const thirdPartyRelationshipAttribute = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "relationshipSpecificUniqueKey"
});

await When.iCreateAThirdPartyRelationshipAttribute(thirdPartyRelationshipAttribute);

const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER,
owner: TestIdentity.CURRENT_IDENTITY,
key: "relationshipSpecificUniqueKey"
});

await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfSender }, TestIdentity.RECIPIENT);
await When.iCallCanCreateOutgoingRequestItemWith({ attribute: relationshipAttributeOfSender }, TestIdentity.PEER);
await Then.theCanCreateResultShouldBeASuccess();
});
});

describe("canAccept", function () {
test("can create a RelationshipAttribute", async function () {
await Given.aRequestItemWithARelationshipAttribute({
attributeOwner: TestIdentity.RECIPIENT
attributeOwner: TestIdentity.PEER
});

await When.iCallCanAccept();
Expand All @@ -262,13 +262,13 @@ describe("CreateAttributeRequestItemProcessor", function () {

test("cannot create another RelationshipAttribute with same key", async function () {
const relationshipAttributeOfRecipient = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.RECIPIENT
owner: TestIdentity.PEER
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfRecipient);

await Given.aRequestItemWithARelationshipAttribute({
attributeOwner: TestIdentity.RECIPIENT
attributeOwner: TestIdentity.PEER
});

await expect(When.iCallCanAccept()).rejects.toThrow(
Expand All @@ -278,7 +278,7 @@ describe("CreateAttributeRequestItemProcessor", function () {

test("cannot create another RelationshipAttribute with same key even if the owner of the provided RelationshipAttribute is an empty string", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER
owner: TestIdentity.CURRENT_IDENTITY
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);
Expand All @@ -294,7 +294,7 @@ describe("CreateAttributeRequestItemProcessor", function () {

test("cannot accept because it would lead to the creation of another RelationshipAttribute with same key but rejecting of the CreateAttributeRequestItem would be permitted", async function () {
const relationshipAttributeOfSender = TestObjectFactory.createRelationshipAttribute({
owner: TestIdentity.SENDER
owner: TestIdentity.CURRENT_IDENTITY
});

await When.iCreateARelationshipAttribute(relationshipAttributeOfSender);
Expand All @@ -317,15 +317,15 @@ describe("CreateAttributeRequestItemProcessor", function () {
describe("accept", function () {
test("in case of a RelationshipAttribute: creates an own shared RelationshipAttribute", async function () {
await Given.aRequestItemWithARelationshipAttribute({
attributeOwner: TestIdentity.SENDER
attributeOwner: TestIdentity.CURRENT_IDENTITY
});
await When.iCallAccept();
await Then.anOwnSharedRelationshipAttributeIsCreated();
});

test("in case of an IdentityAttribute: creates a RepositoryAttribute and an own shared IdentityAttribute", async function () {
await Given.aRequestItemWithAnIdentityAttribute({
attributeOwner: TestIdentity.SENDER
attributeOwner: TestIdentity.CURRENT_IDENTITY
});
await When.iCallAccept();
await Then.aRepositoryAttributeIsCreated();
Expand All @@ -334,7 +334,7 @@ describe("CreateAttributeRequestItemProcessor", function () {
});

describe("applyIncomingResponseItem", function () {
test.each([TestIdentity.RECIPIENT, TestIdentity.EMPTY])(
test.each([TestIdentity.PEER, TestIdentity.EMPTY])(
"in case of an IdentityAttribute with owner=${value.toString()}: creates a LocalAttribute with the Attribute from the RequestItem and the attributeId from the ResponseItem for the peer of the request ",
async function (attributeOwner: CoreAddress) {
await Given.aRequestItemWithAnIdentityAttribute({ attributeOwner });
Expand All @@ -345,7 +345,7 @@ describe("CreateAttributeRequestItemProcessor", function () {
}
);

test.each([TestIdentity.RECIPIENT, TestIdentity.EMPTY, TestIdentity.SENDER])(
test.each([TestIdentity.PEER, TestIdentity.EMPTY, TestIdentity.CURRENT_IDENTITY])(
"in case of a RelationshipAttribute with owner=${value.toString()}: creates a LocalAttribute with the Attribute from the RequestItem and the attributeId from the ResponseItem for the peer of the request ",
async function (attributeOwner: CoreAddress) {
await Given.aRequestItemWithARelationshipAttribute({ attributeOwner });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CoreAddress } from "@nmshd/core-types";

export class TestIdentity {
public static readonly SENDER = CoreAddress.from("{{Sender}}");
public static readonly RECIPIENT = CoreAddress.from("{{Recipient}}");
public static readonly CURRENT_IDENTITY = CoreAddress.from("{{CurrentAddress}}");
public static readonly PEER = CoreAddress.from("{{Peer}}");
public static readonly EMPTY = CoreAddress.from("{{Empty}}");
public static readonly UNDEFINED = CoreAddress.from("{{Undefined}}");
public static readonly SOMEONE_ELSE = CoreAddress.from("{{SomeoneElse}}");
Expand Down

0 comments on commit de2c672

Please sign in to comment.