-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Affected stories
Generated by 🚫 dangerJS |
openapi/index.yaml
Outdated
parameters: | ||
- name: organization_fiscal_code | ||
in: path | ||
type: string |
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.
Do we have a better definition than string
? Can we use OrganizationFiscalCode
openapi/index.yaml
Outdated
"200": | ||
description: Logo uploaded. |
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.
Do we prefer/can return 201 along with the reference to the just uploaded image?
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.
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
openapi/index.yaml
Outdated
"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" |
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.
Maybe we want to add 404 in case no Organization
is found with such fiscal code?
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.
Nope, there's another story to achieve this. At the moment we don't have a check mechanism cause Organization Model is missing.
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.
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", |
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.
This should not have been committed
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.
Yep, It's a Draft for this reason :)
UploadOrganizationLogo/handler.ts
Outdated
| IResponseSuccessJson<undefined> | ||
| IResponseErrorUnauthorized | ||
| IResponseErrorForbiddenNotAuthorized | ||
| IResponseErrorNotFound |
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.
We must map it in the spec as well
UploadOrganizationLogo/handler.ts
Outdated
apiClient: APIClient, | ||
organizationFiscalCode: OrganizationFiscalCode, | ||
logo: Logo | ||
): TaskEither<ErrorResponses, IResponseSuccessJson<undefined>> => |
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.
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 () => { |
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.
Why 201? I think is 200, according to the implementation
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.
Yes, this must be corrected 👍
aLogoPayload | ||
); | ||
|
||
expect(apiClientMock.uploadOrganizationLogo).toHaveBeenCalledTimes(1); |
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.
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); |
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.
ditto
aLogoPayload | ||
); | ||
|
||
expect(apiClientMock.uploadOrganizationLogo).toHaveBeenCalledTimes(1); |
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.
ditto
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.
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
UploadOrganizationLogo/handler.ts
Outdated
).map(_ => ResponseSuccessAccepted()); | ||
|
||
/** | ||
* Handles requests for upload a service logo by a service ID and a base64 logo' s string. |
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.
* Handles requests for upload a service logo by a service ID and a base64 logo' s string. | |
* Handles requests for upload an organization logo. |
openapi/index.yaml
Outdated
This API operation needs a valid API key | ||
otherwise 403 forbidden will be returned to the caller. |
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.
this is implied by the 403 status below
openapi/index.yaml
Outdated
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" |
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.
you should use this format:
https://github.com/pagopa/io-functions-commons/blob/master/openapi/definitions.yaml#L290
This PR adds a new endpoint for
UploadOrganizationLogo
operation. See io-functions-admin PR for further informations