Tests WIP
This commit is contained in:
parent
3923fd6831
commit
6f254d3a3b
|
@ -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)
|
||||
})
|
||||
})
|
|
@ -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 () => {
|
||||
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
curl -X DELETE 'http://example.com'
|
|
@ -0,0 +1 @@
|
|||
curl 'http://example.com'
|
|
@ -0,0 +1,3 @@
|
|||
curl 'http://example.com' \
|
||||
-H 'x-bb-header-1: 123' \
|
||||
-H 'x-bb-header-2: 1456'
|
|
@ -0,0 +1,2 @@
|
|||
curl -X PATCH 'http://example.com/paths/abc' \
|
||||
--data-raw '{ "key" : "val" }'
|
|
@ -0,0 +1 @@
|
|||
curl 'http://example.com/paths/abc'
|
|
@ -0,0 +1,2 @@
|
|||
curl -X POST 'http://example.com' \
|
||||
--data-raw '{ "key" : "val" }'
|
|
@ -0,0 +1,2 @@
|
|||
curl -X PUT 'http://example.com/paths/abc' \
|
||||
--data-raw '{ "key" : "val" }'
|
|
@ -0,0 +1 @@
|
|||
curl 'http://example.com/paths/abc?q1=v1&q1=v2'
|
Loading…
Reference in New Issue