2021-03-16 14:54:39 +01:00
|
|
|
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
|
|
|
|
})
|
2021-06-25 14:46:02 +02:00
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
|
2021-03-16 14:54:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the read method with the correct params", async () => {
|
|
|
|
const sql = "select * from users;"
|
|
|
|
const response = await config.integration.read({
|
|
|
|
sql
|
|
|
|
})
|
2021-06-25 14:46:02 +02:00
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
|
2021-03-16 14:54:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("no rows returned", () => {
|
2021-05-24 13:14:04 +02:00
|
|
|
beforeEach(async () => {
|
|
|
|
await config.integration.connect()
|
2021-03-16 14:54:39 +01:00
|
|
|
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 }])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|