Skip to content

Commit

Permalink
Add customer tokens service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-vysotskyi-cko committed Jul 7, 2023
1 parent e3a1ccb commit 2d56353
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Before going further please make sure that you have installed all dependencies s
> ```yml
> projectId: test-proj_K3Ur9LQzcKtm4zttWJ7oAKHgqdiwboAw
> projectPrivateKey: key_test_RE14RLcNikkP5ZXMn84BFYApwotD05Kc
> customerId: cust_dCFEWBwqWrBFYAtkRIpILCynNqfhLQWX
> apiBaseUrl: https://api.processout.com
> checkoutBaseUrl: https://checkout.processout.com
> ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ import XCTest

func test_updateCard() async throws {
// Given
let cardTokenizationRequest = POCardTokenizationRequest(
number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737"
let card = try await sut.tokenize(
request: .init(number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737")
)
let card = try await sut.tokenize(request: cardTokenizationRequest)
let cardUpdateRequest = POCardUpdateRequest(cardId: card.id, cvc: "123")

// When
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// CustomerTokensServiceTests.swift
// ProcessOut
//
// Created by Andrii Vysotskyi on 07.07.2023.
//

import XCTest
@_spi(PO) import ProcessOut

@MainActor final class CustomerTokensServiceTests: XCTestCase {

override func setUp() {
super.setUp()
let configuration = ProcessOutConfiguration.test(
projectId: Constants.projectId,
privateKey: Constants.projectPrivateKey,
apiBaseUrl: URL(string: Constants.apiBaseUrl)!,
checkoutBaseUrl: URL(string: Constants.checkoutBaseUrl)!
)
ProcessOut.configure(configuration: configuration)
sut = ProcessOut.shared.customerTokens
}

// MARK: - Tests

func test_createCustomerToken_returnsToken() async throws {
// Given
let request = POCreateCustomerTokenRequest(customerId: Constants.customerId)

// When
let token = try await sut.createCustomerToken(request: request)

// Then
XCTAssertEqual(token.customerId, request.customerId)
}

func test_assignCustomerToken_whenVerifyIsSetToFalse_assignsNewSource() async throws {
// Given
let card = try await ProcessOut.shared.cards.tokenize(
request: .init(number: "4242424242424242", expMonth: 12, expYear: 40, cvc: "737")
)
let token = try await sut.createCustomerToken(
request: POCreateCustomerTokenRequest(customerId: Constants.customerId)
)
let request = POAssignCustomerTokenRequest(
customerId: Constants.customerId, tokenId: token.id, source: card.id, verify: false
)

// When
let updatedToken = try await sut.assignCustomerToken(request: request, threeDSService: Mock3DSService())

// Then
XCTAssertEqual(updatedToken.cardId, card.id)
}

// MARK: - Private Properties

private var sut: POCustomerTokensService!
}

0 comments on commit 2d56353

Please sign in to comment.