Skip to content

Commit 8246d35

Browse files
author
JAMES FUQIAN
committed
fix eob unit test and linting.
1 parent c45bd72 commit 8246d35

4 files changed

Lines changed: 32 additions & 62 deletions

File tree

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import axios from "axios";
2-
import { getLoggedInUser } from '../utils/user';
3-
import db from '../utils/db';
42
import app from '../Server';
53
import * as reqs from '../utils/request';
6-
import AuthorizationToken from "../entities/AuthorizationToken";
74

85
const BB2_BASE_URL = "https://sandbox.bluebutton.cms.gov";
96

@@ -23,20 +20,6 @@ const patient = { status: 200, data: { resource: "Patient" } };
2320

2421
const profile = { status: 200, data: { resource: "Profile" } };
2522

26-
const MOCK_AUTH_TOKEN_RESPONSE = {
27-
status: 200,
28-
data: {
29-
access_token: "access_token_foo_refreshed",
30-
expires_in: 36000,
31-
token_type: "Bearer",
32-
scope: ["scope1", "scope2", "scope3"],
33-
refresh_token: "refresh_token_bar_refreshed",
34-
patient: "-19990000000001",
35-
},
36-
};
37-
38-
const MOCK_AUTH_TOKEN = new AuthorizationToken(MOCK_AUTH_TOKEN_RESPONSE.data);
39-
4023
let server: any;
4124

4225
beforeAll(() => {
@@ -48,11 +31,12 @@ afterAll(() => {
4831
});
4932

5033
test("expect patient end point returns patient data.", async () => {
34+
jest.clearAllMocks();
5135
// mock patient returned at deeper layer
5236
jest.spyOn(reqs, 'get').mockImplementation((url) =>
5337
{
5438
if (url === BB2_PATIENT_URL) {
55-
return Promise.resolve(patient);
39+
return Promise.resolve(patient);
5640
} else {
5741
throw Error("Invalid end point URL: " + url);
5842
}
@@ -66,6 +50,7 @@ test("expect patient end point returns patient data.", async () => {
6650
});
6751

6852
test("expect profile end point returns profile data.", async () => {
53+
jest.clearAllMocks();
6954
// mock profile returned at lower level get
7055
jest.spyOn(reqs, 'get').mockImplementation((url) =>
7156
{
@@ -82,11 +67,12 @@ test("expect profile end point returns profile data.", async () => {
8267
});
8368

8469
test("expect coverage end point returns coverage data.", async () => {
70+
jest.clearAllMocks();
8571
// mock coverage returned at deeper layer
8672
jest.spyOn(reqs, 'get').mockImplementation((url) =>
8773
{
8874
if (url === BB2_COVERAGE_URL) {
89-
return Promise.resolve(coverage);
75+
return Promise.resolve(coverage);
9076
} else {
9177
throw Error("Invalid end point URL: " + url);
9278
}
@@ -99,23 +85,20 @@ test("expect coverage end point returns coverage data.", async () => {
9985
expect(response.data).toEqual(coverage.data);
10086
});
10187

102-
//test("expect eob end point returns eob data.", async () => {
103-
// const loggedInUser = getLoggedInUser(db);
104-
//
105-
// loggedInUser.authToken = MOCK_AUTH_TOKEN;
106-
//
107-
// // mock eob returned at lower level get
108-
// jest.spyOn(reqs, 'get').mockImplementation((url) =>
109-
// {
110-
// if (url === BB2_EOB_URL) {
111-
// return Promise.resolve(eob);
112-
// } else {
113-
// throw Error("Invalid end point URL: " + url);
114-
// }
115-
// }
116-
// );
117-
//
118-
// const response = await axios.get("http://localhost:3003/api/data/benefit-direct");
119-
// expect(response.status).toEqual(200);
120-
// expect(response.data).toEqual(eob.data);
121-
//});
88+
test("expect eob end point returns eob data.", async () => {
89+
jest.clearAllMocks();
90+
// mock eob returned at lower level get
91+
jest.spyOn(reqs, 'get').mockImplementation((url) =>
92+
{
93+
if (url === BB2_EOB_URL) {
94+
return Promise.resolve(eob);
95+
} else {
96+
throw Error("Invalid end point URL: " + url);
97+
}
98+
}
99+
);
100+
101+
const response = await axios.get("http://localhost:3003/api/data/benefit-direct");
102+
expect(response.status).toEqual(200);
103+
expect(response.data).toEqual(eob.data);
104+
});

server/src/configs/sample.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const config: ConfigType = {
2727
bb2BaseUrl: 'https://sandbox.bluebutton.cms.gov',
2828
bb2ClientId: '<client-id>',
2929
bb2ClientSecret: '<client-secret>',
30-
bb2CallbackUrl: SELENIUM_TESTS ? 'http://server:3001/api/bluebutton/callback/' : 'http://localhost:3001/api/bluebutton/callback/',
30+
bb2CallbackUrl: SELENIUM_TESTS ?
31+
'http://server:3001/api/bluebutton/callback/'
32+
: 'http://localhost:3001/api/bluebutton/callback/',
3133
},
3234
local: {
3335
bb2BaseUrl: 'https://sandbox.bluebutton.cms.gov',

server/src/routes/Authorize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export async function authorizationCallback(req: Request, res: Response) {
7676
* This is a hardcoded redirect, but this should be used from settings stored in a conf file
7777
* or other mechanism
7878
*/
79-
const fe_redirect_url = process.env.SELENIUM_TESTS ? 'http://client:3000' : 'http://localhost:3000';
79+
const fe_redirect_url =
80+
process.env.SELENIUM_TESTS ? 'http://client:3000' : 'http://localhost:3000';
8081
res.redirect(fe_redirect_url);
8182
}
8283

server/src/routes/Data.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Router, Request, Response } from 'express';
2-
import moment from 'moment';
32
import { getLoggedInUser } from '../utils/user';
4-
import { refreshAccessToken } from '../utils/bb2';
53
import config from '../configs/config';
64
import db from '../utils/db';
75
import { get } from '../utils/request';
@@ -22,25 +20,11 @@ function getURL(path: string): string {
2220
// user and returned - we are then storing in a mocked DB
2321
export async function getBenefitData(req: Request, res: Response) {
2422
const loggedInUser = getLoggedInUser(db);
25-
const FHIR_EOB_PATH = 'fhir/ExplanationOfBenefit/';
26-
const BB2_BENEFIT_URL = getURL(FHIR_EOB_PATH);
27-
28-
29-
if (!loggedInUser.authToken || !loggedInUser.authToken.accessToken) {
30-
return { data: {} };
31-
}
32-
33-
/*
34-
* If the access token is expired, use the refresh token to generate a new one
35-
*/
36-
if (moment(loggedInUser.authToken.expiresAt).isBefore(moment())) {
37-
const newAuthToken = await refreshAccessToken(loggedInUser.authToken.refreshToken);
38-
loggedInUser.authToken = newAuthToken;
39-
}
40-
41-
const response = await get(BB2_BENEFIT_URL, req.query, `${loggedInUser.authToken?.accessToken}`);
42-
43-
return response.data as Record<string, unknown>;
23+
// get EOB end point
24+
const response = await get(getURL('fhir/ExplanationOfBenefit/'),
25+
req.query,
26+
`${loggedInUser.authToken?.accessToken || 'no access token'}`);
27+
res.json(response.data);
4428
}
4529

4630
/*

0 commit comments

Comments
 (0)