From d0c2d74eb5a73335bbb1132f4c8b940fcc9777ba Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 5 Jan 2022 14:49:01 -0500 Subject: [PATCH] Fix rest import tests for url and invert dynamic variable invalidation / deletion --- .../query/import/sources/tests/curl/curl.spec.js | 5 ++--- .../import/sources/tests/openapi2/openapi2.spec.js | 13 ++++++------- .../controllers/query/import/tests/index.spec.js | 6 ------ packages/server/src/api/controllers/query/index.js | 10 +++++----- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js index 11869862f7..2b17685f24 100644 --- a/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js @@ -35,7 +35,6 @@ describe("Curl Import", () => { it("returns import info", async () => { await init("get") const info = await curl.getInfo() - expect(info.url).toBe("http://example.com") expect(info.name).toBe("example.com") }) @@ -67,8 +66,8 @@ describe("Curl Import", () => { } it("populates path", async () => { - await testPath("get", "") - await testPath("path", "paths/abc") + await testPath("get", "http://example.com/") + await testPath("path", "http://example.com/paths/abc") }) const testHeaders = async (file, headers) => { diff --git a/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js index 845c4f38f6..3c5aa89e3c 100644 --- a/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +++ b/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js @@ -41,7 +41,6 @@ describe("OpenAPI2 Import", () => { const testImportInfo = async (file, extension) => { await init(file, extension) const info = await openapi2.getInfo() - expect(info.url).toBe("https://petstore.swagger.io/v2") expect(info.name).toBe("Swagger Petstore") } @@ -92,12 +91,12 @@ describe("OpenAPI2 Import", () => { it("populates path", async () => { const assertions = { - "createEntity" : "entities", - "getEntities" : "entities", - "getEntity" : "entities/{{entityId}}", - "updateEntity" : "entities/{{entityId}}", - "patchEntity" : "entities/{{entityId}}", - "deleteEntity" : "entities/{{entityId}}" + "createEntity" : "http://example.com/entities", + "getEntities" : "http://example.com/entities", + "getEntity" : "http://example.com/entities/{{entityId}}", + "updateEntity" : "http://example.com/entities/{{entityId}}", + "patchEntity" : "http://example.com/entities/{{entityId}}", + "deleteEntity" : "http://example.com/entities/{{entityId}}" } await runTests("crud", testPath, assertions) }) diff --git a/packages/server/src/api/controllers/query/import/tests/index.spec.js b/packages/server/src/api/controllers/query/import/tests/index.spec.js index 32f3b43b44..5a509d2258 100644 --- a/packages/server/src/api/controllers/query/import/tests/index.spec.js +++ b/packages/server/src/api/controllers/query/import/tests/index.spec.js @@ -51,30 +51,24 @@ describe("Rest Importer", () => { await init(data) const info = await restImporter.getInfo() expect(info.name).toBe(assertions[key].name) - expect(info.url).toBe(assertions[key].url) } it("gets info", async () => { const assertions = { "oapi2CrudJson" : { name: "CRUD", - url: "http://example.com" }, "oapi2CrudYaml" : { name: "CRUD", - url: "http://example.com" }, "oapi2PetstoreJson" : { name: "Swagger Petstore", - url: "https://petstore.swagger.io/v2" }, "oapi2PetstoreYaml" :{ name: "Swagger Petstore", - url: "https://petstore.swagger.io/v2" }, "curl": { name: "example.com", - url: "http://example.com" } } await runTest(testGetInfo, assertions) diff --git a/packages/server/src/api/controllers/query/index.js b/packages/server/src/api/controllers/query/index.js index ea2042ad49..6e5fdfb356 100644 --- a/packages/server/src/api/controllers/query/index.js +++ b/packages/server/src/api/controllers/query/index.js @@ -173,16 +173,16 @@ const removeDynamicVariables = async (db, queryId) => { const dynamicVariables = datasource.config.dynamicVariables if (dynamicVariables) { + // delete dynamic variables from the datasource + const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId) + datasource.config.dynamicVariables = newVariables + await db.put(datasource) + // invalidate the deleted variables const variablesToDelete = dynamicVariables.filter( dv => dv.queryId === queryId ) await invalidateDynamicVariables(variablesToDelete) - - // delete dynamic variables from the datasource - const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId) - datasource.config.dynamicVariables = newVariables - await db.put(datasource) } }