diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/curl.spec.js deleted file mode 100644 index da90f4a61c..0000000000 --- a/packages/server/src/api/controllers/query/import/sources/tests/curl.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -// const Airtable = require("airtable") -// const AirtableIntegration = require("../airtable") - -jest.mock("airtable") - -// class TestConfiguration { -// constructor(config = {}) { -// this.integration = new AirtableIntegration.integration(config) -// this.client = { -// create: jest.fn(), -// select: jest.fn(), -// update: jest.fn(), -// destroy: jest.fn(), -// } -// this.integration.client = () => this.client -// } -// } - -describe("Airtable Integration", () => { - let config - - beforeEach(() => { - config = new TestConfiguration() - }) - - it("calls the create method with the correct params", async () => { - const response = await config.integration.create({ - table: "test", - json: {} - }) - expect(config.client.create).toHaveBeenCalledWith([ - { - fields: {} - } - ]) - }) - - it("calls the read method with the correct params", async () => { - const response = await config.integration.read({ - table: "test", - view: "Grid view" - }) - expect(config.client.select).toHaveBeenCalledWith({ - maxRecords: 10, view: "Grid view" - }) - }) - - it("calls the update method with the correct params", async () => { - const response = await config.integration.update({ - table: "test", - id: "123", - json: { - name: "test" - } - }) - expect(config.client.update).toHaveBeenCalledWith([ - { - id: "123", - fields: { name: "test" } - } - ]) - }) - - it("calls the delete method with the correct params", async () => { - const ids = [1,2,3,4] - const response = await config.integration.delete({ - ids - }) - expect(config.client.destroy).toHaveBeenCalledWith(ids) - }) -}) \ No newline at end of file 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 new file mode 100644 index 0000000000..6fc6008b0d --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js @@ -0,0 +1,88 @@ +// const Airtable = require("airtable") +// const AirtableIntegration = require("../airtable") +const { Curl } = require("../../curl") +const fs = require("fs") +const path = require('path') +jest.mock("airtable") + +// class TestConfiguration { +// constructor(config = {}) { +// this.integration = new AirtableIntegration.integration(config) +// this.client = { +// create: jest.fn(), +// select: jest.fn(), +// update: jest.fn(), +// destroy: jest.fn(), +// } +// this.integration.client = () => this.client +// } +// } + +const getData = (file) => { + return fs.readFileSync(path.join(__dirname, `./data/${file}.txt`), "utf8") +} +describe("Curl Import", () => { + let curl + + beforeEach(() => { + curl = new Curl() + }) + + it("validates unsupported data", async () => { + let data + let supported + + // JSON + data = "{}" + supported = await curl.isSupported(data) + expect(supported).toBe(false) + + // Empty + data = "" + supported = await curl.isSupported(data) + expect(supported).toBe(false) + }) + + it("returns import info", async () => { + const data = getData() + await curl.isSupported(data) + const info = await curl.getInfo() + expect(info.url).toBe("http://example.com") + expect(info.name).toBe("example.com") + }) + + describe("Returns queries", () => { + describe("populates verb", () => { + const testVerb = async (file, verb) => { + const data = getData(file) + await curl.isSupported(data) + const queries = await curl.getQueries(data) + expect(queries.length).toBe(1) + expect(queries[0].verb).toBe(verb) + } + it("populates verb", async () => { + await testVerb("get", "read") + await testVerb("post", "create") + await testVerb("put", "update") + await testVerb("delete", "delete") + await testVerb("patch", "patch") + }) + }) + + it("populates path", async () => { + + }) + + it("populates headers", async () => { + + }) + + it("populates query", async () => { + + }) + + it("populates body", async () => { + + }) + }) +}) \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/delete.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/delete.txt new file mode 100644 index 0000000000..93e70d2460 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/delete.txt @@ -0,0 +1 @@ +curl -X DELETE 'http://example.com' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/get.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/get.txt new file mode 100644 index 0000000000..6ac7b0e3d1 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/get.txt @@ -0,0 +1 @@ +curl 'http://example.com' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/headers.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/headers.txt new file mode 100644 index 0000000000..aba6d05cbf --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/headers.txt @@ -0,0 +1,3 @@ +curl 'http://example.com' \ + -H 'x-bb-header-1: 123' \ + -H 'x-bb-header-2: 1456' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/patch.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/patch.txt new file mode 100644 index 0000000000..0556f5b2d2 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/patch.txt @@ -0,0 +1,2 @@ +curl -X PATCH 'http://example.com/paths/abc' \ + --data-raw '{ "key" : "val" }' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/path.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/path.txt new file mode 100644 index 0000000000..d4c18f49b5 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/path.txt @@ -0,0 +1 @@ +curl 'http://example.com/paths/abc' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/post.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/post.txt new file mode 100644 index 0000000000..f86c43e1d3 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/post.txt @@ -0,0 +1,2 @@ +curl -X POST 'http://example.com' \ + --data-raw '{ "key" : "val" }' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/put.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/put.txt new file mode 100644 index 0000000000..7e4aef4835 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/put.txt @@ -0,0 +1,2 @@ +curl -X PUT 'http://example.com/paths/abc' \ + --data-raw '{ "key" : "val" }' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/data/query.txt b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/query.txt new file mode 100644 index 0000000000..cb031e7537 --- /dev/null +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/data/query.txt @@ -0,0 +1 @@ +curl 'http://example.com/paths/abc?q1=v1&q1=v2' \ No newline at end of file diff --git a/packages/server/src/api/controllers/query/import/sources/tests/openapi2.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js similarity index 100% rename from packages/server/src/api/controllers/query/import/sources/tests/openapi2.spec.js rename to packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js diff --git a/packages/server/src/api/controllers/query/import/sources/tests/openapi.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/openapi3/openapi3.spec.js similarity index 100% rename from packages/server/src/api/controllers/query/import/sources/tests/openapi.spec.js rename to packages/server/src/api/controllers/query/import/sources/tests/openapi3/openapi3.spec.js