Skip to content

Commit

Permalink
fix(Bonus Pagamenti Digitali): [#175117682] Citizen delete response c…
Browse files Browse the repository at this point in the history
…annot be decoded (#2265)

* [#175117682] fix

* [#175117682] fixes

* [#175117682] fixes

* [#175117682] restore changed file

* [#175117682] fix a bug

* [#175117682] update store on delete from program

Co-authored-by: fabriziofff <[email protected]>
  • Loading branch information
Undermaken and fabriziofff authored Oct 7, 2020
1 parent 312eeef commit 5520010
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
39 changes: 29 additions & 10 deletions ts/features/bonus/bpd/api/backendBpdClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as t from "io-ts";
import * as r from "italia-ts-commons/lib/requests";
import { defaultRetryingFetch } from "../../../../utils/fetch";
import {
deleteUsingDELETEDefaultDecoder,
DeleteUsingDELETET,
enrollmentDecoder,
EnrollmentT,
findUsingGETDecoder,
Expand Down Expand Up @@ -61,12 +59,36 @@ const enrollCitizenIOT: EnrollmentTTExtra = {
response_decoder: enrollmentDecoder(PatchedCitizenResource)
};

const deleteCitizenIOT: DeleteUsingDELETET = {
const deleteResponseDecoders = r.composeResponseDecoders(
r.composeResponseDecoders(
r.constantResponseDecoder<undefined, 204>(204, undefined),
r.constantResponseDecoder<undefined, 401>(401, undefined)
),
r.constantResponseDecoder<undefined, 404>(404, undefined)
);

// these responses code/codec are built from api usage and not from API spec
// see https://bpd-dev.portal.azure-api.net/docs/services/bpd-ms-citizen/operations/deleteUsingDELETE
type DeleteUsingDELETETExtra = r.IDeleteApiRequestType<
{
readonly apiKeyHeader: string;
readonly Authorization: string;
readonly x_request_id?: string;
},
"Ocp-Apim-Subscription-Key",
never,
| r.IResponseType<204, undefined>
| r.IResponseType<401, undefined>
| r.IResponseType<404, undefined>
| r.IResponseType<500, undefined>
>;

const deleteCitizenIOT: DeleteUsingDELETETExtra = {
method: "delete",
url: () => `/bpd/io/citizen`,
query: _ => ({}),
headers: headersProducers(),
response_decoder: deleteUsingDELETEDefaultDecoder()
response_decoder: deleteResponseDecoders
};

// decoders composition to handle updatePaymentMethod response
Expand Down Expand Up @@ -146,12 +168,9 @@ export function BackendBpdClient(
// FIX ME !this code must be removed!
// only for test purpose
const withTestToken = () =>
fetchApi(
`https://bpd-dev.azure-api.net/bpd/pagopa/api/v1/login?fiscalCode=${fiscalCode}`,
{
method: "post"
}
);
fetchApi(`${baseUrl}/bpd/pagopa/api/v1/login?fiscalCode=${fiscalCode}`, {
method: "post"
});

const withBearerToken = <P extends extendHeaders, R>(
f: (p: P) => Promise<R>
Expand Down
1 change: 1 addition & 0 deletions ts/features/bonus/bpd/saga/networking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export function* deleteCitizen(
if (deleteCitizenIOResult.isRight()) {
if (deleteCitizenIOResult.value.status === 204) {
yield put(bpdDeleteUserFromProgram.success());
return;
}
throw new Error(`response status ${deleteCitizenIOResult.value.status}`);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
RemoteValue
} from "../../../../model/RemoteValue";
import { bpdLoadActivationStatus } from "../../../actions/details";
import { bpdEnrollUserToProgram } from "../../../actions/onboarding";
import {
bpdDeleteUserFromProgram,
bpdEnrollUserToProgram
} from "../../../actions/onboarding";
import paymentInstrumentReducer, {
PayoffInstrumentType
} from "./payoffInstrument";
Expand Down Expand Up @@ -41,6 +44,8 @@ const enabledReducer = (
case getType(bpdLoadActivationStatus.success):
case getType(bpdEnrollUserToProgram.success):
return remoteReady(action.payload.enabled);
case getType(bpdDeleteUserFromProgram.success):
return remoteReady(false);
case getType(bpdLoadActivationStatus.failure):
case getType(bpdEnrollUserToProgram.failure):
return remoteError(action.payload);
Expand Down

0 comments on commit 5520010

Please sign in to comment.