Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKPass file stub support #209

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Example/SBTUITestTunnel_Tests/StubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class StubTests: XCTestCase {
let headers = result["responseHeaders"] as! [String: String]
XCTAssert(request.headers(headers, isEqual: expectedHeaders))
}

func testStubPKPassContentType() {
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org"), response: SBTStubResponse(fileNamed: "test_file.pkpass"))

let expectedHeaders = ["Content-Type": "application/vnd.apple.pkpass"]

let result = request.dataTaskNetwork(urlString: "https://httpbin.org/get?param1=val1&param2=val2")
let headers = result["responseHeaders"] as! [String: String]
XCTAssert(request.headers(headers, isEqual: expectedHeaders))
}

func testStubTextContentType() {
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org"), response: SBTStubResponse(response: "stubbed text"))
Expand Down
1 change: 1 addition & 0 deletions Example/SBTUITestTunnel_Tests/test_file.pkpass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hello":"there"}
5 changes: 4 additions & 1 deletion Sources/SBTUITestTunnelCommon/SBTStubResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
NSString * const SBTResponseContentTypeData = @"application/octet-stream";
NSString * const SBTResponseContentTypeHtml = @"text/html";
NSString * const SBTResponseContentTypePdf = @"application/pdf";
NSString * const SBTResponseContentPKPass = @"application/vnd.apple.pkpass";

@interface SBTResponseDefaults: NSObject
@property (nonatomic, assign) NSTimeInterval responseTime;
Expand Down Expand Up @@ -160,8 +161,10 @@ - (instancetype)initWithFileNamed:(NSString *)fileNamed
contentType = SBTResponseContentTypeHtml;
} else if ([loweredStubExtension isEqualToString:@"pdf"]) {
contentType = SBTResponseContentTypePdf;
} else if ([loweredStubExtension isEqualToString:@"pkpass"]){
contentType = SBTResponseContentPKPass;
} else {
NSAssert(NO, @"Unsupported file extension. Expecting json, xml, txt, htm, html, pdf");
NSAssert(NO, @"Unsupported file extension. Expecting json, xml, txt, htm, html, pdf, pkpass");
}

return [self initWithResponse:stubData headers:headers contentType:contentType returnCode:returnCode responseTime:responseTime activeIterations:activeIterations];
Expand Down
Loading