import * as SUT from '../index' ; describe ( 'mock creators' , ( ) : void => { beforeEach ( ( ) : void => { } ) ; test ( 'should return a mock for GET json depending on query string' , async ( ) : Promise < void > => { const response = { prop1 : 'value1' , prop2 : 'value2' , } ; const relativeUrl = '/api/yo' ; const mock = SUT . mockGetWithJsonResponseDependingOnQueryString ( relativeUrl , { foo : 'bar' } , response ) ; expect ( mock . displayName ) . toBe ( 'GET /api/yo?foo=bar' ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/yo?foo=baz` ) ) . toBe ( true ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/go?foo=baz` ) ) . toBe ( false ) ; expect ( mock . queryStringMatcher ! ( { foo : 'bar' } ) ) . toBe ( true ) ; expect ( mock . queryStringMatcher ! ( { foo : 'bar' , bar : 'baz' } ) ) . toBe ( true ) ; expect ( mock . queryStringMatcher ! ( { bar : 'baz' } ) ) . toBe ( false ) ; expect ( mock . queryStringMatcher ! ( { } ) ) . toBe ( false ) ; } ) ; test ( 'should return a mock for GET json' , async ( ) : Promise < void > => { const response = { prop1 : 'value1' , prop2 : 'value2' , } ; const mock = SUT . mockGetWithJsonResponse ( '/api/yo' , response ) ; expect ( mock . displayName ) . toBe ( 'GET /api/yo' ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/yo?foo=baz` ) ) . toBe ( true ) ; } ) ; test ( 'should return a mock for GET javascript' , async ( ) : Promise < void > => { const response = `window.foo = 'bar';` ; const mock = SUT . mockGetWithJavascriptResponse ( '/api/foo.js' , response ) ; expect ( mock . displayName ) . toBe ( 'GET /api/foo.js' ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/foo.js` ) ) . toBe ( true ) ; expect ( mock . responseType ) . toBe ( 'javascript' ) ; expect ( typeof mock . rawResponse ) . toBe ( 'function' ) ; } ) ; test ( 'should return a mock for GET that returns a 401' , async ( ) : Promise < void > => { const mock = SUT . mockGetWithUnauthorizedResponse ( '/api/foo.js' ) ; expect ( mock . displayName ) . toBe ( 'GET /api/foo.js' ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/foo.js` ) ) . toBe ( true ) ; expect ( mock . responseType ) . toBe ( 'empty' ) ; expect ( typeof mock . methodMatcher ) . toBe ( 'function' ) ; expect ( mock . methodMatcher ! ( `GET` ) ) . toBe ( true ) ; expect ( mock . status ) . toBe ( 401 ) ; } ) ; test ( 'should return a mock for GET that returns a 403' , async ( ) : Promise < void > => { const mock = SUT . mockGetWithForbiddenResponse ( '/api/foo.js' ) ; expect ( mock . displayName ) . toBe ( 'GET /api/foo.js' ) ; expect ( mock . urlMatcher ! ( `https://yo.com/api/foo.js` ) ) . toBe ( true ) ; expect ( mock . responseType ) . toBe ( 'empty' ) ; expect ( typeof mock . methodMatcher ) . toBe ( 'function' ) ; expect ( mock . methodMatcher ! ( `GET` ) ) . toBe ( true ) ; expect ( mock . status ) . toBe ( 403 ) ; } ) ; } ) ;