diff --git a/src/test/metaData/import.spec.ts b/src/test/metaData/import.spec.ts index 06f49770..187e9c36 100644 --- a/src/test/metaData/import.spec.ts +++ b/src/test/metaData/import.spec.ts @@ -4,14 +4,14 @@ import { getLocal } from 'mockttp'; describe('metadata.import', () => { const localServer = getLocal(); - beforeEach(() => localServer.start(8005)); + beforeEach(() => localServer.start(8008)); afterEach(() => localServer.stop()); it('name + import + ref', async () => { initFileProvider({ 'import.http': ` # @name foo -GET http://localhost:8005/json +GET http://localhost:8008/json `, }); await localServer.forGet('/json').thenJson(200, { foo: 'bar', test: 1 }); @@ -20,7 +20,7 @@ GET http://localhost:8005/json # @import ./import.http ### # @ref foo -POST http://localhost:8005/post?test={{foo.test}} +POST http://localhost:8008/post?test={{foo.test}} foo={{foo.foo}} `); @@ -31,7 +31,7 @@ foo={{foo.foo}} }); const requests = await mockedEndpoints.getSeenRequests(); - expect(requests[0].url).toBe('http://localhost:8005/post?test=1'); + expect(requests[0].url).toBe('http://localhost:8008/post?test=1'); expect(await requests[0].body.getText()).toBe('foo=bar'); }); it('import global variable', async () => { @@ -45,7 +45,7 @@ foo={{foo.foo}} const mockedEndpoints = await localServer.forPost('/post').thenReply(200); const httpFile = await parseHttp(` # @import ./import.http -POST http://localhost:8005/post?foo={{foo}} +POST http://localhost:8008/post?foo={{foo}} bar={{bar}} `); @@ -56,7 +56,7 @@ bar={{bar}} }); const requests = await mockedEndpoints.getSeenRequests(); - expect(requests[0].url).toBe('http://localhost:8005/post?foo=bar'); + expect(requests[0].url).toBe('http://localhost:8008/post?foo=bar'); expect(await requests[0].body.getText()).toBe('bar=foo'); }); it('import named variable', async () => { @@ -73,7 +73,7 @@ bar={{bar}} const httpFile = await parseHttp(` # @import ./import.http # @ref test -POST http://localhost:8005/post?foo={{foo}} +POST http://localhost:8008/post?foo={{foo}} bar={{bar}} `); @@ -84,7 +84,42 @@ bar={{bar}} }); const requests = await mockedEndpoints.getSeenRequests(); - expect(requests[0].url).toBe('http://localhost:8005/post?foo=bar'); + expect(requests[0].url).toBe('http://localhost:8008/post?foo=bar'); expect(await requests[0].body.getText()).toBe('bar=foo'); }); + it('import request with using global host variable', async () => { + initFileProvider({ + 'import.http': ` + @host=http://localhost:8008 + + ### Apple + # @name send_apple + POST /anything + Content-Type: application/json + + { + "id": "0001", + "type": "fruit", + "name": "Apple" + } + `, + }); + await localServer.forGet('/json').thenJson(200, { foo: 'bar', test: 1 }); + const mockedEndpoints = await localServer.forPost('/anything').thenReply(200); + const httpFile = await parseHttp(` +# @import ./import.http + +### +# @forceRef send_apple + `); + + await send({ + httpFile, + httpRegion: httpFile.httpRegions[1], + }); + + const requests = await mockedEndpoints.getSeenRequests(); + expect(requests[0].url).toBe('http://localhost:8008/anything'); + expect(requests[0].headers['content-type']).toBe('application/json'); + }); });