Skip to content

Commit 3be9893

Browse files
brief factory test
1 parent 625a4a3 commit 3be9893

File tree

3 files changed

+123
-7
lines changed

3 files changed

+123
-7
lines changed

catalyst_voices/packages/internal/catalyst_voices_dev/lib/src/catalyst_voices_models/document/document_data_factory.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@ import 'package:catalyst_voices_models/catalyst_voices_models.dart' hide Documen
33

44
abstract final class DocumentDataFactory {
55
static DocumentData build({
6-
DocumentContentType contentType = DocumentContentType.json,
76
DocumentType type = DocumentType.proposalDocument,
87
DocumentRef? id,
8+
SignedDocumentRef? ref,
99
SignedDocumentRef? template,
10+
List<CatalystId>? collaborators,
1011
DocumentParameters parameters = const DocumentParameters(),
11-
DocumentDataContent content = const DocumentDataContent({}),
12+
List<CatalystId>? authors,
13+
DocumentContentType contentType = DocumentContentType.json,
14+
Map<String, dynamic> contentData = const {},
1215
}) {
1316
return DocumentData(
1417
metadata: DocumentDataMetadata(
1518
contentType: contentType,
1619
type: type,
1720
id: id ?? DocumentRefFactory.signedDocumentRef(),
21+
ref: ref,
1822
template: template,
23+
collaborators: collaborators,
1924
parameters: parameters,
25+
authors: authors,
2026
),
21-
content: content,
27+
content: DocumentDataContent(contentData),
2228
);
2329
}
2430
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import 'package:catalyst_voices_dev/catalyst_voices_dev.dart';
2+
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
void main() {
6+
group(ProposalBriefData, () {
7+
group('build', () {
8+
test('basic raw data is mapped correctly', () {
9+
// Given
10+
final id = DocumentRefFactory.signedDocumentRef();
11+
final author = CatalystIdFactory.create();
12+
const title = 'Test Proposal';
13+
14+
final rawProposal = RawProposalBrief(
15+
proposal: DocumentDataFactory.build(
16+
id: id,
17+
authors: [author],
18+
contentData: {
19+
'setup': {
20+
'title': {'title': title},
21+
},
22+
},
23+
),
24+
template: null,
25+
actionType: ProposalSubmissionAction.aFinal,
26+
versionIds: [
27+
id.ver!,
28+
DocumentRefFactory.randomUuidV7(),
29+
DocumentRefFactory.randomUuidV7(),
30+
],
31+
commentsCount: 10,
32+
isFavorite: true,
33+
originalAuthors: [author],
34+
);
35+
final proposalOrDocument = ProposalOrDocument.data(rawProposal.proposal);
36+
37+
// When
38+
final brief = ProposalBriefData.build(
39+
data: rawProposal,
40+
proposal: proposalOrDocument,
41+
);
42+
43+
// Then
44+
expect(brief.id, rawProposal.proposal.id);
45+
expect(brief.author, author);
46+
expect(brief.title, title);
47+
expect(brief.isFinal, isTrue);
48+
expect(brief.isFavorite, isTrue);
49+
expect(brief.iteration, 1);
50+
expect(brief.commentsCount, isNull);
51+
expect(brief.versions?.length, 3);
52+
expect(brief.collaborators?.first.id, isNull);
53+
});
54+
55+
test('collaborators actions are mapped correctly', () {
56+
// Given
57+
final id = DocumentRefFactory.signedDocumentRef();
58+
final author = CatalystIdFactory.create(username: 'Author');
59+
final collaboratorA = CatalystIdFactory.create(username: 'CollabA', role0KeySeed: 1);
60+
final collaboratorB = CatalystIdFactory.create(username: 'CollabB', role0KeySeed: 2);
61+
final collaboratorAAction = RawCollaboratorAction(
62+
id: collaboratorA,
63+
proposalId: id,
64+
action: ProposalSubmissionAction.draft,
65+
);
66+
final collaboratorBAction = RawCollaboratorAction(
67+
id: collaboratorB,
68+
proposalId: id,
69+
action: ProposalSubmissionAction.hide,
70+
);
71+
72+
final collaboratorsActions = {
73+
collaboratorA.toSignificant(): collaboratorAAction,
74+
collaboratorB.toSignificant(): collaboratorBAction,
75+
};
76+
77+
final rawProposal = RawProposalBrief(
78+
proposal: DocumentDataFactory.build(
79+
id: id,
80+
authors: [author],
81+
collaborators: [collaboratorA, collaboratorB],
82+
),
83+
template: null,
84+
actionType: ProposalSubmissionAction.draft,
85+
versionIds: [id.ver!],
86+
commentsCount: 0,
87+
isFavorite: false,
88+
originalAuthors: [author],
89+
);
90+
final proposalOrDocument = ProposalOrDocument.data(rawProposal.proposal);
91+
92+
// When
93+
final brief = ProposalBriefData.build(
94+
data: rawProposal,
95+
proposal: proposalOrDocument,
96+
collaboratorsActions: collaboratorsActions,
97+
);
98+
99+
// Then
100+
expect(brief.collaborators, hasLength(2));
101+
102+
final collabA = brief.collaborators!.firstWhere((element) => element.id == collaboratorA);
103+
final collabB = brief.collaborators!.firstWhere((element) => element.id == collaboratorB);
104+
105+
expect(collabA.status, ProposalsCollaborationStatus.accepted);
106+
expect(collabB.status, ProposalsCollaborationStatus.rejected);
107+
});
108+
});
109+
});
110+
}

catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/document_repository_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ void main() {
5757
final template = DocumentDataFactory.build(
5858
id: templateRef,
5959
type: DocumentType.proposalTemplate,
60-
content: DocumentDataContent(templateData),
60+
contentData: templateData,
6161
);
6262
final proposal = DocumentDataFactory.build(
6363
id: SignedDocumentRef.first(DocumentRefFactory.randomUuidV7()),
6464
template: templateRef,
65-
content: DocumentDataContent(proposalData),
65+
contentData: proposalData,
6666
);
6767

6868
when(
@@ -316,7 +316,7 @@ void main() {
316316
final updatedData = DocumentDataFactory.build(
317317
id: draftRef,
318318
template: templateRef,
319-
content: updatedContent,
319+
contentData: updatedContent.data,
320320
);
321321

322322
// When
@@ -361,7 +361,7 @@ void main() {
361361
id: publicDraftRef,
362362
template: templateRef,
363363
parameters: DocumentParameters({DocumentRefFactory.signedDocumentRef()}),
364-
content: publicDraftContent,
364+
contentData: publicDraftContent.data,
365365
);
366366

367367
await localDocuments.save(data: templateData);

0 commit comments

Comments
 (0)