Fix rest import tests for url and invert dynamic variable invalidation / deletion
This commit is contained in:
parent
6d5d301adb
commit
d0c2d74eb5
|
@ -35,7 +35,6 @@ describe("Curl Import", () => {
|
||||||
it("returns import info", async () => {
|
it("returns import info", async () => {
|
||||||
await init("get")
|
await init("get")
|
||||||
const info = await curl.getInfo()
|
const info = await curl.getInfo()
|
||||||
expect(info.url).toBe("http://example.com")
|
|
||||||
expect(info.name).toBe("example.com")
|
expect(info.name).toBe("example.com")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -67,8 +66,8 @@ describe("Curl Import", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it("populates path", async () => {
|
it("populates path", async () => {
|
||||||
await testPath("get", "")
|
await testPath("get", "http://example.com/")
|
||||||
await testPath("path", "paths/abc")
|
await testPath("path", "http://example.com/paths/abc")
|
||||||
})
|
})
|
||||||
|
|
||||||
const testHeaders = async (file, headers) => {
|
const testHeaders = async (file, headers) => {
|
||||||
|
|
|
@ -41,7 +41,6 @@ describe("OpenAPI2 Import", () => {
|
||||||
const testImportInfo = async (file, extension) => {
|
const testImportInfo = async (file, extension) => {
|
||||||
await init(file, extension)
|
await init(file, extension)
|
||||||
const info = await openapi2.getInfo()
|
const info = await openapi2.getInfo()
|
||||||
expect(info.url).toBe("https://petstore.swagger.io/v2")
|
|
||||||
expect(info.name).toBe("Swagger Petstore")
|
expect(info.name).toBe("Swagger Petstore")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +91,12 @@ describe("OpenAPI2 Import", () => {
|
||||||
|
|
||||||
it("populates path", async () => {
|
it("populates path", async () => {
|
||||||
const assertions = {
|
const assertions = {
|
||||||
"createEntity" : "entities",
|
"createEntity" : "http://example.com/entities",
|
||||||
"getEntities" : "entities",
|
"getEntities" : "http://example.com/entities",
|
||||||
"getEntity" : "entities/{{entityId}}",
|
"getEntity" : "http://example.com/entities/{{entityId}}",
|
||||||
"updateEntity" : "entities/{{entityId}}",
|
"updateEntity" : "http://example.com/entities/{{entityId}}",
|
||||||
"patchEntity" : "entities/{{entityId}}",
|
"patchEntity" : "http://example.com/entities/{{entityId}}",
|
||||||
"deleteEntity" : "entities/{{entityId}}"
|
"deleteEntity" : "http://example.com/entities/{{entityId}}"
|
||||||
}
|
}
|
||||||
await runTests("crud", testPath, assertions)
|
await runTests("crud", testPath, assertions)
|
||||||
})
|
})
|
||||||
|
|
|
@ -51,30 +51,24 @@ describe("Rest Importer", () => {
|
||||||
await init(data)
|
await init(data)
|
||||||
const info = await restImporter.getInfo()
|
const info = await restImporter.getInfo()
|
||||||
expect(info.name).toBe(assertions[key].name)
|
expect(info.name).toBe(assertions[key].name)
|
||||||
expect(info.url).toBe(assertions[key].url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it("gets info", async () => {
|
it("gets info", async () => {
|
||||||
const assertions = {
|
const assertions = {
|
||||||
"oapi2CrudJson" : {
|
"oapi2CrudJson" : {
|
||||||
name: "CRUD",
|
name: "CRUD",
|
||||||
url: "http://example.com"
|
|
||||||
},
|
},
|
||||||
"oapi2CrudYaml" : {
|
"oapi2CrudYaml" : {
|
||||||
name: "CRUD",
|
name: "CRUD",
|
||||||
url: "http://example.com"
|
|
||||||
},
|
},
|
||||||
"oapi2PetstoreJson" : {
|
"oapi2PetstoreJson" : {
|
||||||
name: "Swagger Petstore",
|
name: "Swagger Petstore",
|
||||||
url: "https://petstore.swagger.io/v2"
|
|
||||||
},
|
},
|
||||||
"oapi2PetstoreYaml" :{
|
"oapi2PetstoreYaml" :{
|
||||||
name: "Swagger Petstore",
|
name: "Swagger Petstore",
|
||||||
url: "https://petstore.swagger.io/v2"
|
|
||||||
},
|
},
|
||||||
"curl": {
|
"curl": {
|
||||||
name: "example.com",
|
name: "example.com",
|
||||||
url: "http://example.com"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await runTest(testGetInfo, assertions)
|
await runTest(testGetInfo, assertions)
|
||||||
|
|
|
@ -173,16 +173,16 @@ const removeDynamicVariables = async (db, queryId) => {
|
||||||
const dynamicVariables = datasource.config.dynamicVariables
|
const dynamicVariables = datasource.config.dynamicVariables
|
||||||
|
|
||||||
if (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
|
// invalidate the deleted variables
|
||||||
const variablesToDelete = dynamicVariables.filter(
|
const variablesToDelete = dynamicVariables.filter(
|
||||||
dv => dv.queryId === queryId
|
dv => dv.queryId === queryId
|
||||||
)
|
)
|
||||||
await invalidateDynamicVariables(variablesToDelete)
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue