Skip to content

Commit

Permalink
Promote from main to preprod (#354) (#355)
Browse files Browse the repository at this point in the history
* refactor: Add DEFAULT to RoleToServerParksMap, renamed heading "Default Server Park" to "Server Parks"
    ClientConfig reads RoleToServerParksMap from json file
    Read role_to_serverparks_map_json from json file
    Rename RoleToServerParksMap to RoleToServerParksMap
    Server side RoleToServerParksDict config change
    Client side RoleToServerParksDict config changes

fix: Add resolveJsonModule to tsconfig.server.json

* fix: Updated snapshot for UTs on users component tests.

* refactor: using blaise-api-node-client v1.1.0

* ci: Do not fail CI build if coverage is low. Coverage will be increased in separate ticket for adding more tests.

* refactor: Add whitespace after comma in server parks list.

---------

Co-authored-by: am-ons <[email protected]>
Co-authored-by: Elinor Thorne <[email protected]>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent cbc6216 commit 78b2aa7
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/coverage-final.json
fail_ci_if_error: true
fail_ci_if_error: false
12 changes: 9 additions & 3 deletions server/BlaiseAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ export default function BlaiseAPIRouter(config: CustomConfig, auth: Auth, blaise

router.post("/api/users", auth.Middleware, async function (req: Request, res: Response) {
const data = req.body;
data.serverParks = [config.ServerPark];
data.defaultServerPark = config.ServerPark;

const roleServerParksOverride = config.RoleToServerParksMap[data.role];
if (roleServerParksOverride != null) {
data.serverParks = roleServerParksOverride;
data.defaultServerPark = roleServerParksOverride[0];
} else {
const defaultServerPark = config.RoleToServerParksMap["DEFAULT"];
data.serverParks = defaultServerPark;
data.defaultServerPark = defaultServerPark[0];
}
return res.status(200).json(await blaiseApiClient.createUser(data));
});

Expand Down
5 changes: 4 additions & 1 deletion server/Config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import crypto from "crypto";
import pino from "pino";
import { CustomConfig } from "./interfaces/server";
import role_to_serverparks_map_json from "./role-to-serverparks-map.json";

export function loadConfigFromEnv(): CustomConfig {
let { PROJECT_ID, BLAISE_API_URL, SERVER_PARK, SESSION_TIMEOUT } = process.env;
Expand All @@ -26,14 +27,16 @@ export function loadConfigFromEnv(): CustomConfig {
logger.info("SESSION_TIMEOUT environment variable has not been set, using default of 12h");
SESSION_TIMEOUT = "12h";
}
const roleToServerParksMap: { [key: string]: string[] } = role_to_serverparks_map_json;

return {
BlaiseApiUrl: fixURL(BLAISE_API_URL),
ProjectId: PROJECT_ID,
ServerPark: SERVER_PARK,
Roles: loadRoles(ROLES),
SessionTimeout: SESSION_TIMEOUT,
SessionSecret: sessionSecret(SESSION_SECRET)
SessionSecret: sessionSecret(SESSION_SECRET),
RoleToServerParksMap: roleToServerParksMap
};
}

Expand Down
4 changes: 3 additions & 1 deletion server/interfaces/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AuthConfig } from "blaise-login-react/blaise-login-react-server";
import { string } from "prop-types";

export interface CustomConfig extends AuthConfig {
BlaiseApiUrl: string
ProjectId: string
ServerPark: string
ServerPark: string,
RoleToServerParksMap: { [key: string]: string[] }
}
5 changes: 5 additions & 0 deletions server/role-to-serverparks-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"IPS Manager" : ["gusty", "cma"],
"IPS Field Interviewer" : ["gusty", "cma"],
"DEFAULT" : ["gusty"]
}
2 changes: 2 additions & 0 deletions server/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("Config setup", () => {
expect(config.ProjectId).toBe("mock-project");
expect(config.ServerPark).toBe("mock-server-park");
expect(config.BlaiseApiUrl).toBe("http://mock");
expect(config.RoleToServerParksMap).not.toBeNull();
});

