Skip to content

Commit

Permalink
Update Vendor object + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmerlet-at-didomi committed Feb 22, 2024
1 parent 9152495 commit bda25cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions example/integration_test/vendor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void main() {
assert(isReady == false);
});

testWidgets("Get a vendor name without initialization", (WidgetTester tester) async {
testWidgets("Get a vendor info without initialization", (WidgetTester tester) async {
// Start app
app.main();
await tester.pumpAndSettle();
Expand Down Expand Up @@ -145,7 +145,7 @@ void main() {
assert(isReady == true);
});

testWidgets("Get a vendor name with initialization", (WidgetTester tester) async {
testWidgets("Get a vendor info with initialization", (WidgetTester tester) async {
// Start app
app.main();
await tester.pumpAndSettle();
Expand All @@ -164,7 +164,8 @@ void main() {
await tester.tap(getVendorBtnFinder);
await tester.pumpAndSettle();

final expected = "Native message: Vendor: 152 Media LLC.";
final expected = "Native message: Vendor: 2KDirect, Inc. (dba iPromote). "
"Purposes: 3 consent, 4 LI, 0 features, 2 special purposes, 0 special features.";
assertNativeMessage("getVendor", expected);

assert(isError == false);
Expand Down
6 changes: 4 additions & 2 deletions example/lib/widgets/get_vendor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class _GetVendorState

@override
Future<String> callDidomiPlugin() async {
final Vendor? result = await DidomiSdk.getVendor("1111");
final Vendor? result = await DidomiSdk.getVendor("217");

if (result == null) {
return "Vendor does not exist.";
} else {
return "Vendor: ${result.name}.";
return "Vendor: ${result.name}. Purposes: ${result.purposeIds.length} consent, "
"${result.legIntPurposeIds.length} LI, ${result.featureIds.length} features, "
"${result.specialPurposeIds.length} special purposes, ${result.specialFeatureIds.length} special features.";
}
}
}
14 changes: 6 additions & 8 deletions lib/entities/vendor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ class Vendor implements Comparable<Vendor> {
this.specialFeatureIds,
this.urls);

// When parsing a Vendor, we need to consider that some properties are parsed differently on Android and iOS,
// mainly because TCFv1 used properties such as purposeIds and TCFv2 uses properties such as purposes.
Vendor.fromJson(dynamic json)
: id = json["id"],
name = json["name"],
policyUrl = json["policyUrl"],
namespaces = json["namespaces"]?.cast<Namespaces>(),
purposeIds = (json["purposeIds"] ?? json["purposes"]).cast<String>(),
legIntPurposeIds = (json["legIntPurposeIds"] ?? json["legIntPurposes"]).cast<String>(),
featureIds = (json["featureIds"] ?? json["features"]).cast<String>(),
flexiblePurposeIds = (json["flexiblePurposeIds"] ?? json["flexiblePurposes"]).cast<String>(),
specialPurposeIds = (json["specialPurposeIds"] ?? json["specialPurposes"]).cast<String>(),
specialFeatureIds = (json["specialFeatureIds"] ?? json["specialFeatures"]).cast<String>(),
purposeIds = json["purposeIds"].cast<String>(),
legIntPurposeIds = json["legIntPurposeIds"].cast<String>(),
featureIds = json["featureIds"].cast<String>(),
flexiblePurposeIds = json["flexiblePurposeIds"].cast<String>(),
specialPurposeIds = json["specialPurposeIds"].cast<String>(),
specialFeatureIds = json["specialFeatureIds"].cast<String>(),
urls = json["urls"]?.cast<Url>();

@override
Expand Down

0 comments on commit bda25cb

Please sign in to comment.