• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

optimizely / optimizely-flutter-sdk / 15421959879

03 Jun 2025 03:50PM CUT coverage: 84.952% (+0.05%) from 84.898%
15421959879

Pull #80

github

web-flow
Merge ebb85f377 into 48c1b5c58
Pull Request #80: [FSSDK-11465] chore: add netspring support

621 of 731 relevant lines covered (84.95%)

1.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.18
/lib/src/data_objects/decide_response.dart
1
/// **************************************************************************
2
/// Copyright 2022, Optimizely, Inc. and contributors                        *
3
///                                                                          *
4
/// Licensed under the Apache License, Version 2.0 (the "License");          *
5
/// you may not use this file except in compliance with the License.         *
6
/// You may obtain a copy of the License at                                  *
7
///                                                                          *
8
///    http://www.apache.org/licenses/LICENSE-2.0                            *
9
///                                                                          *
10
/// Unless required by applicable law or agreed to in writing, software      *
11
/// distributed under the License is distributed on an "AS IS" BASIS,        *
12
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13
/// See the License for the specific language governing permissions and      *
14
/// limitations under the License.                                           *
15
///**************************************************************************/
16

17
import 'dart:convert';
18

19
import 'package:optimizely_flutter_sdk/src/data_objects/base_response.dart';
20
import 'package:optimizely_flutter_sdk/src/utils/constants.dart';
21

22
class Decision {
23
  String variationKey = '';
24
  String flagKey = '';
25
  String ruleKey = '';
26
  bool enabled = false;
27
  Map<String, dynamic> userContext = {};
28
  Map<String, dynamic> variables = {};
29
  List<String> reasons = [];
30

31
  Decision(Map<String, dynamic> json) {
1✔
32
    if (json[Constants.variationKey] is String) {
2✔
33
      variationKey = json[Constants.variationKey];
2✔
34
    }
35
    if (json[Constants.flagKey] is String) {
2✔
36
      flagKey = json[Constants.flagKey];
2✔
37
    }
38
    if (json[Constants.ruleKey] is String) {
2✔
39
      ruleKey = json[Constants.ruleKey];
2✔
40
    }
41
    if (json[Constants.enabled] is bool) {
2✔
42
      enabled = json[Constants.enabled];
2✔
43
    }
44
    if (json[Constants.userContext] is Map<dynamic, dynamic>) {
2✔
45
      Map<String, dynamic> localUserContext =
46
          Map<String, dynamic>.from(json[Constants.userContext]);
2✔
47
      if (localUserContext[Constants.userId] is String) {
2✔
48
        userContext[Constants.userId] = localUserContext[Constants.userId];
3✔
49
      }
50
      if (localUserContext[Constants.attributes] is Map<dynamic, dynamic>) {
2✔
51
        userContext[Constants.attributes] =
2✔
52
            Map<String, dynamic>.from(localUserContext[Constants.attributes]);
2✔
53
      }
54
    }
55

56
    if (json[Constants.variables] is Map<dynamic, dynamic>) {
2✔
57
      variables = Map<String, dynamic>.from(json[Constants.variables]);
3✔
58
    }
59
    if (json[Constants.reasons] is List<dynamic>) {
2✔
60
      reasons = List<String>.from(json[Constants.reasons]);
3✔
61
    }
62
  }
63

64
  @override
×
65
  String toString() {
66
    var encodedVariables = json.encode(variables);
×
67
    var encodedUserContext = json.encode(userContext);
×
68
    var reasonsString = reasons.join(",");
×
69
    return 'Decision {variationKey="$variationKey", enabled="$enabled", variables="$encodedVariables", ruleKey="$ruleKey", flagKey="$flagKey", userContext="$encodedUserContext", reasons="$reasonsString"}';
×
70
  }
71
}
72

73
class BaseDecideResponse extends BaseResponse {
74
  final Map<String, Decision> _decisions = {};
75

76
  BaseDecideResponse(Map<String, dynamic> json) : super(json) {
2✔
77
    if (json[Constants.responseResult] is Map<dynamic, dynamic>) {
2✔
78
      final decisionsMap =
79
          Map<String, dynamic>.from(json[Constants.responseResult]);
2✔
80
      // ignore: unnecessary_set_literal
81
      decisionsMap.forEach((k, v) => {
2✔
82
            if (v is Map<dynamic, dynamic>)
1✔
83
              {_decisions[k] = Decision(Map<String, dynamic>.from(v))}
5✔
84
          });
85
    }
86
  }
87

88
  Map<String, Decision> getDecisions() {
1✔
89
    return _decisions;
1✔
90
  }
91
}
92

93
class DecideResponse extends BaseDecideResponse {
94
  Decision? decision;
95

96
  DecideResponse(Map<String, dynamic> json) : super(json) {
2✔
97
    final decisions = getDecisions();
1✔
98
    if (decisions.isNotEmpty) {
1✔
99
      decision = decisions.values.first;
3✔
100
    }
101
  }
102
}
103

104
class DecideForKeysResponse extends BaseDecideResponse {
105
  Map<String, Decision> decisions = {};
106

107
  DecideForKeysResponse(Map<String, dynamic> json) : super(json) {
2✔
108
    decisions = getDecisions();
2✔
109
  }
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc