11import axios from "axios" ;
2- import { getLoggedInUser } from '../utils/user' ;
3- import db from '../utils/db' ;
42import app from '../Server' ;
53import * as reqs from '../utils/request' ;
6- import AuthorizationToken from "../entities/AuthorizationToken" ;
74
85const BB2_BASE_URL = "https://sandbox.bluebutton.cms.gov" ;
96
@@ -23,20 +20,6 @@ const patient = { status: 200, data: { resource: "Patient" } };
2320
2421const 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-
4023let server : any ;
4124
4225beforeAll ( ( ) => {
@@ -48,11 +31,12 @@ afterAll(() => {
4831} ) ;
4932
5033test ( "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
6852test ( "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
8469test ( "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+ } ) ;
0 commit comments