@@ -4,8 +4,10 @@ sourceMapSupport.install();
44import axiosFactory from '@js-entity-repos/axios/dist/factory' ;
55import facadeTest from '@js-entity-repos/core/dist/tests' ;
66import { TestEntity } from '@js-entity-repos/core/dist/tests/utils/testEntity' ;
7+ import * as assert from 'assert' ;
78import axios from 'axios' ;
89import { config } from 'dotenv' ;
10+ import { BAD_REQUEST , OK } from 'http-status-codes' ;
911import 'mocha' ; // tslint:disable-line:no-import-side-effect
1012import createTestServer from './utils/createTestServer' ;
1113config ( ) ;
@@ -31,9 +33,25 @@ after(async () => {
3133 server . close ( ) ;
3234} ) ;
3335
36+ const axiosClient = axios . create ( {
37+ baseURL : `http://localhost:${ testServerPort } ${ testServerRoute } ` ,
38+ } ) ;
39+
3440facadeTest ( axiosFactory < TestEntity > ( {
35- axios : axios . create ( {
36- baseURL : `http://localhost:${ testServerPort } ${ testServerRoute } ` ,
37- } ) ,
41+ axios : axiosClient ,
3842 entityName : 'Test Entity' ,
3943} ) ) ;
44+
45+ describe ( 'facade' , ( ) => {
46+ it ( 'should not throw JSON error' , async ( ) => {
47+ const response = await axiosClient . get ( '/' ) ;
48+ assert . equal ( response . status , OK ) ;
49+ } ) ;
50+ it ( 'should throw JSON error when using invalid filter' , async ( ) => {
51+ await axiosClient . get ( '/?filter=invalid_json' ) . then ( ( response ) => {
52+ return { response } ;
53+ } ) . catch ( ( err ) => {
54+ assert . equal ( err . response . status , BAD_REQUEST ) ;
55+ } ) ;
56+ } ) ;
57+ } ) ;
0 commit comments