Skip to content

Commit

Permalink
refactor: renaming RelationshipCreationContents
Browse files Browse the repository at this point in the history
  • Loading branch information
britsta committed Jul 12, 2024
1 parent 7890936 commit a2ea09a
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 128 deletions.
2 changes: 1 addition & 1 deletion packages/enmeshed_types/lib/src/contents/contents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export 'message_content/message_content.dart';
export 'notification.dart';
export 'notification_item/notification_item.dart';
export 'relationship_attribute.dart';
export 'relationship_creation_content/relationship_creation_content.dart';
export 'relationship_creation_content/relationship_creation_content_derivation.dart';
export 'relationship_template_content.dart';
export 'render_hints.dart';
export 'request.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import 'dart:collection';
part of 'relationship_creation_content_derivation.dart';

import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
class RelationshipCreationContent extends RelationshipCreationContentDerivation {
final Response response;

import '../arbitraty_json.dart';
import '../response.dart';
const RelationshipCreationContent({
required this.response,
});

part 'relationship_creation_content_containing_response.dart';
factory RelationshipCreationContent.fromJson(Map json) => RelationshipCreationContent(
response: Response.fromJson(json['response']),
);

abstract class RelationshipCreationContent extends Equatable {
const RelationshipCreationContent();

factory RelationshipCreationContent.fromJson(Map json) {
if (json.containsKey('response')) {
return RelationshipCreationContentContainingResponse.fromJson(json);
}

return ArbitraryRelationshipCreationContent(json);
}

Map<String, dynamic> toJson();

@mustCallSuper
@override
List<Object?> get props;
}

class ArbitraryRelationshipCreationContent extends RelationshipCreationContent with MapMixin<String, dynamic>, ArbitraryJSON {
@override
final Map<String, dynamic> internalJson;

ArbitraryRelationshipCreationContent(Map internalJson) : internalJson = Map<String, dynamic>.from(internalJson);
Map<String, dynamic> toJson() {
return {
'@type': 'RelationshipCreationContent',
'response': response.toJson(),
};
}

@override
List<Object?> get props => [internalJson];
List<Object?> get props => [response];
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:collection';

import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

import '../arbitraty_json.dart';
import '../response.dart';

part 'relationship_creation_content.dart';

abstract class RelationshipCreationContentDerivation extends Equatable {
const RelationshipCreationContentDerivation();

factory RelationshipCreationContentDerivation.fromJson(Map json) {
if (json.containsKey('response')) {
return RelationshipCreationContent.fromJson(json);
}

return ArbitraryRelationshipCreationContent(json);
}

Map<String, dynamic> toJson();

@mustCallSuper
@override
List<Object?> get props;
}

class ArbitraryRelationshipCreationContent extends RelationshipCreationContentDerivation with MapMixin<String, dynamic>, ArbitraryJSON {
@override
final Map<String, dynamic> internalJson;

ArbitraryRelationshipCreationContent(Map internalJson) : internalJson = Map<String, dynamic>.from(internalJson);

@override
List<Object?> get props => [internalJson];
}
6 changes: 3 additions & 3 deletions packages/enmeshed_types/lib/src/dtos/relationship.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:enmeshed_types/src/contents/relationship_creation_content/relationship_creation_content.dart';
import 'package:enmeshed_types/src/contents/relationship_creation_content/relationship_creation_content_derivation.dart';
import 'package:equatable/equatable.dart';

import 'identity.dart';
Expand All @@ -24,7 +24,7 @@ class RelationshipDTO extends Equatable {
final RelationshipStatus status;
final String peer;
final IdentityDTO peerIdentity;
final RelationshipCreationContent creationContent;
final RelationshipCreationContentDerivation creationContent;
final List<RelationshipAuditLogEntryDTO> auditLog;

const RelationshipDTO({
Expand All @@ -43,7 +43,7 @@ class RelationshipDTO extends Equatable {
status: RelationshipStatus.values.byName(json['status']),
peer: json['peer'],
peerIdentity: IdentityDTO.fromJson(json['peerIdentity']),
creationContent: RelationshipCreationContent.fromJson(json['creationContent']),
creationContent: RelationshipCreationContentDerivation.fromJson(json['creationContent']),
auditLog: List<RelationshipAuditLogEntryDTO>.from(json['auditLog'].map((x) => RelationshipAuditLogEntryDTO.fromJson(x))));

Map<String, dynamic> toJson() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RelationshipDVO extends DataViewObject with EquatableMixin {
final String statusText;
final bool isPinned;
final RelationshipTheme? theme;
final RelationshipCreationContent creationContent;
final RelationshipCreationContentDerivation creationContent;
final List<RelationshipAuditLogEntryDTO> auditLog;
final List<LocalAttributeDVO> items;
final Map<String, List<LocalAttributeDVO>> attributeMap;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:enmeshed_types/enmeshed_types.dart';
import 'package:test/test.dart';

void main() {
group('RelationshipCreationContentDerivation fromJson', () {
test('parsed valid RelationshipCreationContent', () {
final relationshipCreationContentJson = {
'@type': 'RelationshipCreationContentDerivation',
'response': const Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: []).toJson(),
};
final relationshipCreationContent = RelationshipCreationContentDerivation.fromJson(relationshipCreationContentJson);
expect(relationshipCreationContent, isA<RelationshipCreationContent>());
});

test('parsed valid ArbitraryRelationshipCreationContent when not given a Response', () {
final arbitraryRelationshipCreationContentJson = {
'@type': 'RelationshipCreationContentDerivation',
'internalJson': 'anInternalJson',
};
final arbitraryRelationshipCreationContent = RelationshipCreationContentDerivation.fromJson(arbitraryRelationshipCreationContentJson);
expect(arbitraryRelationshipCreationContent, isA<ArbitraryRelationshipCreationContent>());
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@ import 'package:enmeshed_types/enmeshed_types.dart';
import 'package:test/test.dart';

void main() {
group('RelationshipCreationContent fromJson', () {
test('parsed valid RelationshipCreationContent', () {
final relationshipCreationContentJson = {
'@type': 'RelationshipCreationContent',
'response': const Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: []).toJson(),
};
final relationshipCreationContent = RelationshipCreationContent.fromJson(relationshipCreationContentJson);
expect(relationshipCreationContent, isA<RelationshipCreationContentContainingResponse>());
group('RelationshipCreationContent toJson', () {
test('is correctly converted', () {
const relationshipCreationContent = RelationshipCreationContent(
response: Response(
result: ResponseResult.Accepted,
requestId: 'aRequestId',
items: [CreateAttributeAcceptResponseItem(attributeId: 'anAttributeId')],
),
);
final relationshipCreationContentJson = relationshipCreationContent.toJson();
expect(
relationshipCreationContentJson,
equals({
'@type': 'RelationshipCreationContent',
'response': const Response(
result: ResponseResult.Accepted,
requestId: 'aRequestId',
items: [CreateAttributeAcceptResponseItem(attributeId: 'anAttributeId')],
).toJson(),
}),
);
});
});

test('parsed valid ArbitraryRelationshipCreationContent when not given a Response', () {
final arbitraryRelationshipCreationContentJson = {
group('RelationshipCreationContent fromJson', () {
test('is correctly converted', () {
final json = {
'@type': 'RelationshipCreationContent',
'internalJson': 'anInternalJson',
'response': const Response(
result: ResponseResult.Accepted,
requestId: 'aRequestId',
items: [CreateAttributeAcceptResponseItem(attributeId: 'anAttributeId')],
).toJson(),
};
final arbitraryRelationshipCreationContent = RelationshipCreationContent.fromJson(arbitraryRelationshipCreationContentJson);
expect(arbitraryRelationshipCreationContent, isA<ArbitraryRelationshipCreationContent>());
expect(
RelationshipCreationContent.fromJson(json),
equals(const RelationshipCreationContent(
response: Response(
result: ResponseResult.Accepted,
requestId: 'aRequestId',
items: [CreateAttributeAcceptResponseItem(attributeId: 'anAttributeId')],
),
)),
);
});
});
}
8 changes: 4 additions & 4 deletions packages/enmeshed_types/test/dtos/relationship_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
status: RelationshipStatus.Active,
peer: 'aPeer',
peerIdentity: IdentityDTO(address: 'anAddress', publicKey: 'aPublicKey'),
creationContent: RelationshipCreationContentContainingResponse(
creationContent: RelationshipCreationContent(
response: Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: [RejectResponseItem()]),
),
auditLog: [
Expand Down Expand Up @@ -74,7 +74,7 @@ void main() {
'status': 'Active',
'peer': 'aPeer',
'peerIdentity': const IdentityDTO(address: 'anAddress', publicKey: 'aPublicKey').toJson(),
'creationContent': const RelationshipCreationContentContainingResponse(
'creationContent': const RelationshipCreationContent(
response: Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: [RejectResponseItem()]),
).toJson(),
'auditLog': [
Expand Down Expand Up @@ -125,7 +125,7 @@ void main() {
'status': 'Active',
'peer': 'aPeer',
'peerIdentity': const IdentityDTO(address: 'anAddress', publicKey: 'aPublicKey').toJson(),
'creationContent': const RelationshipCreationContentContainingResponse(
'creationContent': const RelationshipCreationContent(
response: Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: [RejectResponseItem()]),
).toJson(),
'auditLog': [
Expand Down Expand Up @@ -171,7 +171,7 @@ void main() {
status: RelationshipStatus.Active,
peer: 'aPeer',
peerIdentity: IdentityDTO(address: 'anAddress', publicKey: 'aPublicKey'),
creationContent: RelationshipCreationContentContainingResponse(
creationContent: RelationshipCreationContent(
response: Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: [RejectResponseItem()]),
),
auditLog: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
status: RelationshipStatus.Active,
peer: 'peer',
peerIdentity: const IdentityDTO(address: 'address', publicKey: 'publicKey'),
creationContent: const RelationshipCreationContentContainingResponse(
creationContent: const RelationshipCreationContent(
response: Response(result: ResponseResult.Accepted, requestId: 'aRequestId', items: [RejectResponseItem()]),
),
auditLog: const [
Expand Down

0 comments on commit a2ea09a

Please sign in to comment.