Skip to content

Feature/structured metadata #171

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

Merged
merged 8 commits into from
Aug 8, 2019
Merged

Feature/structured metadata #171

merged 8 commits into from
Aug 8, 2019

Conversation

nitzanj
Copy link
Contributor

@nitzanj nitzanj commented Jul 10, 2019

No description provided.

@nitzanj nitzanj requested a review from asisayag2 July 10, 2019 05:37
@asisayag2
Copy link
Contributor

@nitzanj , one of the tests failed. please check


/**
* Update the datasource entries for a given field
* @param fieldExternalId The id of the field to update
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistency - sometimes it is called externalId and sometimes fieldExternalId.
I suggest using fieldId (not sure what the external represents)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you send an ID to a function about a field you an omit the 'field' for brevity. When you need to provide an id for a field in the context of another API (e.g. datasource, that has it's own id() you must include the 'field' in the parameter name for clarity.

I can use 'fieldExternalId' everywhere for consistency. The word external is part of the spec, that's the key used in all the requests and responses, we have to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the fieldExternalId vs. externalId, got it.

Regarding the external,
I understand that this is what the server is using, but I don't understand why they are using it.
In any case, why do we have to be aligned with the server naming?

Copy link
Contributor Author

@nitzanj nitzanj Aug 7, 2019

Choose a reason for hiding this comment

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

I had a long discussion about it with docs, for them it's real bad if the API docs use different names than the SDK docs so we're using the same names. We can open it up tomorrow to if you want, for us it's a quick easy fix...

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. let's talk about it

addFieldToAccount(stringField);

ApiResponse result = cloudinary.api().listMetadataFields();
assertNotNull(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's assert the rest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can assert that there's a list, not the actual item as it may be far behind and not get fetched on the first batch (parallel testing).

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I get what you mean...

ApiResponse fieldResult = addFieldToAccount(newFieldInstance("testDeleteField"));
ApiResponse result = api.deleteMetadataField(fieldResult.get("external_id").toString());
assertNotNull(result);
assertEquals("ok", result.get("message"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Check that getMetadataField returns null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? Java tests are slow as it is, and subsequent calls are 100% server tests with no implications on the SDK whatsoever. Since we do assert the server ACK, checking again will turn this into a pure backend regression test...

MetadataDataSource.Entry newEntry = new MetadataDataSource.Entry("id1", "new1");
ApiResponse result = api.updateMetadataFieldDatasource(fieldResult.get("external_id").toString(), Collections.singletonList(newEntry));
assertNotNull(result);
assertEquals("new1", ((Map) ((List) result.get("values")).get(0)).get("value"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Check what happens when adding an entry that already exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, your call but I was trying to avoid making this a full backend integration/regression test. There isn't even a 'correct' behaviour in the spec to test against...

Map<String, Object> metadata = Collections.<String, Object>singletonMap(fieldId, "123456");
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("metadata", metadata, "tags", Arrays.asList(SDK_TEST_TAG, METADATA_UPLOADER_TAG)));
assertNotNull(result.get("metadata"));
assertEquals("123456", ((Map) result.get("metadata")).get(fieldId));
Copy link
Contributor

Choose a reason for hiding this comment

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

What about testing validations? or sending wrong values?

@nitzanj nitzanj merged commit 948e5c6 into master Aug 8, 2019
@nitzanj nitzanj deleted the feature/structured-metadata branch August 8, 2019 08:59
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.

2 participants