|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter_test/flutter_test.dart'; |
| 6 | +import 'package:in_app_purchase/in_app_purchase.dart'; |
| 7 | +import 'package:in_app_purchase/src/store_kit_wrappers/sk_product_wrapper.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('Constructor Tests', () { |
| 11 | + test( |
| 12 | + 'fromSkProduct should correctly parse data from a SKProductWrapper instance.', |
| 13 | + () { |
| 14 | + final SKProductWrapper dummyProductWrapper = SKProductWrapper( |
| 15 | + productIdentifier: 'id', |
| 16 | + localizedTitle: 'title', |
| 17 | + localizedDescription: 'description', |
| 18 | + priceLocale: |
| 19 | + SKPriceLocaleWrapper(currencySymbol: '\$', currencyCode: 'USD'), |
| 20 | + subscriptionGroupIdentifier: 'com.group', |
| 21 | + price: '13.37', |
| 22 | + ); |
| 23 | + |
| 24 | + ProductDetails productDetails = |
| 25 | + ProductDetails.fromSKProduct(dummyProductWrapper); |
| 26 | + expect(productDetails.id, equals(dummyProductWrapper.productIdentifier)); |
| 27 | + expect(productDetails.title, equals(dummyProductWrapper.localizedTitle)); |
| 28 | + expect(productDetails.description, |
| 29 | + equals(dummyProductWrapper.localizedDescription)); |
| 30 | + expect(productDetails.rawPrice, equals(13.37)); |
| 31 | + expect(productDetails.currencyCode, |
| 32 | + equals(dummyProductWrapper.priceLocale.currencyCode)); |
| 33 | + expect(productDetails.skProduct, equals(dummyProductWrapper)); |
| 34 | + expect(productDetails.skuDetail, isNull); |
| 35 | + }); |
| 36 | + |
| 37 | + test( |
| 38 | + 'fromSkuDetails should correctly parse data from a SkuDetailsWrapper instance', |
| 39 | + () { |
| 40 | + final SkuDetailsWrapper dummyDetailWrapper = SkuDetailsWrapper( |
| 41 | + description: 'description', |
| 42 | + freeTrialPeriod: 'freeTrialPeriod', |
| 43 | + introductoryPrice: 'introductoryPrice', |
| 44 | + introductoryPriceMicros: 'introductoryPriceMicros', |
| 45 | + introductoryPriceCycles: 1, |
| 46 | + introductoryPricePeriod: 'introductoryPricePeriod', |
| 47 | + price: '13.37', |
| 48 | + priceAmountMicros: 13370000, |
| 49 | + priceCurrencyCode: 'usd', |
| 50 | + sku: 'sku', |
| 51 | + subscriptionPeriod: 'subscriptionPeriod', |
| 52 | + title: 'title', |
| 53 | + type: SkuType.inapp, |
| 54 | + originalPrice: 'originalPrice', |
| 55 | + originalPriceAmountMicros: 1000, |
| 56 | + ); |
| 57 | + |
| 58 | + ProductDetails productDetails = |
| 59 | + ProductDetails.fromSkuDetails(dummyDetailWrapper); |
| 60 | + expect(productDetails.id, equals(dummyDetailWrapper.sku)); |
| 61 | + expect(productDetails.title, equals(dummyDetailWrapper.title)); |
| 62 | + expect( |
| 63 | + productDetails.description, equals(dummyDetailWrapper.description)); |
| 64 | + expect(productDetails.price, equals(dummyDetailWrapper.price)); |
| 65 | + expect(productDetails.rawPrice, equals(13.37)); |
| 66 | + expect(productDetails.currencyCode, |
| 67 | + equals(dummyDetailWrapper.priceCurrencyCode)); |
| 68 | + expect(productDetails.skProduct, isNull); |
| 69 | + expect(productDetails.skuDetail, equals(dummyDetailWrapper)); |
| 70 | + }); |
| 71 | + }); |
| 72 | +} |
0 commit comments