⚠️ Make sure all Unit Tests are implemented. I will carefully check it 👍
⚠️ Please use the correct JSON data. You can capture it from httpbin.org or producthunt.com. Don't create a fake Unit Test Data, for example:
HTTP/1.1 200 OK
asdsa: asdsad
ASdsad: adsad
{":sdasd": 132}
Unit Test Strategy
Start the Proxy Server
Create a flow
Create a Map Local from a flow
At this step, we can try to change the Status Code, header or the body of the Raw Message of the Map Local
Make a real request
Assert if the body is exactly the Response that we've updated ✅
Reference Unit Test:
func testMapLocalFile_MapDefaultFile() throws {
let jsonExpected = "{\n \"status\": \"ok\"\n}"
// Start the Proxyman Proxy Server
core = PMProxyServer.allwaysInterceptCore()
runProxyCore { (expectation) in
// Create a flow
let url = "https://httpbin.org/post"
let body: [String: Any] = ["name": "Original Proxyman",
"country": 123,
"code": "VN"]
let flow = FlowFactory.flowWithJSON()
// Create a Map Local Rule from a given Flow
let entry = try! MapLocalFactory.buildMapLocal(flow: flow)
// insert it
MapLocalService.shared.insert(entry: entry, atNode: nil)
// Use Networking library to make a call
self.manager.request(url, method: .post, parameters: body, encoding: JSONEncoding(), headers: nil).responseJSON { response in
let header = response.response?.allHeaderFields["X-Proxyman-Map-Local"] as? String
XCTAssertNotNil(header)
XCTAssertTrue(header!.hasPrefix("Serve from file:"))
// Verify the JSON
XCTAssertEqual(jsonExpected, String(data: response.data!, encoding: .utf8))
expectation.fulfill()
}
}
}
Unit Test for MapLocalService
1. Map with the default HTTP Message file
Input: Create a Map Local with a default HTTP
Expected: A flow is matched, and the Response Body is the same as the default HTTP Raw Message
2. Map Local from a given flow
Input: Create a Map Local with a given JSON Flow -> Modify the status code, add some header, and change some body
Expected: A flow is matched, and the Response Body is the same as we've updated (Status code, Header, Body)
3. Map Local from a given flow - by selecting a local HTTP Message file
Input:
Create a Map Local with a given JSON Flow
Create an HTTP Message with some Status code, Header, and JSON body -> Save it to the temporary folder for testing
Ask the Map Entry to select a local file (created in the 2nd step)
Expected:
A flow is matched, and the Response Body is the same as the local file
4. Map Local from a given flow - by selecting a local JSON File
Input:
Create a Map Local with a given JSON Flow
Create an local JSON body -> Save it to the temporary folder for testing
Ask the Map Entry to select a local file (created in the 2nd step)
Expected:
A flow is matched
The Response Header must have the Content-Type: application/json
Response Status code is 200
Response Body is exactly as a JSON Local File.
5. Map Local from a given flow - by selecting a local Image PNG File (Binary)
Input:
Create a Map Local with a given JSON Flow
Copy a small PNG image from the testing resource folder to the Temporary folder
Ask the Map Entry to select a PNG File.
Expected:
A flow is matched
The Response Header must have the Content-Type: image/png
Response Status code is 200
Response Body data must be exactly the PNG data. We can encode the binary to base64 or HASH String, and compare the string.
6. Map Local, but not matching
Input:
Create a Map Local with a given JSON Flow
Ask the Map Entry to change the URL
Expected:
A flow is not matched
Response Status code is 200
3 Response Body is exactly the HTTP Bin Response data (from the Real server)
7. Map Local from a given flow with GraphQL
Input:
Create a Map Local with a given GraphQL Flow
Ask the Map Entry to change some Header and Body.
Expected:
A flow is matched
The Map Local Entry must have the graphQLQueryName, and it matched the graphQL Query Name from the flow.
Response Status code is 200
Response Body and header are the same as we've updated
78 Map Local from a given flow with GraphQL, but different graphQL Query Name
Input:
Create a Map Local with a given GraphQL Flow
Ask the Map Entry to change the GraphQL Query Name to a different name.
Expected:
A flow is not matched! (Because the GraphQL is different even though the URL is the same)
Response Status code is 200
The response Body and header are the same with the real server (HTTP Bin)
Accepept Criteria
⚠️ Make sure all Unit Tests are implemented. I will carefully check it 👍 ⚠️ Please use the correct JSON data. You can capture it from httpbin.org or producthunt.com. Don't create a fake Unit Test Data, for example:
Reference Unit Test:
Unit Test for MapLocalService
1. Map with the default HTTP Message file
2. Map Local from a given flow
3. Map Local from a given flow - by selecting a local HTTP Message file
Input:
Expected:
4. Map Local from a given flow - by selecting a local JSON File
Input:
Expected:
Content-Type: application/json
5. Map Local from a given flow - by selecting a local Image PNG File (Binary)
Input:
Expected:
Content-Type: image/png
6. Map Local, but not matching
Input:
Expected:
7. Map Local from a given flow with GraphQL
Input:
Expected:
78 Map Local from a given flow with GraphQL, but different graphQL Query Name
Input:
Expected: