@@ -4,8 +4,10 @@ sourceMapSupport.install();
4
4
import axiosFactory from '@js-entity-repos/axios/dist/factory' ;
5
5
import facadeTest from '@js-entity-repos/core/dist/tests' ;
6
6
import { TestEntity } from '@js-entity-repos/core/dist/tests/utils/testEntity' ;
7
+ import * as assert from 'assert' ;
7
8
import axios from 'axios' ;
8
9
import { config } from 'dotenv' ;
10
+ import { BAD_REQUEST , OK } from 'http-status-codes' ;
9
11
import 'mocha' ; // tslint:disable-line:no-import-side-effect
10
12
import createTestServer from './utils/createTestServer' ;
11
13
config ( ) ;
@@ -31,9 +33,25 @@ after(async () => {
31
33
server . close ( ) ;
32
34
} ) ;
33
35
36
+ const axiosClient = axios . create ( {
37
+ baseURL : `http://localhost:${ testServerPort } ${ testServerRoute } ` ,
38
+ } ) ;
39
+
34
40
facadeTest ( axiosFactory < TestEntity > ( {
35
- axios : axios . create ( {
36
- baseURL : `http://localhost:${ testServerPort } ${ testServerRoute } ` ,
37
- } ) ,
41
+ axios : axiosClient ,
38
42
entityName : 'Test Entity' ,
39
43
} ) ) ;
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