-
Notifications
You must be signed in to change notification settings - Fork 106
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
Return context and structured metadata in rename API #381
Open
GiniAppsPartners
wants to merge
6
commits into
master
Choose a base branch
from
feature/context-metadata-used-by-variables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f536ae
Add content metadata new test
apsoftwareservice 0163874
Add new context and metadata parameters, add new unit tests.
3542c1c
Merge branch 'master' into feature/context-metadata-used-by-variables
b256071
Remove extra line
40dff76
Remove context and metadata params from rename func
AlexPinhasov 5eb329a
Remove context and metadata from function documentation
AlexPinhasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,9 @@ import XCTest | |
|
||
|
||
class ManagementApiTests: NetworkBaseTest { | ||
|
||
|
||
private var allowFolderDecouplingCalls: Bool = false | ||
|
||
// MARK: - rename | ||
func testRename() { | ||
|
||
|
@@ -85,6 +87,109 @@ class ManagementApiTests: NetworkBaseTest { | |
XCTAssertNil(error, "error should be nil") | ||
XCTAssertNotNil(result, "response should not be nil") | ||
} | ||
|
||
func testRenameShouldReturnContext() throws { | ||
|
||
try XCTSkipUnless(allowFolderDecouplingCalls, "prevents redundant call to Cloudinary PAID Folder Decoupling service. to allow Folder Decoupling service testing - set to true") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adimiz1 @const-cloudinary Let me know what the service I am trying to use thats blocking me because of my free account type, il change that afterward. |
||
|
||
let expectation = self.expectation(description: "Rename should succeed") | ||
|
||
var result: CLDRenameResult? | ||
var error: Error? | ||
|
||
uploadFile().response({ (uploadResult, uploadError) in | ||
if let publicId = uploadResult?.publicId { | ||
let toRename = publicId + "__APPENDED STRING" | ||
self.cloudinary!.createManagementApi().rename(publicId, to: toRename, overwrite: true, invalidate: true, context: true).response({ (resultRes, errorRes) in | ||
result = resultRes | ||
error = errorRes | ||
|
||
expectation.fulfill() | ||
}) | ||
} | ||
else { | ||
error = uploadError | ||
expectation.fulfill() | ||
} | ||
}) | ||
|
||
waitForExpectations(timeout: timeout, handler: nil) | ||
|
||
XCTAssertNil(error, "error should be nil") | ||
XCTAssertNotNil(result?.context, "response should not be nil") | ||
} | ||
|
||
func testRenameShouldReturnContextSimplifiedToRequest() { | ||
do { | ||
var urlRequest = URLRequest(url: URL(string: "https://example.com/image/rename")!) | ||
urlRequest.httpMethod = CLDNHTTPMethod.post.rawValue | ||
let renameParams = CLDRenameRequestParams(fromPublicId: "from", toPublicId: "to", overwrite: true, invalidate: true, context: true, metadata: false) | ||
|
||
let encodedURLRequest = try CLDNURLEncoding.default.CLDN_Encode(urlRequest, with: renameParams.params) | ||
|
||
XCTAssertNotNil(encodedURLRequest.httpBody, "HTTPBody should not be nil") | ||
|
||
if let httpBody = encodedURLRequest.httpBody, let decodedHTTPBody = String(data: httpBody, encoding: .utf8) { | ||
XCTAssertTrue(decodedHTTPBody.contains("context=1") && decodedHTTPBody.contains("metadata=0")) | ||
} else { | ||
XCTFail("decoded http body should not be nil") | ||
} | ||
} catch { | ||
XCTFail("Test encountered unexpected error: \(error)") | ||
} | ||
} | ||
|
||
func testRenameShouldReturnMetadata() throws { | ||
|
||
try XCTSkipUnless(allowFolderDecouplingCalls, "prevents redundant call to Cloudinary PAID Folder Decoupling service. to allow Folder Decoupling service testing - set to true") | ||
|
||
let expectation = self.expectation(description: "Rename should succeed") | ||
|
||
var result: CLDRenameResult? | ||
var error: Error? | ||
|
||
uploadFile().response({ (uploadResult, uploadError) in | ||
if let publicId = uploadResult?.publicId { | ||
let toRename = publicId + "__APPENDED STRING" | ||
self.cloudinary!.createManagementApi().rename(publicId, to: toRename, overwrite: true, invalidate: true, metadata: true).response({ (resultRes, errorRes) in | ||
result = resultRes | ||
error = errorRes | ||
|
||
expectation.fulfill() | ||
}) | ||
} | ||
else { | ||
error = uploadError | ||
expectation.fulfill() | ||
} | ||
}) | ||
|
||
waitForExpectations(timeout: timeout, handler: nil) | ||
|
||
XCTAssertNil(error, "error should be nil") | ||
XCTAssertNotNil(result?.metadata, "response should not be nil") | ||
} | ||
|
||
func testRenameShouldReturnMetadataSimplifiedToRequest() { | ||
do { | ||
var urlRequest = URLRequest(url: URL(string: "https://example.com/image/rename")!) | ||
urlRequest.httpMethod = CLDNHTTPMethod.post.rawValue | ||
let renameParams = CLDRenameRequestParams(fromPublicId: "from", toPublicId: "to", overwrite: true, invalidate: true, context: false, metadata: true) | ||
|
||
// When | ||
let encodedURLRequest = try CLDNURLEncoding.default.CLDN_Encode(urlRequest, with: renameParams.params) | ||
|
||
XCTAssertNotNil(encodedURLRequest.httpBody, "HTTPBody should not be nil") | ||
|
||
if let httpBody = encodedURLRequest.httpBody, let decodedHTTPBody = String(data: httpBody, encoding: .utf8) { | ||
XCTAssertTrue(decodedHTTPBody.contains("metadata=1") && decodedHTTPBody.contains("context=0")) | ||
} else { | ||
XCTFail("decoded http body should not be nil") | ||
} | ||
} catch { | ||
XCTFail("Test encountered unexpected error: \(error)") | ||
} | ||
} | ||
|
||
// MARK: - explicit | ||
func testExplicit() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@const-cloudinary I think we should put the new optional parameters only in the
CLRenameRequestParams
and not part of therename
functionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexPinhasovLili please put the
context
andmetadata
params only in theCLDRenameRequestParams
and not part of therename
function