-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update PaymentProvider model and add integration test (#33)
- Loading branch information
Showing
7 changed files
with
155 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Provider.swift | ||
// KarhooSDK | ||
// | ||
// Copyright © 2020 Flit Technologies Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct Provider : KarhooCodableModel { | ||
public let id: String | ||
public let loyaltyProgammes: [LoyaltyProgramme] | ||
|
||
public init(id: String = "", | ||
loyaltyProgammes: [LoyaltyProgramme] = []) { | ||
self.id = id | ||
self.loyaltyProgammes = loyaltyProgammes | ||
} | ||
|
||
public init (from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.id = (try? container.decode(String.self, forKey: .id)) ?? "" | ||
self.loyaltyProgammes = (try? container.decode([LoyaltyProgramme].self, forKey: .loyaltyProgammes)) ?? [] | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case loyaltyProgammes = "loyalty_programmes" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
KarhooSDKIntegrationTests/JSON/Payment/PaymentProvider/PaymentProvider.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"provider": { | ||
"id": "Adyen" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
KarhooSDKIntegrationTests/Service/Payment/PaymentProvider/PaymentProviderSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// PaymentProviderSpec.swift | ||
// KarhooSDKIntegrationTests | ||
// | ||
// Copyright © 2020 Flit Technologies Ltd. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import KarhooSDK | ||
|
||
final class PaymentProviderSpec: XCTestCase { | ||
|
||
private var paymentService: PaymentService! | ||
private let path: String = "/v3/payments/providers" | ||
private var call: Call<PaymentProvider>! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
paymentService = KarhooPaymentService() | ||
|
||
call = paymentService.getPaymentProvider() | ||
} | ||
|
||
/** | ||
* When: Getting the payment provider | ||
* And: The response returns successful | ||
* Then: Result is success | ||
*/ | ||
func testHappyPath() { | ||
NetworkStub.successResponse(jsonFile: "PaymentProvider.json", path: path) | ||
|
||
let expectation = self.expectation(description: "Callback called with succeess") | ||
|
||
call.execute(callback: { result in | ||
XCTAssertEqual("Adyen", result.successValue()?.provider.id) | ||
expectation.fulfill() | ||
}) | ||
|
||
waitForExpectations(timeout: 10) | ||
} | ||
|
||
/** | ||
* When: Getting the payment provider | ||
* And: The response returns error K0001 | ||
* Then: Resulting error value should be a generalRequestError | ||
*/ | ||
func testErrorResponse() { | ||
let expectedError = RawKarhooErrorFactory.buildError(code: "K0001") | ||
|
||
NetworkStub.errorResponse(path: path, responseData: expectedError) | ||
|
||
let expectation = self.expectation(description: "calls callback with error result") | ||
|
||
call.execute(callback: { result in | ||
XCTAssertEqual(.generalRequestError, result.errorValue()!.type) | ||
expectation.fulfill() | ||
}) | ||
|
||
waitForExpectations(timeout: 1) | ||
} | ||
|
||
/** | ||
* When: Getting the payment provider | ||
* And: The response returns time out error | ||
* Then: Result is error | ||
*/ | ||
func testTimeOut() { | ||
NetworkStub.errorResponseTimeOutConnection(path: path) | ||
|
||
let expectation = self.expectation(description: "calls the callback with error") | ||
|
||
call.execute(callback: { result in | ||
XCTAssertFalse(result.isSuccess()) | ||
XCTAssertEqual(.unknownError, result.errorValue()?.type) | ||
expectation.fulfill() | ||
}) | ||
|
||
waitForExpectations(timeout: 1) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters