-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOPID-1372,IOPID-1373] Add remote ToS management (#5446)
###⚠️ This PR Depends on pagopa/io-services-metadata#764⚠️ ### ## Short description This PR adds the remote ToS management feature. <details open><summary>Details</summary> <p> | Custom Url | Default Url | | - | - | | <video src="https://github.com/pagopa/io-app/assets/16268789/fe048576-f519-4a78-a336-7cb97f0e20d2" /> | <video src="https://github.com/pagopa/io-app/assets/16268789/45b695ba-ed02-4d35-92ae-2a37353e675b" /> </p> </details> ## List of changes proposed in this pull request - Bump io-servives-metadata tag from 1.0.29 to 1.0.30 - Add the remote ToS management ## How to test Run the app against [this dev server branch](https://github.com/pagopa/io-dev-api-server/tree/IOPID-1374-remote-tos) and try to change [`ToS version`](https://github.com/pagopa/io-dev-api-server/blob/4df1c0c1f17f1e633a1fb6b77cd9df4c7142beff/src/payloads/backend.ts#L125) (with a number greater than the one in the profile) and [`ToS url`](https://github.com/pagopa/io-dev-api-server/blob/4df1c0c1f17f1e633a1fb6b77cd9df4c7142beff/src/payloads/backend.ts#L126) with a custom one. Then restore the ToS url to the expected one `https://io.italia.it/app-content/tos_privacy.html` and test that it's shown too. --------- Co-authored-by: Alice Di Rico <[email protected]>
- Loading branch information
1 parent
8cd556b
commit 585f6d4
Showing
12 changed files
with
137 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { NonNegativeNumber } from "@pagopa/ts-commons/lib/numbers"; | ||
import { TosConfig } from "../../../definitions/content/TosConfig"; | ||
|
||
export const getTosVersion = (tosData: TosConfig): NonNegativeNumber => | ||
tosData.tos_version as NonNegativeNumber; | ||
|
||
export const getTosUrl = (tosData: TosConfig): string => tosData.tos_url; |
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,65 @@ | ||
import * as O from "fp-ts/lib/Option"; | ||
import { NonNegativeNumber } from "@pagopa/ts-commons/lib/numbers"; | ||
import { BackendStatus } from "../../../../../../definitions/content/BackendStatus"; | ||
import { baseRawBackendStatus } from "../../../../../store/reducers/__mock__/backendStatus"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { TosConfig } from "../../../../../../definitions/content/TosConfig"; | ||
import { getTosUrl, getTosVersion } from "../../.."; | ||
|
||
const TOS_CONFIG: TosConfig = { | ||
tos_url: "https://www.example.com", | ||
tos_version: 3.2 as NonNegativeNumber | ||
}; | ||
|
||
const status: BackendStatus = { | ||
...baseRawBackendStatus | ||
}; | ||
|
||
const customStore = { | ||
backendStatus: { | ||
status: O.some({ | ||
...status, | ||
config: { | ||
...status.config, | ||
tos: TOS_CONFIG | ||
} | ||
}) | ||
} | ||
} as unknown as GlobalState; | ||
|
||
function runTest(store: GlobalState, test: (tosConfig: TosConfig) => void) { | ||
const actualStatus = store.backendStatus.status; | ||
expect(O.isSome(actualStatus)).toBe(true); | ||
if (O.isSome(actualStatus)) { | ||
const tosConfig = actualStatus.value.config.tos; | ||
expect(tosConfig).not.toBeUndefined(); | ||
test(tosConfig); | ||
} else { | ||
fail("unexpected none"); | ||
} | ||
} | ||
|
||
describe("Tos config", () => { | ||
it("should return a value", () => { | ||
runTest(customStore, tosConfig => { | ||
expect(getTosVersion(tosConfig)).not.toBeUndefined(); | ||
expect(getTosUrl(tosConfig)).not.toBeNull(); | ||
expect(getTosVersion(tosConfig)).not.toBeNaN(); | ||
}); | ||
}); | ||
it("should be right", () => { | ||
runTest(customStore, tosConfig => { | ||
expect(getTosVersion(tosConfig)).toBe(3.2); | ||
expect(getTosUrl(tosConfig)).toBe("https://www.example.com"); | ||
}); | ||
}); | ||
it("should not be wrong", () => { | ||
runTest(customStore, tosConfig => { | ||
expect(getTosVersion(tosConfig)).not.toBe(3.0); | ||
expect(getTosVersion(tosConfig)).not.toBe(3); | ||
expect(getTosUrl(tosConfig)).not.toBe("http://www.example.com"); | ||
expect(getTosVersion(tosConfig)).not.toBe(3.8); | ||
expect(getTosUrl(tosConfig)).not.toBe("http://www.example.it"); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { createSelector } from "reselect"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
import * as O from "fp-ts/lib/Option"; | ||
import { TosConfig } from "../../../../../definitions/content/TosConfig"; | ||
import { privacyUrl } from "../../../../config"; | ||
import { backendStatusSelector } from "../../../../store/reducers/backendStatus"; | ||
|
||
const DEFAULT_TOS_CONFIG: TosConfig = { | ||
tos_url: privacyUrl, | ||
tos_version: 4.8 | ||
}; | ||
|
||
export const tosConfigSelector = createSelector( | ||
backendStatusSelector, | ||
backendStatus => | ||
pipe( | ||
backendStatus, | ||
O.chainNullableK(bs => bs.config.tos), | ||
O.fold( | ||
() => DEFAULT_TOS_CONFIG, | ||
v => v | ||
) | ||
) | ||
); |
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
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
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