@@ -2,12 +2,54 @@ import { fetch } from 'whatwg-fetch';
22import { setupContext , teardownContext } from '@ember/test-helpers' ;
33import param from 'jquery-param' ;
44
5+ let cleanupMocks = function ( ) {
6+ return fetch ( '/__cleanup-mocks' ) ;
7+ } ;
8+
9+ let createMock = async function ( path , method , statusCode , response ) {
10+ return await fetch ( '/__mock-request' , {
11+ method : 'post' ,
12+ headers : {
13+ "Content-Type" : "application/json" ,
14+ } ,
15+ body : JSON . stringify ( {
16+ path,
17+ method,
18+ statusCode,
19+ response
20+ } ) ,
21+ } ) ;
22+ }
23+
24+ export let mockServer = {
25+ async get ( path , response , status = 200 ) {
26+ return createMock ( path , "GET" , status , response ) ;
27+ } ,
28+
29+ async post ( path , response , status = 200 ) {
30+ return createMock ( path , "POST" , status , response ) ;
31+ } ,
32+
33+ async patch ( path , response , status = 200 ) {
34+ return createMock ( path , "PATCH" , status , response ) ;
35+ } ,
36+
37+ async put ( path , response , status = 200 ) {
38+ return createMock ( path , "PUT" , status , response ) ;
39+ } ,
40+
41+ async delete ( path , response , status = 200 ) {
42+ return createMock ( path , "DELETE" , status , response ) ;
43+ }
44+ } ;
45+
546export function setup ( hooks ) {
647 hooks . beforeEach ( function ( ) {
748 return setupContext ( this ) ;
849 } ) ;
950
10- hooks . afterEach ( function ( ) {
51+ hooks . afterEach ( async function ( ) {
52+ await cleanupMocks ( ) ;
1153 return teardownContext ( this ) ;
1254 } ) ;
1355}
0 commit comments