@@ -14,6 +14,7 @@ @interface TranslatorTest : XCTestCase
1414@property (strong , nonatomic ) NSMutableDictionary  *productMap;
1515@property (strong , nonatomic ) NSDictionary  *productResponseMap;
1616@property (strong , nonatomic ) NSDictionary  *paymentMap;
17+ @property (copy , nonatomic ) NSDictionary  *paymentDiscountMap;
1718@property (strong , nonatomic ) NSDictionary  *transactionMap;
1819@property (strong , nonatomic ) NSDictionary  *errorMap;
1920@property (strong , nonatomic ) NSDictionary  *localeMap;
@@ -45,6 +46,9 @@ - (void)setUp {
4546 self.productMap [@" subscriptionPeriod"  ] = self.periodMap ;
4647 self.productMap [@" introductoryPrice"  ] = self.discountMap ;
4748 }
49+  if  (@available (iOS 12.2 , *)) {
50+  self.productMap [@" discounts"  ] = @[ self .discountMap ];
51+  }
4852
4953 if  (@available (iOS 12.0 , *)) {
5054 self.productMap [@" subscriptionGroupIdentifier"  ] = @" com.group"  ;
@@ -59,6 +63,13 @@ - (void)setUp {
5963 @" applicationUsername"   : @" app user name"  ,
6064 @" simulatesAskToBuyInSandbox"   : @(NO )
6165 };
66+  self.paymentDiscountMap  = @{
67+  @" identifier"   : @" payment_discount_identifier"  ,
68+  @" keyIdentifier"   : @" payment_discount_key_identifier"  ,
69+  @" nonce"   : @" d18981e0-9003-4365-98a2-4b90e3b62c52"  ,
70+  @" signature"   : @" this is a encrypted signature"  ,
71+  @" timestamp"   : @([NSDate  date ].timeIntervalSince1970 ),
72+  };
6273 NSDictionary  *originalTransactionMap = @{
6374 @" transactionIdentifier"   : @" 567"  ,
6475 @" transactionState"   : @(SKPaymentTransactionStatePurchasing),
@@ -175,4 +186,134 @@ - (void)testSKStorefrontAndSKPaymentTransactionToMap {
175186 }
176187}
177188
189+ - (void )testSKPaymentDiscountFromMap  {
190+  if  (@available (iOS 12.2 , *)) {
191+  NSString  *error = nil ;
192+  SKPaymentDiscount *paymentDiscount =
193+  [FIAObjectTranslator getSKPaymentDiscountFromMap: self .paymentDiscountMap withError: &error];
194+ 
195+  XCTAssertEqual (paymentDiscount.identifier , self.paymentDiscountMap [@" identifier"  ]);
196+  XCTAssertEqual (paymentDiscount.keyIdentifier , self.paymentDiscountMap [@" keyIdentifier"  ]);
197+  XCTAssertEqualObjects (paymentDiscount.nonce ,
198+  [[NSUUID  alloc ] initWithUUIDString: self .paymentDiscountMap[@" nonce"  ]]);
199+  XCTAssertEqual (paymentDiscount.signature , self.paymentDiscountMap [@" signature"  ]);
200+  XCTAssertEqual (paymentDiscount.timestamp , self.paymentDiscountMap [@" timestamp"  ]);
201+  }
202+ }
203+ 
204+ - (void )testSKPaymentDiscountFromMapMissingIdentifier  {
205+  if  (@available (iOS 12.2 , *)) {
206+  NSArray  *invalidValues = @[ [NSNull  null ], @(1 ), @" "   ];
207+ 
208+  for  (id  value in invalidValues) {
209+  NSDictionary  *discountMap = @{
210+  @" identifier"   : value,
211+  @" keyIdentifier"   : @" payment_discount_key_identifier"  ,
212+  @" nonce"   : @" d18981e0-9003-4365-98a2-4b90e3b62c52"  ,
213+  @" signature"   : @" this is a encrypted signature"  ,
214+  @" timestamp"   : @([NSDate  date ].timeIntervalSince1970 ),
215+  };
216+ 
217+  NSString  *error = nil ;
218+  [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
219+ 
220+  XCTAssertNotNil (error);
221+  XCTAssertEqualObjects (
222+  error, @" When specifying a payment discount the 'identifier' field is mandatory."  );
223+  }
224+  }
225+ }
226+ 
227+ - (void )testSKPaymentDiscountFromMapMissingKeyIdentifier  {
228+  if  (@available (iOS 12.2 , *)) {
229+  NSArray  *invalidValues = @[ [NSNull  null ], @(1 ), @" "   ];
230+ 
231+  for  (id  value in invalidValues) {
232+  NSDictionary  *discountMap = @{
233+  @" identifier"   : @" payment_discount_identifier"  ,
234+  @" keyIdentifier"   : value,
235+  @" nonce"   : @" d18981e0-9003-4365-98a2-4b90e3b62c52"  ,
236+  @" signature"   : @" this is a encrypted signature"  ,
237+  @" timestamp"   : @([NSDate  date ].timeIntervalSince1970 ),
238+  };
239+ 
240+  NSString  *error = nil ;
241+  [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
242+ 
243+  XCTAssertNotNil (error);
244+  XCTAssertEqualObjects (
245+  error, @" When specifying a payment discount the 'keyIdentifier' field is mandatory."  );
246+  }
247+  }
248+ }
249+ 
250+ - (void )testSKPaymentDiscountFromMapMissingNonce  {
251+  if  (@available (iOS 12.2 , *)) {
252+  NSArray  *invalidValues = @[ [NSNull  null ], @(1 ), @" "   ];
253+ 
254+  for  (id  value in invalidValues) {
255+  NSDictionary  *discountMap = @{
256+  @" identifier"   : @" payment_discount_identifier"  ,
257+  @" keyIdentifier"   : @" payment_discount_key_identifier"  ,
258+  @" nonce"   : value,
259+  @" signature"   : @" this is a encrypted signature"  ,
260+  @" timestamp"   : @([NSDate  date ].timeIntervalSince1970 ),
261+  };
262+ 
263+  NSString  *error = nil ;
264+  [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
265+ 
266+  XCTAssertNotNil (error);
267+  XCTAssertEqualObjects (error,
268+  @" When specifying a payment discount the 'nonce' field is mandatory."  );
269+  }
270+  }
271+ }
272+ 
273+ - (void )testSKPaymentDiscountFromMapMissingSignature  {
274+  if  (@available (iOS 12.2 , *)) {
275+  NSArray  *invalidValues = @[ [NSNull  null ], @(1 ), @" "   ];
276+ 
277+  for  (id  value in invalidValues) {
278+  NSDictionary  *discountMap = @{
279+  @" identifier"   : @" payment_discount_identifier"  ,
280+  @" keyIdentifier"   : @" payment_discount_key_identifier"  ,
281+  @" nonce"   : @" d18981e0-9003-4365-98a2-4b90e3b62c52"  ,
282+  @" signature"   : value,
283+  @" timestamp"   : @([NSDate  date ].timeIntervalSince1970 ),
284+  };
285+ 
286+  NSString  *error = nil ;
287+  [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
288+ 
289+  XCTAssertNotNil (error);
290+  XCTAssertEqualObjects (
291+  error, @" When specifying a payment discount the 'signature' field is mandatory."  );
292+  }
293+  }
294+ }
295+ 
296+ - (void )testSKPaymentDiscountFromMapMissingTimestamp  {
297+  if  (@available (iOS 12.2 , *)) {
298+  NSArray  *invalidValues = @[ [NSNull  null ], @" "  , @(-1 ) ];
299+ 
300+  for  (id  value in invalidValues) {
301+  NSDictionary  *discountMap = @{
302+  @" identifier"   : @" payment_discount_identifier"  ,
303+  @" keyIdentifier"   : @" payment_discount_key_identifier"  ,
304+  @" nonce"   : @" d18981e0-9003-4365-98a2-4b90e3b62c52"  ,
305+  @" signature"   : @" this is a encrypted signature"  ,
306+  @" timestamp"   : value,
307+  };
308+ 
309+  NSString  *error = nil ;
310+  [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
311+ 
312+  XCTAssertNotNil (error);
313+  XCTAssertEqualObjects (
314+  error, @" When specifying a payment discount the 'timestamp' field is mandatory."  );
315+  }
316+  }
317+ }
318+ 
178319@end 
0 commit comments