Skip to content

[AMSDK-10032][AMSDK-10197] APIs for functional test assertions for network requests#33

Merged
emdobrin merged 18 commits intoadobe:devfrom
emdobrin:AMSDK-10032-network
Jun 17, 2020
Merged

[AMSDK-10032][AMSDK-10197] APIs for functional test assertions for network requests#33
emdobrin merged 18 commits intoadobe:devfrom
emdobrin:AMSDK-10032-network

Conversation

@emdobrin
Copy link
Copy Markdown
Contributor

Description

Adds APIs for setting network request expectations, mocking a network response and making assertions on the count and network request format in functional tests.

Related Issue

Motivation and Context

How Has This Been Tested?

See FunctionalSampleTest

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

/// The error associated with the request failure or nil on success
public let error: Error?

public init(data: Data?, response: HTTPURLResponse?, error: Error?) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make this public to create a HttpConnection as by default it is internal, will need to make this change in swift core too.

Copy link
Copy Markdown
Contributor

@nporter-adbe nporter-adbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just a few questions.

extension NetworkRequest : Hashable {

/// Equals compare based on host, scheme and URL path. Query params are not taken into consideration
public static func == (lhs: NetworkRequest, rhs: NetworkRequest) -> Bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are query params not considered? I think if you declare that NetworkRequest conforms to Equatable you will get this functionality for free without having to implement it yourself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented a custom compare for simplicity, I don't think you want to pass all the parameters when you mock a response (including headers, read/connect timeout).

Regarding the query params, some of the network requests contain unique query params that cannot be fetched from the extension beforehand, for e.g. requestId.
The other option would be to pass a regex, but again that makes the usage a bit more complex. With current implementation you can assert on these parameters on the NetworkRequest (s) returned by getNetworkRequestsWith(url: url, httpMethod: HttpMethod.post), if needed.

- run:
name: Project Setup
command: make setup
command: make update
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with calling pod update in CI as it could update the pods to versions the developer did not intend. Instead, we should update the pods locally and push the new Podfile.lock and call pod install in CI to install the CocoaPods versions defined in Podfile.lock. Also, calling pod repo update takes a long time in CircleCI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinlind would pod install work for new versions without repo update?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean pod repo update? I talked with Steve about this a while ago because the Places Monitor build does do pod repo update && pod install. I was hoping we could avoid running update as it takes so long in CircleCI, but it looks like it is needed. Instead of changing the CircleCI config, can you change the Makefile setup step to cd build/xcode && pod repo update || true && pod install ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but we use make setup on our local machines as well and I didn't want to run pod repo update all the times, it indeed takes long time. I can add a ci-pod-update command in the Makefile instead and use it in the config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly like having CI specific targets in the Makefile. I know we do that for the internal repos, but that was because we were using common build files which needed a consistent set of target names. Instead, what about adding a new target "install-dep" or "pod-install" which just runs cd build/xcode && pod install and change "setup" to cd build/xcode && pod repo update || true && pod install ?

@emdobrin emdobrin force-pushed the AMSDK-10032-network branch from 3cf4855 to 0d92fdd Compare June 13, 2020 01:57
@emdobrin emdobrin force-pushed the AMSDK-10032-network branch from 0d92fdd to 8d4d46e Compare June 13, 2020 01:59
@emdobrin emdobrin merged commit a60278f into adobe:dev Jun 17, 2020
@emdobrin emdobrin deleted the AMSDK-10032-network branch June 17, 2020 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants