-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
432 additions
and
22 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
56 changes: 56 additions & 0 deletions
56
Tests/FlareTests/UnitTests/Models/PromotionalOfferTests.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,56 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
@testable import Flare | ||
import StoreKit | ||
import XCTest | ||
|
||
// MARK: - PromotionalOfferTests | ||
|
||
final class PromotionalOfferTests: XCTestCase { | ||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) | ||
func test_purchaseOptions() throws { | ||
let option = try PromotionalOffer.SignedData.randomOffer.promotionalOffer | ||
let expected: Product.PurchaseOption = .promotionalOffer( | ||
offerID: PromotionalOffer.SignedData.randomOffer.identifier, | ||
keyID: PromotionalOffer.SignedData.randomOffer.keyIdentifier, | ||
nonce: PromotionalOffer.SignedData.randomOffer.nonce, | ||
signature: Data(), | ||
timestamp: PromotionalOffer.SignedData.randomOffer.timestamp | ||
) | ||
|
||
XCTAssertEqual(expected, option) | ||
} | ||
|
||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) | ||
func test_purchaseOptionWithInvalidSignatureThrows() throws { | ||
do { | ||
_ = try PromotionalOffer.SignedData.invalidOffer.promotionalOffer | ||
} catch { | ||
let error = try XCTUnwrap(error as? IAPError) | ||
XCTAssertEqual(error, IAPError.failedToDecodeSignature(signature: PromotionalOffer.SignedData.invalidOffer.signature)) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Constants | ||
|
||
private extension PromotionalOffer.SignedData { | ||
static let randomOffer: PromotionalOffer.SignedData = .init( | ||
identifier: "identifier \(Int.random(in: 0 ..< 1000))", | ||
keyIdentifier: "key identifier \(Int.random(in: 0 ..< 1000))", | ||
nonce: .init(), | ||
signature: "signature \(Int.random(in: 0 ..< 1000))".asData.base64EncodedString(), | ||
timestamp: Int.random(in: 0 ..< 1000) | ||
) | ||
|
||
static let invalidOffer: PromotionalOffer.SignedData = .init( | ||
identifier: "identifier \(Int.random(in: 0 ..< 1000))", | ||
keyIdentifier: "key identifier \(Int.random(in: 0 ..< 1000))", | ||
nonce: .init(), | ||
signature: "signature \(Int.random(in: 0 ..< 1000))", | ||
timestamp: Int.random(in: 0 ..< 1000) | ||
) | ||
} |
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,8 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
final class StoreProductTests: XCTestCase {} |
12 changes: 12 additions & 0 deletions
12
Tests/FlareTests/UnitTests/TestHelpers/Extensions/String+Data.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,12 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
var asData: Data { | ||
Data(utf8) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
Tests/IntegrationTests/Helpers/Extensions/AsyncSequence+.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,16 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *) | ||
extension AsyncSequence { | ||
/// Returns the elements of the asynchronous sequence. | ||
func extractValues() async rethrows -> [Element] { | ||
try await reduce(into: []) { | ||
$0.append($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
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
Oops, something went wrong.