@smallprod/models
Version:
63 lines (62 loc) • 2.05 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../..");
const chai_1 = require("chai");
const query_1 = __importDefault(require("../_utils/query"));
describe.each([
['MariaDB', 'maria'],
['MySql', 'mysql'],
['PostgresSql', 'postgres'],
])('Transaction tests with %s', (dbName, name) => {
let dbManager;
let model;
beforeAll(async (done) => {
dbManager = __1.DbManager.getInstance();
const m = dbManager.get(name);
if (m) {
model = m;
}
else {
throw new Error(`Database connection not found ${name}`);
}
await query_1.default.create(model, name);
done();
});
test('Transaction with commit', async () => {
await model.startTransaction();
await model.query(`INSERT INTO categories (label) VALUES ('test');`);
await model.commit();
const res = await model.query(`SELECT * FROM categories`);
if (res instanceof Array) {
chai_1.expect(res.length).to.be.equal(1);
}
else {
chai_1.expect(res.rows.length).to.be.equal(1);
}
});
test('Transaction with rollback', async () => {
await model.startTransaction();
await model.query(`INSERT INTO categories (label) VALUES ('test');`);
await model.rollback();
const res = await model.query(`SELECT * FROM categories`);
if (res instanceof Array) {
chai_1.expect(res.length).to.be.equal(0);
}
else {
chai_1.expect(res.rows.length).to.be.equal(0);
}
});
test('Start two transactions', async () => {
});
afterEach(async (done) => {
await model.query('DELETE FROM categories');
done();
});
afterAll(async (done) => {
await query_1.default.delete(model);
done();
});
});