Skip to content

Commit

Permalink
fix: Fix formatting: yarn eslint . --fix
Browse files Browse the repository at this point in the history
fix: Add typemoq as dependency
  • Loading branch information
am-ons committed Jun 20, 2024
1 parent 6cca8d8 commit e578bd6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"formik": "2.4.2"
},
"dependencies": {
"formik": "2.4.2",
"@google-cloud/profiler": "^4.1.1",
"@testing-library/dom": "^8.3.0",
"@testing-library/jest-dom": "^5.16.4",
Expand All @@ -43,6 +42,7 @@
"dotenv": "^10.0.0",
"ejs": "^3.1.7",
"express": "^4.19.2",
"formik": "2.4.2",
"history": "^4.9.0",
"jest-cucumber": "^3.0.0",
"lodash": "^4.17.21",
Expand All @@ -56,6 +56,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.0",
"react-scripts": "5.0.0",
"typemoq": "^2.1.0",
"typescript": "~5.3.3"
},
"devDependencies": {
Expand Down
15 changes: 7 additions & 8 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import * as profiler from "@google-cloud/profiler";
import { newLoginHandler, Auth } from "blaise-login-react/blaise-login-react-server";
import pino from "pino";
import { CustomConfig } from "./interfaces/server";
import BlaiseApi from "blaise-api-node-client"
import { Express } from 'express';
import fs from 'fs';
import BlaiseApi from "blaise-api-node-client";
import { Express } from "express";
import fs from "fs";


export default function GetNodeServer(config: CustomConfig, blaiseApi: BlaiseApi, auth: Auth): Express
export default function GetNodeServer(config: CustomConfig, blaiseApi: BlaiseApi, auth: Auth): Express
{
const pinoLogger = pino();
profiler.start({ logLevel: 4 }).catch((err: unknown) => {
Expand Down Expand Up @@ -60,11 +59,11 @@ export default function GetNodeServer(config: CustomConfig, blaiseApi: BlaiseApi
"/static",
express.static(path.join(__dirname, `${buildFolder}/static`))
);

let indexFilePath = path.join(__dirname, `${buildFolder}/index.html`);
if (!fs.existsSync(indexFilePath)) {
indexFilePath = path.join(__dirname, `../public/index.html`);
}
indexFilePath = path.join(__dirname, "../public/index.html");
}
server.get("*", function (_req: Request, res: Response) {
res.render(indexFilePath);
});
Expand Down
23 changes: 11 additions & 12 deletions server/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import supertest from "supertest";
import GetNodeServer from "../server";
import { loadConfigFromEnv } from "../Config";
import BlaiseApiClient, {NewUser, User} from "blaise-api-node-client";
import BlaiseApiClient, { NewUser, User } from "blaise-api-node-client";
import { Auth } from "blaise-login-react/blaise-login-react-server";
import { IMock, Mock, It, Times } from "typemoq";
import { IMock, Mock, It, Times } from "typemoq";

// Temporary fix for Jest open handle issue (gcp profiler TCPWRAP error)
jest.mock("@google-cloud/profiler", () => ({
Expand All @@ -21,9 +21,8 @@ const auth = new Auth(config);
const server = GetNodeServer(config, blaiseApiMock.object, auth);
const sut = supertest(server);


describe("Test Heath Endpoint", () => {

it("should return a 200 status and json message", async () => {
const response = await sut.get("/bam-ui/version/health");

Expand All @@ -33,7 +32,7 @@ describe("Test Heath Endpoint", () => {
});

describe("app engine start", () => {

it("should return a 200 status and json message", async () => {
process.env = Object.assign({
PROJECT_ID: "mock",
Expand All @@ -48,7 +47,7 @@ describe("app engine start", () => {
});
});

import role_to_serverparks_map from '../role-to-serverparks-map.json'
import role_to_serverparks_map from "../role-to-serverparks-map.json";
import { size } from "lodash";
describe("Test /api/users POST endpoint", () => {
beforeEach(() => {
Expand All @@ -61,8 +60,8 @@ describe("Test /api/users POST endpoint", () => {

it("should call Blaise API createUser endpoint with correct serverParks for each role EXISTING in server/role-to-serverparks-map.json and return http status 200", async () => {
let currentRoleNo = 0;
let totalRoleCount = size(role_to_serverparks_map);
for(let roleName in role_to_serverparks_map)
const totalRoleCount = size(role_to_serverparks_map);
for(const roleName in role_to_serverparks_map)
{
blaiseApiMock.reset();
console.log("Running for role %i of %i: %s", ++currentRoleNo, totalRoleCount, roleName);
Expand All @@ -76,13 +75,13 @@ describe("Test /api/users POST endpoint", () => {
defaultServerPark: spmap[0]
};
blaiseApiMock.setup((api) => api.createUser(It.isAny())).returns(async () => newUser);

const response = await sut.post("/api/users")
.field("role", roleName);

expect(response.statusCode).toEqual(200);
blaiseApiMock.verify(a => a.createUser(It.is<NewUser>(
x=> x.defaultServerPark == newUser.defaultServerPark
x=> x.defaultServerPark == newUser.defaultServerPark
&& x.role == newUser.role
&& Array.isArray(x.serverParks) && x.serverParks.every(item => typeof item === "string")
&& x.serverParks.every((val, idx) => val === newUser.serverParks[idx])
Expand All @@ -102,13 +101,13 @@ describe("Test /api/users POST endpoint", () => {
defaultServerPark: spmap[0]
};
blaiseApiMock.setup((api) => api.createUser(It.isAny())).returns(async () => newUser);

const response = await sut.post("/api/users")
.field("role", roleName);

expect(response.statusCode).toEqual(200);
blaiseApiMock.verify(a => a.createUser(It.is<NewUser>(
x=> x.defaultServerPark == newUser.defaultServerPark
x=> x.defaultServerPark == newUser.defaultServerPark
&& x.role == newUser.role
&& Array.isArray(x.serverParks) && x.serverParks.every(item => typeof item === "string")
&& x.serverParks.every((val, idx) => val === newUser.serverParks[idx])
Expand Down
21 changes: 20 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6127,6 +6127,11 @@ ci-info@^3.2.0:
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91"
integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==

circular-json@^0.3.1:
version "0.3.3"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
integrity sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==

citty@^0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/citty/-/citty-0.1.6.tgz#0f7904da1ed4625e1a9ea7e0fa780981aab7c5e4"
Expand Down Expand Up @@ -11396,7 +11401,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==

lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.7.0:
lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -13195,6 +13200,11 @@ postcss@^8.3.5, postcss@^8.4.23, postcss@^8.4.33, postcss@^8.4.4:
picocolors "^1.0.0"
source-map-js "^1.2.0"

postinstall-build@^5.0.1:
version "5.0.3"
resolved "https://registry.yarnpkg.com/postinstall-build/-/postinstall-build-5.0.3.tgz#238692f712a481d8f5bc8960e94786036241efc7"
integrity sha512-vPvPe8TKgp4FLgY3+DfxCE5PIfoXBK2lyLfNCxsRbDsV6vS4oU5RG/IWxrblMn6heagbnMED3MemUQllQ2bQUg==

[email protected]:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pprof/-/pprof-3.2.0.tgz#5a60638dc51a61128a3d57c74514e8fd99e93722"
Expand Down Expand Up @@ -15744,6 +15754,15 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==

typemoq@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/typemoq/-/typemoq-2.1.0.tgz#4452ce360d92cf2a1a180f0c29de2803f87af1e8"
integrity sha512-DtRNLb7x8yCTv/KHlwes+NI+aGb4Vl1iPC63Hhtcvk1DpxSAZzKWQv0RQFY0jX2Uqj0SDBNl8Na4e6MV6TNDgw==
dependencies:
circular-json "^0.3.1"
lodash "^4.17.4"
postinstall-build "^5.0.1"

typescript@~4.2.2:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
Expand Down

0 comments on commit e578bd6

Please sign in to comment.