Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.4 KiB

const sqlServer = require("mssql")
const MSSQLIntegration = require("../microsoftSqlServer")
jest.mock("mssql")
class TestConfiguration {
constructor(config = {}) {
this.integration = new MSSQLIntegration.integration(config)
}
}
describe("MS SQL Server Integration", () => {
let config
beforeEach(() => {
config = new TestConfiguration()
})
it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
})
it("calls the read method with the correct params", async () => {
const sql = "select * from users;"
const response = await config.integration.read({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
})
describe("no rows returned", () => {
beforeEach(async () => {
await config.integration.connect()
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
})
it("returns the correct response when the create response has no rows", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({
sql
})
expect(response).toEqual([{ created: true }])
})
})
})