Skip to content

Instantly share code, notes, and snippets.

@aleksejkozin
Last active April 19, 2022 07:00
Show Gist options
  • Save aleksejkozin/d9f6a2ea9912a4a424e5e3e9c04d7c8f to your computer and use it in GitHub Desktop.
Save aleksejkozin/d9f6a2ea9912a4a424e5e3e9c04d7c8f to your computer and use it in GitHub Desktop.
const testQuery = async query => {
const pool = new sql.ConnectionPool({ // ... //})
try {
await pool.connect()
return await pool.request().query(`
BEGIN TRANSACTION
${query}
ROLLBACK TRANSACTION
`)
} finally {
await pool.close()
}
}
export const selectMaxRetailPriceMSSQL = `
SELECT TOP 1 MasterRetailPrice
FROM UpcCollisionReport
ORDER BY MasterRetailPrice DESC
`
it('Should return maximum MasterRetailPrice', async () => {
const {recordset} = await testQuery(`
-- Initializing database state
TRUNCATE TABLE UpcCollisionReport;
INSERT INTO UpcCollisionReport (MasterRetailPrice)
VALUES (3), (5), (1), (2), (4);
${selectMaxRetailPriceMSSQL}
`)
expect(recordset).toStrictEqual([
expect.objectContaining({MasterRetailPrice: 5}),
])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment