Skip to content

Commit

Permalink
Merge pull request #21 from TrustlyInc/dev-233805-implement-the-funct…
Browse files Browse the repository at this point in the history
…ionality-of-being-able-to-choose-webview-or-in-app-browser-in-the-sdk

[DEV-233805] implement the functionality of being able to choose webview or in app browser in the sdk
  • Loading branch information
marcosrivereto authored Dec 17, 2024
2 parents aeab51c + 5cdf2be commit 9d4380b
Show file tree
Hide file tree
Showing 25 changed files with 1,493 additions and 279 deletions.
30 changes: 30 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Description

_(Insert pull request description)_

---

### Relevant Commits

_(List of main updates)_

---

### Requirements

_(Please check if your pull request fulfills the following requirements)_

- [ ] Changes were properly tested (attach evidence if applicable)
- [ ] Repository's code-style/linting compliant

---

### Evidence

_(Insert any evidence related to this pull request. Leave it as **"None"** or **"Not applicable"** if you have nothing to add)_

---

### Additional Information

_(Insert any additional information related to this pull request, as more context or Jira ticket. Leave it as **"None"** or **"Not applicable"** if you have nothing to add)_
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- TrustlySDK (3.2.2)
- TrustlySDK (3.2.3)

DEPENDENCIES:
- TrustlySDK (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
TrustlySDK: 507ad3f6d631c120bf1cfc1ff366060fb7aced7e
TrustlySDK: 63b611ce510c67c2d7e4f1779d163688aea65c39

PODFILE CHECKSUM: 2d88e8d6e29e33aaa64b36a8d0e73ac21b25b6ba

Expand Down
60 changes: 60 additions & 0 deletions Example/Tests/EstablishDataUtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// EstablishDataUtilsTests.swift
// TrustlySDK_Tests
//
// Created by Marcos Rivereto on 15/02/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import XCTest
@testable import TrustlySDK

final class EstablishDataUtilsTests: XCTestCase {

var establishData:Dictionary<String, String> = [:]
var urlWithParamters: String = ""

override func setUp() {
super.setUp()

self.establishData = ["accessId": "A48B73F694C4C8EE6306",
"customer.address.country" : "US",
"customer.address.street" : "ABC Avenue",
"metadata.urlScheme": "demoapp://"]

self.urlWithParamters = "demoapp://?transactionId=1003151780&transactionType=1&merchantReference=g:cac73df7-52b4-47d7-89d3-9628d4cfb65e&payment.paymentProvider.type=1&requestSignature=E0rbmsl4KOORibvsHoDvfqIqlaQ%3D"

}

func testNormalizeDotNotation() throws {

let expectedEstablishData: [String : AnyHashable] = [
"accessId": "A48B73F694C4C8EE6306",
"customer" : ["address": ["country": "US", "street": "ABC Avenue"]],
"metadata" : ["urlScheme": "demoapp://"]
]

let normalizedEstablish = EstablishDataUtils.normalizeEstablishWithDotNotation(establish: self.establishData)

XCTAssertEqual(expectedEstablishData, normalizedEstablish)

}
// TODO: This test was commented, because for now we will not normalize the return
// func testConvertUrlWithParameterToNormalizedEstablish() throws {
//
// let expectedEstablishData: [String : AnyHashable] = [
// "transactionId": "1003151780",
// "transactionType": "1",
// "merchantReference": "g:cac73df7-52b4-47d7-89d3-9628d4cfb65e",
// "payment": ["paymentProvider": ["type" : "1"]],
// "requestSignature": "E0rbmsl4KOORibvsHoDvfqIqlaQ%3D",
// "url": self.urlWithParamters
// ]
//
// let normalizedEstablish = EstablishDataUtils.buildEstablishFrom(urlWithParameters: self.urlWithParamters)
//
// XCTAssertEqual(expectedEstablishData, normalizedEstablish)
//
// }

}
34 changes: 34 additions & 0 deletions Example/Tests/JsonUtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// JsonUtilsTests.swift
// TrustlySDK_Tests
//
// Created by Marcos Rivereto on 08/02/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import XCTest
@testable import TrustlySDK

final class JsonUtilsTests: XCTestCase {

var establishData:Dictionary<String, String> = [:]

override func setUp() {
super.setUp()

self.establishData = ["accessId": "FakeAccessId",
"merchantId" : "8827389273"]

}


func testConvertDictionaryToJsonBase64AndJsonBase64ToDictionary() throws {

let jsonStringBase64 = JSONUtils.getJsonBase64From(dictionary: self.establishData)!
let newDictionary = JSONUtils.getDictionaryFrom(jsonStringBase64: jsonStringBase64)!

XCTAssertEqual(newDictionary, self.establishData)

}

}
137 changes: 137 additions & 0 deletions Example/Tests/NetworkHelperTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// NetworkHelperTests.swift
// TrustlySDK_Tests
//
// Created by Marcos Rivereto on 16/07/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import XCTest
@testable import TrustlySDK

final class NetworkHelperTests: XCTestCase {

override func setUpWithError() throws {
}

override func tearDownWithError() throws {

}

func testThrowsInvalidUrlError() throws {

XCTAssertThrowsError(try buildEnvironment(
resourceUrl: .widget,
environment: "<sandbox>",
localUrl: "",
paymentType: "Retrieval",
build: "3.2.2"
)) { error in
XCTAssertEqual(error as! NetworkError, NetworkError.invalidUrl)
}
}

func testBuildLocalEnvironment() throws {

let environment = try buildEnvironment(
resourceUrl: .widget,
environment: "local",
localUrl: "192.168.0.1",
paymentType: "Retrieval",
build: "3.2.2"
)

let expectedIsLocal = true
let expectedUrl = URL(string: "http://192.168.0.1:8000/start/selectBank/widget?v=3.2.2-ios-sdk")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

func testBuildLocalHostEnvironment() throws {

let environment = try buildEnvironment(
resourceUrl: .widget,
environment: "local",
localUrl: "",
paymentType: "Retrieval",
build: "3.2.2"
)

let expectedIsLocal = true
let expectedUrl = URL(string: "http://localhost:8000/start/selectBank/widget?v=3.2.2-ios-sdk")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

func testBuildLocalHostEnvironmentFrontendPort() throws {

let environment = try buildEnvironment(
resourceUrl: .setup,
environment: "local",
localUrl: "",
paymentType: "Retrieval",
build: "3.2.2",
path: .mobile
)

let expectedIsLocal = true
let expectedUrl = URL(string: "http://localhost:10000/frontend/mobile/setup")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

func testBuildDynamicEnvironment() throws {

let environment = try buildEnvironment(
resourceUrl: .widget,
environment: "dynamic",
localUrl: "trustlyTest",
paymentType: "Retrieval",
build: "3.2.2"
)

let expectedIsLocal = false
let expectedUrl = URL(string: "https://trustlyTest.int.trustly.one/start/selectBank/widget?v=3.2.2-ios-sdk")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

func testBuildSandboxEnvironment() throws {

let environment = try buildEnvironment(
resourceUrl: .widget,
environment: "sandbox",
localUrl: "",
paymentType: "Retrieval",
build: "3.2.2"
)

let expectedIsLocal = false
let expectedUrl = URL(string: "https://sandbox.paywithmybank.com/start/selectBank/widget?v=3.2.2-ios-sdk")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

func testBuildProductionEnvironment() throws {

let environment = try buildEnvironment(
resourceUrl: .widget,
environment: "",
localUrl: "",
paymentType: "Retrieval",
build: "3.2.2"
)

let expectedIsLocal = false
let expectedUrl = URL(string: "https://paywithmybank.com/start/selectBank/widget?v=3.2.2-ios-sdk")!

XCTAssertEqual(expectedIsLocal, environment.isLocal)
XCTAssertEqual(expectedUrl, environment.url)
}

}
Loading

0 comments on commit 9d4380b

Please sign in to comment.