Skip to content

Commit

Permalink
feat: [#173965657] Adds the status redeemed for multiple bonus alert …
Browse files Browse the repository at this point in the history
…selector (#2093)

* [#173965657] Adds the status redeemed for multiple bonus alert selector

* Refactoring

* [#173965657] update tests

* [#173965657] update comment

Co-authored-by: Matteo Boschi <[email protected]>
  • Loading branch information
CrisTofani and Undermaken authored Jul 24, 2020
1 parent f8ab6d3 commit 35adc07
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ bonus:
validBetween: You will be able to use the Bonus Vacanze starting from {{from}} until {{to}}
bonusRejected: Attention! This Bonus Vacanze has been rejected
redeemed: This Bonus Vacanze has been consumed on {{date}}
multipleBonus: Two bonuses requested and activated by you. Make sure you use the correct DSU to prevent the bonus user from incurring subsequent recovery actions.
multipleBonus: Two or more bonuses requested and activated by you. Make sure you use the correct DSU to prevent the bonus user from incurring subsequent recovery actions.
usableAmount: Expendable at the accommodation facility
taxBenefit: Deductible in tax return
request: Request the
Expand Down
2 changes: 1 addition & 1 deletion locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ bonus:
validBetween: Potrai usare questo Bonus Vacanze dal {{from}} fino al {{to}}
bonusRejected: Attenzione! Questo Bonus Vacanze è stato annullato
redeemed: Questo Bonus Vacanze è stato utilizzato il {{date}}
multipleBonus: Risultano due bonus richiesti e attivati da te. Assicurati di usare quello relativo alla DSU corretta, per evitare che chi utilizza il bonus incorra in successive azioni di recupero.
multipleBonus: Risultano due o più bonus richiesti e attivati da te. Assicurati di usare quello relativo alla DSU corretta, per evitare che chi utilizza il bonus incorra in successive azioni di recupero.
usableAmount: Spendibile presso la struttura ricettiva
taxBenefit: Detraibile in dichiarazione dei redditi
request: Richiedi il
Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/screens/ActiveBonusScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from "../store/actions/bonusVacanze";
import {
bonusActiveDetailByIdSelector,
ownedActiveBonus
ownedActiveOrRedeemedBonus
} from "../store/reducers/allActive";
import {
availableBonusTypesSelectorFromId,
Expand Down Expand Up @@ -472,7 +472,7 @@ const mapStateToProps = (state: GlobalState, ownProps: OwnProps) => {
const bonus = bonusActiveDetailByIdSelector(bonusFromNav.id)(state);

return {
hasMoreOwnedActiveBonus: ownedActiveBonus(state).length > 1,
hasMoreOwnedActiveBonus: ownedActiveOrRedeemedBonus(state).length > 1,
bonusInfo: availableBonusTypesSelectorFromId(ID_BONUS_VACANZE_TYPE)(state),
bonus,
isError: pot.isNone(bonus) && pot.isError(bonus), // error and no bonus data, user should retry to load
Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/screens/BonusInformationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { actionWithAlert } from "../components/alert/ActionWithAlert";
import { bonusVacanzeStyle } from "../components/Styles";
import TosBonusComponent from "../components/TosBonusComponent";
import { checkBonusVacanzeEligibility } from "../store/actions/bonusVacanze";
import { ownedActiveBonus } from "../store/reducers/allActive";
import { ownedActiveOrRedeemedBonus } from "../store/reducers/allActive";

type NavigationParams = Readonly<{
bonusItem: BonusAvailable;
Expand Down Expand Up @@ -249,7 +249,7 @@ const BonusInformationScreen: React.FunctionComponent<Props> = props => {
};

const mapStateToProps = (state: GlobalState) => ({
hasOwnedActiveBonus: ownedActiveBonus(state).length > 0
hasOwnedActiveBonus: ownedActiveOrRedeemedBonus(state).length > 0
});

const mapDispatchToProps = (dispatch: Dispatch) => ({
Expand Down
59 changes: 47 additions & 12 deletions ts/features/bonusVacanze/store/reducers/__tests__/allActive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Version } from "../../../../../../definitions/backend/Version";
import { BonusActivationStatusEnum } from "../../../../../../definitions/bonus_vacanze/BonusActivationStatus";
import { BonusCode } from "../../../../../../definitions/bonus_vacanze/BonusCode";
import { mockedBonus } from "../../../mock/mockData";
import { ownedActiveBonus } from "../allActive";
import { ownedActiveOrRedeemedBonus } from "../allActive";

const fiscalCode = "ABCDEF83A12L719R" as FiscalCode;
const profile: InitializedProfile = {
Expand Down Expand Up @@ -39,14 +39,22 @@ const bonusActive = pot.some({
applicant_fiscal_code: fiscalCode
});

describe("ownedActiveBonus", () => {
const bonusRedeemed = pot.some({
...mockedBonus,
status: BonusActivationStatusEnum.REDEEMED,
applicant_fiscal_code: fiscalCode
});

describe("ownedActiveOrRedeemedBonus", () => {
it("should return an empty array", () => {
expect(ownedActiveBonus.resultFunc([], potProfile)).toStrictEqual([]);
expect(ownedActiveOrRedeemedBonus.resultFunc([], potProfile)).toStrictEqual(
[]
);
});

it("should return an empty array", () => {
expect(
ownedActiveBonus.resultFunc(
ownedActiveOrRedeemedBonus.resultFunc(
[pot.none, pot.none, pot.noneError(new Error("some error"))],
potProfile
)
Expand All @@ -55,24 +63,51 @@ describe("ownedActiveBonus", () => {

it("should return an empty array (different applicant)", () => {
expect(
ownedActiveBonus.resultFunc([bonusDifferentApplicant], potProfile)
ownedActiveOrRedeemedBonus.resultFunc(
[bonusDifferentApplicant],
potProfile
)
).toStrictEqual([]);
});

it("should return an empty array (status !== ACTIVE)", () => {
const bonusRedeemed = pot.some({
it("should return the bonus redeemed", () => {
expect(
ownedActiveOrRedeemedBonus.resultFunc([bonusRedeemed], potProfile)
).toStrictEqual([bonusRedeemed.value]);
});

it("should return the bonus redeemed and active", () => {
expect(
ownedActiveOrRedeemedBonus.resultFunc(
[bonusRedeemed, bonusActive],
potProfile
)
).toStrictEqual([bonusRedeemed.value, bonusActive.value]);
});

it("should return the bonus redeemed and active", () => {
expect(
ownedActiveOrRedeemedBonus.resultFunc(
[bonusRedeemed, bonusActive, pot.none, bonusDifferentApplicant],
potProfile
)
).toStrictEqual([bonusRedeemed.value, bonusActive.value]);
});

it("should return an empty array (status !== ACTIVE|REDEEMED)", () => {
const bonusProcessing = pot.some({
...mockedBonus,
status: BonusActivationStatusEnum.REDEEMED,
status: BonusActivationStatusEnum.PROCESSING,
applicant_fiscal_code: fiscalCode
});
expect(
ownedActiveBonus.resultFunc([bonusRedeemed], potProfile)
ownedActiveOrRedeemedBonus.resultFunc([bonusProcessing], potProfile)
).toStrictEqual([]);
});

it("should return the active bonus", () => {
expect(
ownedActiveBonus.resultFunc(
ownedActiveOrRedeemedBonus.resultFunc(
[bonusDifferentApplicant, bonusActive],
potProfile
)
Expand All @@ -81,7 +116,7 @@ describe("ownedActiveBonus", () => {

it("should return the active bonus", () => {
expect(
ownedActiveBonus.resultFunc(
ownedActiveOrRedeemedBonus.resultFunc(
[bonusDifferentApplicant, bonusActive, pot.none],
potProfile
)
Expand All @@ -94,7 +129,7 @@ describe("ownedActiveBonus", () => {
id: "XYZ" as BonusCode
});
expect(
ownedActiveBonus.resultFunc(
ownedActiveOrRedeemedBonus.resultFunc(
[bonusDifferentApplicant, bonusActive, anotherBonusActive, pot.none],
potProfile
)
Expand Down
7 changes: 4 additions & 3 deletions ts/features/bonusVacanze/store/reducers/allActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export const allBonusActiveSelector = createSelector<
return Object.keys(allActiveObj).map(k => allActiveObj[k]);
});

// return the list of the active bonus of which the current profile is the applicant
export const ownedActiveBonus = createSelector<
// return the list of the active or redeemed bonus of which the current profile is the applicant
export const ownedActiveOrRedeemedBonus = createSelector<
GlobalState,
ReadonlyArray<pot.Pot<BonusActivationWithQrCode, Error>>,
ProfileState,
Expand All @@ -89,7 +89,8 @@ export const ownedActiveBonus = createSelector<
if (
pot.isSome(curr) &&
curr.value.applicant_fiscal_code === p.fiscal_code &&
curr.value.status === BonusActivationStatusEnum.ACTIVE
(curr.value.status === BonusActivationStatusEnum.ACTIVE ||
curr.value.status === BonusActivationStatusEnum.REDEEMED)
) {
return [...acc, curr.value];
}
Expand Down

0 comments on commit 35adc07

Please sign in to comment.