Convert curl.spec.js
This commit is contained in:
parent
93c10cf17b
commit
5709c3b836
|
@ -1,34 +1,24 @@
|
||||||
const { Curl } = require("../../curl")
|
import { Curl } from "../../curl"
|
||||||
const fs = require("fs")
|
import { readFileSync } from "fs"
|
||||||
const path = require("path")
|
import { join } from "path"
|
||||||
|
|
||||||
const getData = file => {
|
const getData = (file: string) => {
|
||||||
return fs.readFileSync(path.join(__dirname, `./data/${file}.txt`), "utf8")
|
return readFileSync(join(__dirname, `./data/${file}.txt`), "utf8")
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Curl Import", () => {
|
describe("Curl Import", () => {
|
||||||
let curl
|
let curl: Curl
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
curl = new Curl()
|
curl = new Curl()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates unsupported data", async () => {
|
it("validates unsupported data", async () => {
|
||||||
let data
|
expect(await curl.isSupported("{}")).toBe(false)
|
||||||
let supported
|
expect(await curl.isSupported("")).toBe(false)
|
||||||
|
|
||||||
// JSON
|
|
||||||
data = "{}"
|
|
||||||
supported = await curl.isSupported(data)
|
|
||||||
expect(supported).toBe(false)
|
|
||||||
|
|
||||||
// Empty
|
|
||||||
data = ""
|
|
||||||
supported = await curl.isSupported(data)
|
|
||||||
expect(supported).toBe(false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const init = async file => {
|
const init = async (file: string) => {
|
||||||
await curl.isSupported(getData(file))
|
await curl.isSupported(getData(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,14 +29,14 @@ describe("Curl Import", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Returns queries", () => {
|
describe("Returns queries", () => {
|
||||||
const getQueries = async file => {
|
const getQueries = async (file: string) => {
|
||||||
await init(file)
|
await init(file)
|
||||||
const queries = await curl.getQueries()
|
const queries = await curl.getQueries("fake_datasource_id")
|
||||||
expect(queries.length).toBe(1)
|
expect(queries.length).toBe(1)
|
||||||
return queries
|
return queries
|
||||||
}
|
}
|
||||||
|
|
||||||
const testVerb = async (file, verb) => {
|
const testVerb = async (file: string, verb: string) => {
|
||||||
const queries = await getQueries(file)
|
const queries = await getQueries(file)
|
||||||
expect(queries[0].queryVerb).toBe(verb)
|
expect(queries[0].queryVerb).toBe(verb)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +49,7 @@ describe("Curl Import", () => {
|
||||||
await testVerb("patch", "patch")
|
await testVerb("patch", "patch")
|
||||||
})
|
})
|
||||||
|
|
||||||
const testPath = async (file, urlPath) => {
|
const testPath = async (file: string, urlPath: string) => {
|
||||||
const queries = await getQueries(file)
|
const queries = await getQueries(file)
|
||||||
expect(queries[0].fields.path).toBe(urlPath)
|
expect(queries[0].fields.path).toBe(urlPath)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +59,10 @@ describe("Curl Import", () => {
|
||||||
await testPath("path", "http://example.com/paths/abc")
|
await testPath("path", "http://example.com/paths/abc")
|
||||||
})
|
})
|
||||||
|
|
||||||
const testHeaders = async (file, headers) => {
|
const testHeaders = async (
|
||||||
|
file: string,
|
||||||
|
headers: Record<string, string>
|
||||||
|
) => {
|
||||||
const queries = await getQueries(file)
|
const queries = await getQueries(file)
|
||||||
expect(queries[0].fields.headers).toStrictEqual(headers)
|
expect(queries[0].fields.headers).toStrictEqual(headers)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +75,7 @@ describe("Curl Import", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const testQuery = async (file, queryString) => {
|
const testQuery = async (file: string, queryString: string) => {
|
||||||
const queries = await getQueries(file)
|
const queries = await getQueries(file)
|
||||||
expect(queries[0].fields.queryString).toBe(queryString)
|
expect(queries[0].fields.queryString).toBe(queryString)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +84,7 @@ describe("Curl Import", () => {
|
||||||
await testQuery("query", "q1=v1&q1=v2")
|
await testQuery("query", "q1=v1&q1=v2")
|
||||||
})
|
})
|
||||||
|
|
||||||
const testBody = async (file, body) => {
|
const testBody = async (file: string, body?: Record<string, any>) => {
|
||||||
const queries = await getQueries(file)
|
const queries = await getQueries(file)
|
||||||
expect(queries[0].fields.requestBody).toStrictEqual(
|
expect(queries[0].fields.requestBody).toStrictEqual(
|
||||||
JSON.stringify(body, null, 2)
|
JSON.stringify(body, null, 2)
|
Loading…
Reference in New Issue