/
entitlement_info_test.dart
116 lines (102 loc) · 4.16 KB
/
entitlement_info_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import 'package:purchases_flutter/entitlement_info_wrapper.dart';
import 'package:test/test.dart';
void main() {
test('unknown period if missing from json', () {
Map<dynamic, dynamic> entitlementInfoJson = {
"identifier": "almost_pro",
"isActive": true,
"willRenew": true,
"latestPurchaseDateMillis": 1.58759855E9,
"latestPurchaseDate": "2020-04-22T23:35:50.000Z",
"originalPurchaseDateMillis": 1.591725245E9,
"originalPurchaseDate": "2020-06-09T17:54:05.000Z",
"expirationDateMillis": null,
"expirationDate": null,
"store": "PLAY_STORE",
"productIdentifier": "consumable",
"isSandbox": true,
"unsubscribeDetectedAt": null,
"unsubscribeDetectedAtMillis": null,
"billingIssueDetectedAt": null,
"billingIssueDetectedAtMillis": null
};
final entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.periodType, PeriodType.unknown);
});
test('unknown store if missing from json', () {
Map<dynamic, dynamic> entitlementInfoJson = {
"identifier": "almost_pro",
"isActive": true,
"willRenew": true,
"periodType": "NORMAL",
"latestPurchaseDateMillis": 1.58759855E9,
"latestPurchaseDate": "2020-04-22T23:35:50.000Z",
"originalPurchaseDateMillis": 1.591725245E9,
"originalPurchaseDate": "2020-06-09T17:54:05.000Z",
"expirationDateMillis": null,
"expirationDate": null,
"productIdentifier": "consumable",
"isSandbox": true,
"unsubscribeDetectedAt": null,
"unsubscribeDetectedAtMillis": null,
"billingIssueDetectedAt": null,
"billingIssueDetectedAtMillis": null
};
final entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.store, Store.unknownStore);
});
test('unknown ownership type if missing from json', () {
Map<dynamic, dynamic> entitlementInfoJson = {
"identifier": "almost_pro",
"isActive": true,
"willRenew": true,
"latestPurchaseDateMillis": 1.58759855E9,
"latestPurchaseDate": "2020-04-22T23:35:50.000Z",
"originalPurchaseDateMillis": 1.591725245E9,
"originalPurchaseDate": "2020-06-09T17:54:05.000Z",
"expirationDateMillis": null,
"expirationDate": null,
"store": "PLAY_STORE",
"productIdentifier": "consumable",
"isSandbox": true,
"unsubscribeDetectedAt": null,
"unsubscribeDetectedAtMillis": null,
"billingIssueDetectedAt": null,
"billingIssueDetectedAtMillis": null
};
final entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.ownershipType, OwnershipType.unknown);
});
test('ownership type parsed from json', () {
Map<dynamic, dynamic> entitlementInfoJson = {
"identifier": "almost_pro",
"isActive": true,
"willRenew": true,
"latestPurchaseDateMillis": 1.58759855E9,
"latestPurchaseDate": "2020-04-22T23:35:50.000Z",
"originalPurchaseDateMillis": 1.591725245E9,
"originalPurchaseDate": "2020-06-09T17:54:05.000Z",
"expirationDateMillis": null,
"expirationDate": null,
"store": "PLAY_STORE",
"productIdentifier": "consumable",
"isSandbox": true,
"unsubscribeDetectedAt": null,
"unsubscribeDetectedAtMillis": null,
"billingIssueDetectedAt": null,
"billingIssueDetectedAtMillis": null
};
entitlementInfoJson["ownershipType"] = "PURCHASED";
var entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.ownershipType, OwnershipType.purchased);
entitlementInfoJson["ownershipType"] = "FAMILY_SHARED";
entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.ownershipType, OwnershipType.familyShared);
entitlementInfoJson["ownershipType"] = "UNKNOWN";
entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.ownershipType, OwnershipType.unknown);
entitlementInfoJson["ownershipType"] = "AN_UNKNOWN_OWNERSHIP_TYPE";
entitlementInfo = EntitlementInfo.fromJson(entitlementInfoJson);
expect(entitlementInfo.ownershipType, OwnershipType.unknown);
});
}