Last active
April 19, 2022 07:00
-
-
Save aleksejkozin/d9f6a2ea9912a4a424e5e3e9c04d7c8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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