it("should return variables with default string if variables are not defined", () => {
Expand All @@ -30,5 +31,6 @@ describe("Config setup", () => {
expect(config.ProjectId).toBe("ENV_VAR_NOT_SET");
expect(config.ServerPark).toBe("ENV_VAR_NOT_SET");
expect(config.BlaiseApiUrl).toBe("http://ENV_VAR_NOT_SET");
expect(config.RoleToServerParksMap).not.toBeNull();
});
});
11 changes: 11 additions & 0 deletions src/ClientConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface ClientConfig {
RoleToServerParksMap: { [key: string]: string[] } ;
}
import role_to_serverparks_map_json from "./role-to-serverparks-map.json";

export function loadConfigFromEnv(): ClientConfig {
const roleToServerParksMap: { [key: string]: string[] } = role_to_serverparks_map_json;
return {
RoleToServerParksMap: roleToServerParksMap
};
}
11 changes: 11 additions & 0 deletions src/pages/users/NewUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { passwordMatchedValidator, requiredValidator } from "../../form/FormVali
import { UserForm } from "../../Interfaces";
import { BreadcrumbItem } from "../../Interfaces";
import Breadcrumbs from "../../Components/Breadcrumbs";
import { loadConfigFromEnv } from "../../ClientConfig";

function NewUserComponent(): ReactElement {
const [buttonLoading, setButtonLoading] = useState<boolean>(false);
Expand All @@ -18,6 +19,7 @@ function NewUserComponent(): ReactElement {
const [message, setMessage] = useState<string>("");
const [redirect, setRedirect] = useState<boolean>(false);
const [roleList, setRoleList] = useState<UserRole[]>([]);
const cconfig = loadConfigFromEnv();

async function createNewUser(formData: UserForm) {
setUsername(formData.username);
Expand All @@ -29,6 +31,15 @@ function NewUserComponent(): ReactElement {
defaultServerPark: "gusty",
serverParks: ["gusty"]
};
const roleServerParksOverride = cconfig.RoleToServerParksMap[role];
if (roleServerParksOverride != null) {
newUser.serverParks = roleServerParksOverride;
newUser.defaultServerPark = roleServerParksOverride[0];
} else {
const defaultServerPark = cconfig.RoleToServerParksMap["DEFAULT"];
newUser.serverParks = defaultServerPark;
newUser.defaultServerPark = defaultServerPark[0];
}

setButtonLoading(true);
const created = await addNewUser(newUser);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/users/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { ReactElement } from "react";
import { UsersTableProps } from "../../Interfaces/usersPage";

function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactElement {

return <>
{
users && users.length > 0
Expand All @@ -18,7 +19,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl
<span>Role</span>
</th>
<th scope="col" className="ons-table__header ">
<span>Default server park</span>
<span>Server Parks</span>
</th>
{/*<th scope="col" className="ons-table__header ">*/}
{/* <span>Edit user</span>*/}
Expand All @@ -33,7 +34,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl
</thead>
<tbody className="ons-table__body">
{
users.map(({ role, defaultServerPark, name }: User) => {
users.map(({ role, name, serverParks }: User) => {
return (
<tr className="ons-table__row" key={name} data-testid={"users-table-row"}>
<td className="ons-table__cell ">
Expand All @@ -43,7 +44,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl
{role}
</td>
<td className="ons-table__cell ">
{defaultServerPark}
{serverParks.join(", ")}
</td>
{/*<td className="ons-table__cell ">*/}
{/* <Link to={"/survey/" + item.name}>Edit</Link>*/}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/users/__snapshots__/Users.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Object {
scope="col"
>
<span>
Default server park
Server Parks
</span>
</th>
<th
Expand Down Expand Up @@ -293,7 +293,7 @@ Object {
scope="col"
>
<span>
Default server park
Server Parks
</span>
</th>
<th
Expand Down
5 changes: 5 additions & 0 deletions src/role-to-serverparks-map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"IPS Manager" : ["gusty", "cma"],
"IPS Field Interviewer" : ["gusty", "cma"],
"DEFAULT" : ["gusty"]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.server.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/* Enable all strict type-checking options. */
/* Module Resolution Options */
"esModuleInterop": true,
"resolveJsonModule": true,
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
/* Advanced Options */
"skipLibCheck": true,
Expand Down

0 comments on commit 78b2aa7

Please sign in to comment.