-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(IT Wallet): [SIW-1702] Add automatic subscription to the ITW tr…
…ial system (#6228) > [!WARNING] > Can be tested with `io-dev-api-server` by pointing to [this PR.](pagopa/io-dev-api-server#414) ## Short description This PR adds an automatic subscription to the ITW trial system when opening the app. ## List of changes proposed in this pull request - Add the `handleTrialSystemSubscription` function to check the status of the trial system. If a citizen is unsubscribed, the function should automatically subscribe them to the trial system; - Mock the `CONFIG` object from `react-native-config`; - Add tests for `handleTrialSystemSubscription`. ## How to test This PR can be tested with the `io-dev-api-server` by checking the network traffic of the app: - Start `io-dev-api-server` with the default config which is `SUBSCRIBED`; - Start the app with the `.env.local` config; - Login and check for the network traffic. This can be checked either with ProxyMan or via the logs of `io-dev-api-server`; - Do the same test by rotating the trial states in the configuration of `io-dev-api-server`, either by changing it directly in `config.ts` or with a custom `config.json` file. The expected behavior is: ``` Any other state -> Only a `GET` to `trialId/subscriptions` should be performed UNSUBSCRIBED -> Both a `GET` and a `POST` to `trialId/subscriptions` should be performed ``` --------- Co-authored-by: Mario Perrotta <[email protected]> Co-authored-by: Andrea <[email protected]>
- Loading branch information
1 parent
0b6483f
commit ca8bc32
Showing
6 changed files
with
179 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export default { | ||
UA_DONATIONS_ENABLED: "YES", | ||
PREMIUM_MESSAGES_OPT_IN_ENABLED: "YES", | ||
SCAN_ADDITIONAL_BARCODES_ENABLED: "YES" | ||
SCAN_ADDITIONAL_BARCODES_ENABLED: "YES", | ||
ITW_TRIAL_ID: "baz" | ||
}; |
149 changes: 149 additions & 0 deletions
149
ts/features/itwallet/common/saga/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { expectSaga } from "redux-saga-test-plan"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import { DeepPartial } from "redux"; | ||
import * as matchers from "redux-saga-test-plan/matchers"; | ||
import { handleTrialSystemSubscription } from "../index"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { | ||
trialSystemActivationStatus, | ||
trialSystemActivationStatusUpsert | ||
} from "../../../../trialSystem/store/actions"; | ||
import { SubscriptionStateEnum } from "../../../../../../definitions/trial_system/SubscriptionState"; | ||
import { trialStatusSelector } from "../../../../trialSystem/store/reducers"; | ||
import { TrialId } from "../../../../../../definitions/trial_system/TrialId"; | ||
|
||
describe("handleTrialSystemSubscription", () => { | ||
it("should handle trial system subscription correctly", async () => { | ||
const trialId = "baz" as TrialId; | ||
const state = SubscriptionStateEnum.UNSUBSCRIBED; | ||
const store: DeepPartial<GlobalState> = { | ||
trialSystem: { | ||
[trialId]: pot.some(state) | ||
} | ||
}; | ||
return expectSaga(handleTrialSystemSubscription) | ||
.withState(store) | ||
.put(trialSystemActivationStatus.request(trialId)) | ||
.dispatch( | ||
trialSystemActivationStatus.success({ | ||
trialId, | ||
state, | ||
createdAt: new Date() | ||
}) | ||
) | ||
.take([ | ||
trialSystemActivationStatus.success, | ||
trialSystemActivationStatus.failure | ||
]) | ||
.provide([[matchers.select(trialStatusSelector), state]]) | ||
.put(trialSystemActivationStatusUpsert.request(trialId)) | ||
.run(); | ||
}); | ||
|
||
it("shouldn't do anything if the user is already subscribed", async () => { | ||
const trialId = "baz" as TrialId; | ||
const state = SubscriptionStateEnum.SUBSCRIBED; | ||
const store: DeepPartial<GlobalState> = { | ||
trialSystem: { | ||
[trialId]: pot.some(state) | ||
} | ||
}; | ||
return expectSaga(handleTrialSystemSubscription) | ||
.withState(store) | ||
.put(trialSystemActivationStatus.request(trialId)) | ||
.dispatch( | ||
trialSystemActivationStatus.success({ | ||
trialId, | ||
state, | ||
createdAt: new Date() | ||
}) | ||
) | ||
.take([ | ||
trialSystemActivationStatus.success, | ||
trialSystemActivationStatus.failure | ||
]) | ||
.provide([[matchers.select(trialStatusSelector), state]]) | ||
.not.put(trialSystemActivationStatusUpsert.request(trialId)) | ||
.run(); | ||
}); | ||
|
||
it("shouldn't do anything if the user is active", async () => { | ||
const trialId = "baz" as TrialId; | ||
const state = SubscriptionStateEnum.ACTIVE; | ||
const store: DeepPartial<GlobalState> = { | ||
trialSystem: { | ||
[trialId]: pot.some(state) | ||
} | ||
}; | ||
return expectSaga(handleTrialSystemSubscription) | ||
.withState(store) | ||
.put(trialSystemActivationStatus.request(trialId)) | ||
.dispatch( | ||
trialSystemActivationStatus.success({ | ||
trialId, | ||
state, | ||
createdAt: new Date() | ||
}) | ||
) | ||
.take([ | ||
trialSystemActivationStatus.success, | ||
trialSystemActivationStatus.failure | ||
]) | ||
.provide([[matchers.select(trialStatusSelector), state]]) | ||
.not.put(trialSystemActivationStatusUpsert.request(trialId)) | ||
.run(); | ||
}); | ||
|
||
it("shouldn't do anything if the user is disabled", async () => { | ||
const trialId = "baz" as TrialId; | ||
const state = SubscriptionStateEnum.DISABLED; | ||
const store: DeepPartial<GlobalState> = { | ||
trialSystem: { | ||
[trialId]: pot.some(state) | ||
} | ||
}; | ||
return expectSaga(handleTrialSystemSubscription) | ||
.withState(store) | ||
.put(trialSystemActivationStatus.request(trialId)) | ||
.dispatch( | ||
trialSystemActivationStatus.success({ | ||
trialId, | ||
state, | ||
createdAt: new Date() | ||
}) | ||
) | ||
.take([ | ||
trialSystemActivationStatus.success, | ||
trialSystemActivationStatus.failure | ||
]) | ||
.provide([[matchers.select(trialStatusSelector), state]]) | ||
.not.put(trialSystemActivationStatusUpsert.request(trialId)) | ||
.run(); | ||
}); | ||
|
||
it("shouldn't do anything if an error occurs", async () => { | ||
const trialId = "baz" as TrialId; | ||
const state = SubscriptionStateEnum.UNSUBSCRIBED; | ||
const store: DeepPartial<GlobalState> = { | ||
trialSystem: { | ||
[trialId]: pot.some(state) | ||
} | ||
}; | ||
return expectSaga(handleTrialSystemSubscription) | ||
.withState(store) | ||
.put(trialSystemActivationStatus.request(trialId)) | ||
.dispatch( | ||
trialSystemActivationStatus.failure({ | ||
trialId, | ||
error: new Error("foo") | ||
}) | ||
) | ||
.take([ | ||
trialSystemActivationStatus.success, | ||
trialSystemActivationStatus.failure | ||
]) | ||
.provide([[matchers.select(trialStatusSelector), state]]) | ||
.not.put(trialSystemActivationStatusUpsert.request(trialId)) | ||
.run(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters