@@ -188,8 +188,9 @@ - (void)testSKStorefrontAndSKPaymentTransactionToMap {
188188
189189- (void )testSKPaymentDiscountFromMap {
190190 if (@available (iOS 12.2 , *)) {
191+ NSString *error = nil ;
191192 SKPaymentDiscount *paymentDiscount =
192- [FIAObjectTranslator getSKPaymentDiscountFromMap: self .paymentDiscountMap];
193+ [FIAObjectTranslator getSKPaymentDiscountFromMap: self .paymentDiscountMap withError: &error ];
193194
194195 XCTAssertEqual (paymentDiscount.identifier , self.paymentDiscountMap [@" identifier" ]);
195196 XCTAssertEqual (paymentDiscount.keyIdentifier , self.paymentDiscountMap [@" keyIdentifier" ]);
@@ -202,66 +203,111 @@ - (void)testSKPaymentDiscountFromMap {
202203
203204- (void )testSKPaymentDiscountFromMapMissingIdentifier {
204205 if (@available (iOS 12.2 , *)) {
205- NSDictionary *discountMap = @{
206- @" keyIdentifier" : @" payment_discount_key_identifier" ,
207- @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
208- @" signature" : @" this is a encrypted signature" ,
209- @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
210- };
211-
212- XCTAssertThrows ([FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap]);
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 (error, @" When specifying a payment discount the 'identifier' field is mandatory." );
222+ }
213223 }
214224}
215225
216226- (void )testSKPaymentDiscountFromMapMissingKeyIdentifier {
217227 if (@available (iOS 12.2 , *)) {
218- NSDictionary *discountMap = @{
219- @" identifier" : @" payment_discount_identifier" ,
220- @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
221- @" signature" : @" this is a encrypted signature" ,
222- @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
223- };
224-
225- XCTAssertThrows ([FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap]);
228+ NSArray * invalidValues = @[[NSNull null ], @(1 ), @" " ];
229+
230+ for (id value in invalidValues) {
231+ NSDictionary *discountMap = @{
232+ @" identifier" : @" payment_discount_identifier" ,
233+ @" keyIdentifier" : value,
234+ @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
235+ @" signature" : @" this is a encrypted signature" ,
236+ @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
237+ };
238+
239+ NSString *error = nil ;
240+ [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
241+
242+ XCTAssertNotNil (error);
243+ XCTAssertEqualObjects (error, @" When specifying a payment discount the 'keyIdentifier' field is mandatory." );
244+ }
226245 }
227246}
228247
229248- (void )testSKPaymentDiscountFromMapMissingNonce {
230249 if (@available (iOS 12.2 , *)) {
231- NSDictionary *discountMap = @{
232- @" identifier" : @" payment_discount_identifier" ,
233- @" keyIdentifier" : @" payment_discount_key_identifier" ,
234- @" signature" : @" this is a encrypted signature" ,
235- @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
236- };
237-
238- XCTAssertThrows ([FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap]);
250+ NSArray * invalidValues = @[[NSNull null ], @(1 ), @" " ];
251+
252+ for (id value in invalidValues) {
253+ NSDictionary *discountMap = @{
254+ @" identifier" : @" payment_discount_identifier" ,
255+ @" keyIdentifier" : @" payment_discount_key_identifier" ,
256+ @" nonce" : value,
257+ @" signature" : @" this is a encrypted signature" ,
258+ @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
259+ };
260+
261+ NSString *error = nil ;
262+ [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
263+
264+ XCTAssertNotNil (error);
265+ XCTAssertEqualObjects (error, @" When specifying a payment discount the 'nonce' field is mandatory." );
266+ }
239267 }
240268}
241269
242270- (void )testSKPaymentDiscountFromMapMissingSignature {
243271 if (@available (iOS 12.2 , *)) {
244- NSDictionary *discountMap = @{
245- @" identifier" : @" payment_discount_identifier" ,
246- @" keyIdentifier" : @" payment_discount_key_identifier" ,
247- @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
248- @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
249- };
250-
251- XCTAssertThrows ([FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap]);
272+ NSArray * invalidValues = @[[NSNull null ], @(1 ), @" " ];
273+
274+ for (id value in invalidValues) {
275+ NSDictionary *discountMap = @{
276+ @" identifier" : @" payment_discount_identifier" ,
277+ @" keyIdentifier" : @" payment_discount_key_identifier" ,
278+ @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
279+ @" signature" : value,
280+ @" timestamp" : @([NSDate date ].timeIntervalSince1970 ),
281+ };
282+
283+ NSString *error = nil ;
284+ [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
285+
286+ XCTAssertNotNil (error);
287+ XCTAssertEqualObjects (error, @" When specifying a payment discount the 'signature' field is mandatory." );
288+ }
252289 }
253290}
254291
255292- (void )testSKPaymentDiscountFromMapMissingTimestamp {
256293 if (@available (iOS 12.2 , *)) {
257- NSDictionary *discountMap = @{
258- @" identifier" : @" payment_discount_identifier" ,
259- @" keyIdentifier" : @" payment_discount_key_identifier" ,
260- @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
261- @" signature" : @" this is a encrypted signature" ,
262- };
263-
264- XCTAssertThrows ([FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap]);
294+ NSArray * invalidValues = @[[NSNull null ], @" " , @(-1 )];
295+
296+ for (id value in invalidValues) {
297+ NSDictionary *discountMap = @{
298+ @" identifier" : @" payment_discount_identifier" ,
299+ @" keyIdentifier" : @" payment_discount_key_identifier" ,
300+ @" nonce" : @" d18981e0-9003-4365-98a2-4b90e3b62c52" ,
301+ @" signature" : @" this is a encrypted signature" ,
302+ @" timestamp" : value,
303+ };
304+
305+ NSString *error = nil ;
306+ [FIAObjectTranslator getSKPaymentDiscountFromMap: discountMap withError: &error];
307+
308+ XCTAssertNotNil (error);
309+ XCTAssertEqualObjects (error, @" When specifying a payment discount the 'timestamp' field is mandatory." );
310+ }
265311 }
266312}
267313
0 commit comments