|
1 | | -import {setupRDSDatabase} from "./db"; |
2 | | -import {v4 as uuid} from "uuid"; |
3 | | - |
4 | | -xtest('Simple Transaction', async () => { |
5 | | - const rds = setupRDSDatabase().getInstance(); |
6 | | - const uuid1 = uuid(); |
7 | | - const uuid2 = uuid(); |
8 | | - const uuid3 = uuid(); |
9 | | - |
10 | | - const startInfo = await rds.query("SELECT COUNT(id) AS cn FROM TestList"); |
11 | | - |
12 | | - const results = await rds.transaction().then(async (transactionId) => { |
13 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid1)", {uuid1}, transactionId); |
14 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid2)", {uuid2}, transactionId); |
15 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid3)", {uuid3}, transactionId); |
16 | | - const results = await rds.commit(transactionId); |
17 | | - return results; |
18 | | - }); |
19 | | - |
20 | | - const endInfo = await rds.query("SELECT COUNT(id) AS cn FROM TestList"); |
21 | | - const startCount = (startInfo.data[0].cn.number ?? 0); |
22 | | - const endCount = (endInfo.data[0].cn.number ?? 0); |
23 | | - |
24 | | - expect(results).toBe("Transaction Committed"); |
25 | | - expect(startCount).toBe(endCount - 3); |
| 1 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 2 | +import { v4 as uuid } from 'uuid'; |
| 3 | +import { setupRDSDatabase } from './db'; |
| 4 | + |
| 5 | +test('Simple Transaction', async () => { |
| 6 | + const rds = setupRDSDatabase().getInstance(); |
| 7 | + const uuid1 = uuid(); |
| 8 | + const uuid2 = uuid(); |
| 9 | + const uuid3 = uuid(); |
| 10 | + |
| 11 | + const startInfo = await rds.query('SELECT COUNT(id) AS cn FROM TestList'); |
| 12 | + |
| 13 | + const results = await rds.transaction().then(async (transactionId) => { |
| 14 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid1)', { uuid1 }, transactionId); |
| 15 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid2)', { uuid2 }, transactionId); |
| 16 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid3)', { uuid3 }, transactionId); |
| 17 | + const r = await rds.commit(transactionId); |
| 18 | + return r; |
| 19 | + }); |
| 20 | + |
| 21 | + expect(results).toBe('Transaction Committed'); |
| 22 | + |
| 23 | + const endInfo = await rds.query('SELECT COUNT(id) AS cn FROM TestList'); |
| 24 | + const startCount = startInfo.data[0].cn.number ?? 0; |
| 25 | + const endCount = endInfo.data[0].cn.number ?? 0; |
| 26 | + |
| 27 | + expect(results).toBe('Transaction Committed'); |
| 28 | + expect(startCount).toBe(endCount - 3); |
26 | 29 | }); |
27 | 30 |
|
28 | | -xtest('Rollback Transaction', async () => { |
29 | | - const rds = setupRDSDatabase().getInstance(); |
30 | | - const uuid1 = uuid(); |
31 | | - const uuid2 = uuid(); |
32 | | - const uuid3 = uuid(); |
| 31 | +test('Rollback Transaction', async () => { |
| 32 | + const rds = setupRDSDatabase().getInstance(); |
| 33 | + const uuid1 = uuid(); |
| 34 | + const uuid2 = uuid(); |
| 35 | + const uuid3 = uuid(); |
33 | 36 |
|
34 | | - const startInfo = await rds.query("SELECT COUNT(id) AS cn FROM TestList"); |
| 37 | + const startInfo = await rds.query('SELECT COUNT(id) AS cn FROM TestList'); |
35 | 38 |
|
36 | | - const results = await rds.transaction().then(async (transactionId) => { |
37 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid1)", {uuid1}, transactionId); |
38 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid2)", {uuid2}, transactionId); |
39 | | - await rds.query("INSERT INTO TestList (uuid) VALUES (:uuid3)", {uuid3}, transactionId); |
40 | | - const results = await rds.rollback(transactionId); |
41 | | - return results; |
42 | | - }); |
| 39 | + const results = await rds.transaction().then(async (transactionId) => { |
| 40 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid1)', { uuid1 }, transactionId); |
| 41 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid2)', { uuid2 }, transactionId); |
| 42 | + await rds.query('INSERT INTO TestList (uuid) VALUES (:uuid3)', { uuid3 }, transactionId); |
| 43 | + const r = await rds.rollback(transactionId); |
| 44 | + return r; |
| 45 | + }); |
43 | 46 |
|
44 | | - const endInfo = await rds.query("SELECT COUNT(id) AS cn FROM TestList"); |
45 | | - const startCount = (startInfo.data[0].cn.number ?? 0); |
46 | | - const endCount = (endInfo.data[0].cn.number ?? 0); |
| 47 | + const endInfo = await rds.query('SELECT COUNT(id) AS cn FROM TestList'); |
| 48 | + const startCount = startInfo.data[0].cn.number ?? 0; |
| 49 | + const endCount = endInfo.data[0].cn.number ?? 0; |
47 | 50 |
|
48 | | - expect(results).toBe("Rollback Complete"); |
49 | | - expect(startCount).toBe(endCount); |
| 51 | + expect(results).toBe('Rollback Complete'); |
| 52 | + expect(startCount).toBe(endCount); |
50 | 53 | }); |
0 commit comments