Skip to content

Commit

Permalink
add tests, fix build, fix serialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Oct 21, 2024
1 parent e0d0b9d commit d22adc2
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 7 deletions.
31 changes: 31 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
targets:
$default:
builders:
source_gen|combining_builder:
options:
ignore_for_file:
- implicit_dynamic_parameter
- non_constant_identifier_names
- type_annotate_public_apis
- omit_local_variable_types
- unnecessary_this
json_serializable:
options:
any_map: false
create_to_json: true
disallow_unrecognized_keys: false
explicit_to_json: true
# # Options configure how source code is generated for every
# # `@JsonSerializable`-annotated class in the package.
# #
# # The default value for each is listed.
# any_map: false
# checked: false
# create_factory: true
# create_to_json: true
# disallow_unrecognized_keys: false
# explicit_to_json: false
# field_rename: none
# generic_argument_factories: false
# ignore_unannotated: false
# include_if_null: true
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.0.1"
version: "6.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions lib/src/core/model/trait.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ part 'trait.g.dart';

@JsonSerializable()
class Trait {
@JsonKey(includeIfNull: false)
final int? id;
@JsonKey(includeIfNull: false)
final bool? transient;
Expand Down
5 changes: 2 additions & 3 deletions lib/src/core/model/trait.g.dart

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

2 changes: 1 addition & 1 deletion lib/src/flagsmith_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class FlagsmithClient {
cachedUser = user;
var identityData = user.toJson();
if (traits != null && traits.isNotEmpty) {
identityData['traits'] = traits.map((t) => t.toJson());
identityData['traits'] = traits.map((t) => t.toJson()).toList();
}

var response = await _api.post(config.identitiesURI, data: identityData);
Expand Down
96 changes: 96 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.1"
build_config:
dependency: transitive
description:
name: build_config
sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1
url: "https://pub.dev"
source: hosted
version: "1.1.1"
build_daemon:
dependency: transitive
description:
name: build_daemon
sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
build_resolvers:
dependency: transitive
description:
name: build_resolvers
sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
build_runner:
dependency: "direct dev"
description:
name: build_runner
sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d"
url: "https://pub.dev"
source: hosted
version: "2.4.13"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0
url: "https://pub.dev"
source: hosted
version: "7.3.2"
built_collection:
dependency: transitive
description:
Expand All @@ -86,6 +126,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
url: "https://pub.dev"
source: hosted
version: "2.0.3"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -237,6 +285,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
graphs:
dependency: transitive
description:
name: graphs
sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -293,6 +349,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.9.0"
json_serializable:
dependency: "direct dev"
description:
name: json_serializable
sha256: ea1432d167339ea9b5bb153f0571d0039607a873d6e04e0117af043f14a1fd4b
url: "https://pub.dev"
source: hosted
version: "6.8.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -477,6 +541,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
pubspec_parse:
dependency: transitive
description:
name: pubspec_parse
sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8
url: "https://pub.dev"
source: hosted
version: "1.3.0"
rxdart:
dependency: "direct main"
description:
Expand Down Expand Up @@ -586,6 +658,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.0"
source_helper:
dependency: transitive
description:
name: source_helper
sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd"
url: "https://pub.dev"
source: hosted
version: "1.3.4"
source_map_stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -626,6 +706,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
stream_transform:
dependency: transitive
description:
name: stream_transform
sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -674,6 +762,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.2"
timing:
dependency: transitive
description:
name: timing
sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
typed_data:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ dev_dependencies:
http_mock_adapter: ^0.6.1
mockito: ^5.4.2
test_coverage_badge: ^0.3.2
build_runner: ^2.4.13
json_serializable: ^6.8.0
34 changes: 32 additions & 2 deletions test/fg/flagsmith_traits_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,38 @@ void main() {
return server.reply(200, null);
}, data: data.toJson());
});
final result0 = await fs.createTrait(value: data);
expect(result0, isNull);
final result = await fs.createTrait(value: data);
expect(result, isNull);
});

test('When get flags with traits request expected', () async {
var user = Identity(identifier: 'test_another_user');
var traits = [
Trait(key: 'transient_trait', value: 'value', transient: true),
Trait(key: 'normal_trait', value: 'value'),
];
fs = await setupClientAdapter(StorageType.inMemory);
setupEmptyAdapter(fs, cb: (config, adapter) {
adapter.onPost(fs.config.identitiesURI, (server) {
return server.reply(200, jsonDecode(identitiesResponseData));
}, data: jsonDecode(identitiesRequestWithTransientTraitData));
});
final result = await fs.getFeatureFlags(user: user, traits: traits);
expect(result, isNotNull);
expect(result, isNotEmpty);
});

test('When get flags for transient identity request expected', () async {
var user = Identity(identifier: 'test_another_user', transient: true);
fs = await setupClientAdapter(StorageType.inMemory);
setupEmptyAdapter(fs, cb: (config, adapter) {
adapter.onPost(fs.config.identitiesURI, (server) {
return server.reply(200, jsonDecode(identitiesResponseData));
}, data: user.toJson());
});
final result = await fs.getFeatureFlags(user: user);
expect(result, isNotNull);
expect(result, isNotEmpty);
});
});
}
15 changes: 15 additions & 0 deletions test/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,21 @@ final identitiesRequestData = '''{
]
}''';

final identitiesRequestWithTransientTraitData = '''{
"identifier": "test_another_user",
"traits": [
{
"transient": true,
"trait_key": "transient_trait",
"trait_value": "value"
},
{
"trait_key": "normal_trait",
"trait_value": "value"
}
]
}''';

final createTraitRequestData = '''{
"identifier": "test_another_user"
"flags":[
Expand Down

0 comments on commit d22adc2

Please sign in to comment.