Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

test: tested pre_gen hook #305

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/very_good_core_hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: very_good_core_hooks

on:
pull_request:
paths:
- ".github/workflows/very_good_core_hooks.yaml"
- "brick/hooks/**"
push:
branches:
- main
paths:
- ".github/workflows/very_good_core_hooks.yaml"
- "brick/hooks/**"

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
with:
working_directory: "brick/hooks"
analyze_directories: "test"
report_on: "pre_gen.dart"
4 changes: 3 additions & 1 deletion brick/hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ dependencies:
mason: ^0.1.0-dev.50

dev_dependencies:
very_good_analysis: ^5.1.0
mocktail: ^1.0.0
test: ^1.19.2
very_good_analysis: ^5.1.0
83 changes: 83 additions & 0 deletions brick/hooks/test/pre_gen_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import '../pre_gen.dart' as pre_gen;

class _MockHookContext extends Mock implements HookContext {}

void main() {
group('pre_gen', () {
late HookContext context;

setUp(() {
context = _MockHookContext();
});

group('application_id_android', () {
test('when specified is unmodified', () {
final vars = <String, String>{
'project_name': 'project_name',
'org_name': 'org_name',
'application_id': 'com.example.app',
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(context.vars['application_id_android'], 'com.example.app');
});

test(
'''when not specified is set to `org_name + "." + project_name(snake_case)`''',
() {
final vars = <String, String>{
'project_name': 'Project Name',
'org_name': 'org_name',
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(
context.vars['application_id_android'],
'org_name.project_name',
);
},
);
});

group('application_id', () {
test('when specified is unmodified', () {
final vars = <String, String>{
'project_name': 'project_name',
'org_name': 'org_name',
'application_id': 'com.example.app',
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(context.vars['application_id'], 'com.example.app');
});

test(
'''when not specified is set to `org_name + "." + project_name(param-case)`''',
() {
final vars = <String, String>{
'project_name': 'Project Name',
'org_name': 'org_name',
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(
context.vars['application_id'],
'org_name.project-name',
);
},
);
});
});
}