Skip to content

Commit 9d00584

Browse files
authored
feat(cat-voices): Tests for validating proposal node ids (#2298)
* feat: add tests * feat: unify document templates, stop using flutter custom templates * fix: docs loading
1 parent df200ea commit 9d00584

File tree

16 files changed

+204
-1523
lines changed

16 files changed

+204
-1523
lines changed

catalyst_voices/Earthfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
VERSION 0.8
22

3+
IMPORT ../ AS repo-ci
34
IMPORT ../catalyst-gateway AS catalyst-gateway
45
IMPORT github.com/input-output-hk/catalyst-ci/earthly/flutter:v3.3.3 AS flutter-ci
56

@@ -9,6 +10,8 @@ repo-catalyst-voices:
910
FROM scratch
1011
WORKDIR /repo
1112
COPY --dir . .
13+
# Copy docs as some doc files are used for test inputs
14+
COPY repo-ci+copy-docs/docs ./docs
1215

1316
SAVE ARTIFACT /repo repo
1417

catalyst_voices/packages/internal/catalyst_voices_assets/assets/document_templates/proposal/F14-Generic/0ce8ab38-9258-4fbc-a62e-7faa6e58318f.schema.json

Lines changed: 0 additions & 1240 deletions
This file was deleted.

catalyst_voices/packages/internal/catalyst_voices_assets/assets/document_templates/proposal/F14-Generic/example.proposal.json

Lines changed: 0 additions & 171 deletions
This file was deleted.

catalyst_voices/packages/internal/catalyst_voices_assets/lib/src/catalyst_voices_assets.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ export 'package:catalyst_voices_assets/src/assets_ext.dart';
55
export 'package:catalyst_voices_assets/src/catalyst_image.dart';
66
export 'package:catalyst_voices_assets/src/catalyst_svg_icon.dart';
77
export 'package:catalyst_voices_assets/src/catalyst_svg_picture.dart';
8-
9-
export 'voices_documents_templates.dart';

catalyst_voices/packages/internal/catalyst_voices_assets/lib/src/voices_documents_templates.dart

Lines changed: 0 additions & 26 deletions
This file was deleted.

catalyst_voices/packages/internal/catalyst_voices_assets/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ flutter:
3030
- assets/icons/
3131
- assets/lottie/
3232
- assets/videos/
33-
- assets/document_templates/proposal/F14-Generic/
3433
fonts:
3534
- family: SF-Pro
3635
fonts:

catalyst_voices/packages/internal/catalyst_voices_assets/test/src/voices_documents_templates_test.dart

Lines changed: 0 additions & 22 deletions
This file was deleted.

catalyst_voices/packages/internal/catalyst_voices_models/lib/src/document/specialized/proposal_document.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ final class ProposalDocument extends Equatable {
2828
DocumentNodeId.fromString('milestones.milestones.milestone_list');
2929
static final tagNodeId = DocumentNodeId.fromString('theme.theme.grouped_tag');
3030

31+
/// A list of all [DocumentNodeId] that are expected to appear
32+
/// in the proposal template schema.
33+
///
34+
/// The app builds custom logic on top of these node ids.
35+
static final allNodeIds = [
36+
titleNodeId,
37+
descriptionNodeId,
38+
requestedFundsNodeId,
39+
durationNodeId,
40+
authorNameNodeId,
41+
categoryNodeId,
42+
categoryDetailsNodeId,
43+
milestonesNodeId,
44+
milestoneListNodeId,
45+
tagNodeId,
46+
];
47+
3148
static const String exportFileExt = 'json';
3249

3350
final ProposalMetadata metadata;

catalyst_voices/packages/internal/catalyst_voices_repositories/test/fixture/comment_template.json

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:collection/collection.dart';
5+
6+
class VoicesDocumentsTemplates {
7+
static final Future<Map<String, dynamic>> proposalF14Schema =
8+
_getJsonAssetFromDocs(
9+
'/src/architecture/08_concepts/document_templates/proposal/F14-Generic/0ce8ab38-9258-4fbc-a62e-7faa6e58318f.schema.json',
10+
);
11+
12+
static final Future<Map<String, dynamic>> proposalF14Document =
13+
_getJsonAssetFromDocs(
14+
'/src/architecture/08_concepts/document_templates/proposal/F14-Generic/example.proposal.json',
15+
);
16+
17+
static final Future<Map<String, dynamic>> commentF14Schema =
18+
_getJsonAssetFromDocs(
19+
'/src/architecture/08_concepts/document_templates/F14-Comments/0b8424d4-ebfd-46e3-9577-1775a69d290c.schema.json',
20+
);
21+
22+
VoicesDocumentsTemplates._();
23+
24+
/// Starting from current dir go upwards until current dir will contain
25+
/// `/docs` folder and return the `/docs` [Directory].
26+
static Future<Directory> _getDocsRoot() async {
27+
var dir = Directory.current;
28+
29+
while (true) {
30+
final list = dir.listSync();
31+
final docs = list.firstWhereOrNull((e) => e.path.endsWith('/docs'));
32+
if (docs != null) {
33+
return Directory(docs.path);
34+
} else {
35+
final parentDir = dir.parent;
36+
if (dir.path == parentDir.path) {
37+
throw StateError(
38+
'Cannot find /docs directory in the repo. '
39+
'Started lookup from ${Directory.current.path}.',
40+
);
41+
} else {
42+
dir = dir.parent;
43+
}
44+
}
45+
}
46+
}
47+
48+
static Future<Map<String, dynamic>> _getJsonAssetFromDocs(String name) async {
49+
final docsRoot = await _getDocsRoot();
50+
final encodedData = await File(docsRoot.path + name).readAsString();
51+
final decodedData = json.decode(encodedData) as Map<String, dynamic>;
52+
return decodedData;
53+
}
54+
}

0 commit comments

Comments
 (0)