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

[#175395536] Add Organization logo's upload #83

Merged
merged 6 commits into from
Oct 29, 2020

Conversation

AleDore
Copy link
Contributor

@AleDore AleDore commented Oct 26, 2020

This PR adds a new endpoint for UploadOrganizationLogooperation. See io-functions-admin PR for further informations

@codecov-io
Copy link

codecov-io commented Oct 26, 2020

Codecov Report

Merging #83 into master will decrease coverage by 1.31%.
The diff coverage is 88.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
- Coverage   85.71%   84.39%   -1.32%     
==========================================
  Files          36       21      -15     
  Lines         728      673      -55     
  Branches       73       63      -10     
==========================================
- Hits          624      568      -56     
- Misses        100      104       +4     
+ Partials        4        1       -3     
Impacted Files Coverage Δ
UploadOrganizationLogo/handler.ts 82.75% <82.75%> (ø)
CreateService/handler.ts 86.84% <100.00%> (+1.54%) ⬆️
UpdateService/handler.ts 88.37% <100.00%> (+1.19%) ⬆️
generated/definitions/ServicePayload.ts
generated/api-admin/Logo.ts
generated/definitions/DepartmentName.ts
...enerated/definitions/SubscriptionKeyTypePayload.ts
generated/notifications/ProblemJson.ts
generated/definitions/FiscalCode.ts
generated/notifications/requestTypes.ts
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa3bbb6...25e0975. Read the comment docs.

@pagopa-github-bot
Copy link
Contributor

pagopa-github-bot commented Oct 26, 2020

Affected stories

  • 🌟 #175395536: Come SAS, voglio poter caricare l' immagine relativa al logo dell' organizzazione utilizzando le API di onboarding programmatico dei servizi.

Generated by 🚫 dangerJS

@AleDore AleDore requested a review from balanza October 26, 2020 15:12
@AleDore AleDore changed the title [#175395536] Add upload organization logo [#175395536] Add Organization logo's upload Oct 26, 2020
parameters:
- name: organization_fiscal_code
in: path
type: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a better definition than string? Can we use OrganizationFiscalCode

Comment on lines 566 to 567
"200":
description: Logo uploaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we prefer/can return 201 along with the reference to the just uploaded image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The io-functions-admin endpoint, that is called inside this endpoint on io-functions-services' side, returns 201 with the link to the uploaded image. I don't remember well, but in this case we are avoiding to expose infos about storage and CDN links to external subjects. cc: @gunzip

Comment on lines 568 to 579
"400":
description: Invalid payload.
schema:
$ref: "#/definitions/ProblemJson"
"401":
description: Unauthorized.
"403":
description: Forbidden.
"500":
description: The service logo cannot be uploaded.
schema:
$ref: "#/definitions/ProblemJson"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we want to add 404 in case no Organization is found with such fiscal code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, there's another story to achieve this. At the moment we don't have a check mechanism cause Organization Model is missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

The point is that the handler can actually return 404

package.json Outdated
@@ -17,7 +17,7 @@
"lint": "tslint -p .",
"generate:definitions": "rimraf ./generated/definitions && shx mkdir -p ./generated/definitions && gen-api-models --api-spec ./openapi/index.yaml --no-strict --out-dir ./generated/definitions",
"generate:api-notifications": "rimraf ./generated/notifications && shx mkdir -p ./generated/notifications && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-backend/master/api_notifications.yaml --out-dir ./generated/notifications --response-decoders --request-types",
"generate:api-admin": "rimraf generated/api-admin && shx mkdir -p generated/api-admin && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-functions-admin/master/openapi/index.yaml --no-strict --out-dir generated/api-admin --request-types --response-decoders --client",
"generate:api-admin": "rimraf generated/api-admin && shx mkdir -p generated/api-admin && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-functions-admin/175395536_upload_organization_logo/openapi/index.yaml --no-strict --out-dir generated/api-admin --request-types --response-decoders --client",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not have been committed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, It's a Draft for this reason :)

| IResponseSuccessJson<undefined>
| IResponseErrorUnauthorized
| IResponseErrorForbiddenNotAuthorized
| IResponseErrorNotFound
Copy link
Contributor

Choose a reason for hiding this comment

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

We must map it in the spec as well

apiClient: APIClient,
organizationFiscalCode: OrganizationFiscalCode,
logo: Logo
): TaskEither<ErrorResponses, IResponseSuccessJson<undefined>> =>
Copy link
Contributor

Choose a reason for hiding this comment

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

SInce we are returning undefined, is that a hint that we might return something else (like 202 o0r 204)?

};

describe("UploadOrganizationLogo", () => {
it("should respond with 201 if logo upload was successfull", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 201? I think is 200, according to the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this must be corrected 👍

aLogoPayload
);

expect(apiClientMock.uploadOrganizationLogo).toHaveBeenCalledTimes(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this test? This function is mocked, so we expect the test to just fail if it's not called

aLogoPayload
);

expect(apiClientMock.uploadOrganizationLogo).toHaveBeenCalledTimes(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

aLogoPayload
);

expect(apiClientMock.uploadOrganizationLogo).toHaveBeenCalledTimes(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@balanza balanza left a comment

Choose a reason for hiding this comment

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

I made a lot of comments and they might appear unrelated and conflicting. Here I try to sum up:

  • Implementation and specification are not aligned
  • We might want to model the success case with something different than 200
  • Can we use OrganizationFiscaleCode definition?
  • We should avoid testing implementation (that is, has this been called) and try to test input/output instead

@AleDore AleDore marked this pull request as ready for review October 27, 2020 13:04
@AleDore AleDore requested a review from balanza October 27, 2020 13:05
@AleDore
Copy link
Contributor Author

AleDore commented Oct 28, 2020

Can we merge this? @gunzip @balanza

).map(_ => ResponseSuccessAccepted());

/**
* Handles requests for upload a service logo by a service ID and a base64 logo' s string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Handles requests for upload a service logo by a service ID and a base64 logo' s string.
* Handles requests for upload an organization logo.

Comment on lines 551 to 552
This API operation needs a valid API key
otherwise 403 forbidden will be returned to the caller.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is implied by the 403 status below

Comment on lines 721 to 731
OrganizationFiscalCode:
name: organization_fiscal_code
in: path
type: string
description: Organization fiscal code.
format: OrganizationFiscalCode
minLength: 11
maxLength: 11
pattern: "^[0-9]{11}$"
required: true
x-example: "12345678901"
Copy link
Contributor

Choose a reason for hiding this comment

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

@AleDore AleDore requested a review from gunzip October 29, 2020 08:53
@gunzip gunzip merged commit 325fa95 into master Oct 29, 2020
@gunzip gunzip deleted the 175395536_add_upload_organization_logo branch October 29, 2020 13:38
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.

5 participants