Reworking MS-SQL test case to be able to get the sql now with a request being made for each internal query, rather than just at connection.
This commit is contained in:
parent
2f1c22085c
commit
a78230e23b
|
@ -15,7 +15,7 @@ module MsSqlMock {
|
||||||
mssql.ConnectionPool = jest.fn(() => ({
|
mssql.ConnectionPool = jest.fn(() => ({
|
||||||
connect: jest.fn(() => ({
|
connect: jest.fn(() => ({
|
||||||
request: jest.fn(() => ({
|
request: jest.fn(() => ({
|
||||||
query: jest.fn(() => ({})),
|
query: jest.fn(sql => ({ recordset: [ sql ] })),
|
||||||
})),
|
})),
|
||||||
})),
|
})),
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -11,16 +11,22 @@ class TestConfiguration {
|
||||||
describe("MS SQL Server Integration", () => {
|
describe("MS SQL Server Integration", () => {
|
||||||
let config
|
let config
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
config = new TestConfiguration()
|
config = new TestConfiguration()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("check sql used", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await config.integration.connect()
|
||||||
|
})
|
||||||
|
|
||||||
it("calls the create method with the correct params", async () => {
|
it("calls the create method with the correct params", async () => {
|
||||||
const sql = "insert into users (name, age) values ('Joe', 123);"
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
const response = await config.integration.create({
|
const response = await config.integration.create({
|
||||||
sql
|
sql
|
||||||
})
|
})
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
|
expect(config.integration.client.request).toHaveBeenCalledWith()
|
||||||
|
expect(response[0]).toEqual(sql)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls the read method with the correct params", async () => {
|
it("calls the read method with the correct params", async () => {
|
||||||
|
@ -28,13 +34,14 @@ describe("MS SQL Server Integration", () => {
|
||||||
const response = await config.integration.read({
|
const response = await config.integration.read({
|
||||||
sql
|
sql
|
||||||
})
|
})
|
||||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql, {})
|
expect(config.integration.client.request).toHaveBeenCalledWith()
|
||||||
|
expect(response[0]).toEqual(sql)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("no rows returned", () => {
|
describe("no rows returned", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await config.integration.connect()
|
await config.integration.connect()
|
||||||
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("returns the correct response when the create response has no rows", async () => {
|
it("returns the correct response when the create response has no rows", async () => {
|
||||||
|
@ -42,7 +49,7 @@ describe("MS SQL Server Integration", () => {
|
||||||
const response = await config.integration.create({
|
const response = await config.integration.create({
|
||||||
sql
|
sql
|
||||||
})
|
})
|
||||||
expect(response).toEqual([{ created: true }])
|
expect(response[0]).toEqual(sql)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue