Skip to content

Commit 233366b

Browse files
committed
Add test for #7 without fix
1 parent 0029abe commit 233366b

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

test/test1119.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe.skip('Test 1119 - Trigger callback parameter', function () {
3939
assert(
4040
triggerReceivedCorrectData,
4141
'BEFORE INSERT trigger function did not receive the expected data. Received: ' +
42-
JSON.stringify(receivedValue)
42+
JSON.stringify(receivedValue)
4343
);
4444

4545
// Clean up the function to avoid side effects in other tests
@@ -64,7 +64,7 @@ describe.skip('Test 1119 - Trigger callback parameter', function () {
6464
assert(
6565
triggerReceivedCorrectData,
6666
'AFTER INSERT trigger function did not receive the expected data. Received: ' +
67-
JSON.stringify(receivedValue)
67+
JSON.stringify(receivedValue)
6868
);
6969

7070
delete alasql.fn.onchangeAfterInsert;
@@ -91,9 +91,9 @@ describe.skip('Test 1119 - Trigger callback parameter', function () {
9191
assert(
9292
triggerReceivedCorrectData,
9393
'BEFORE UPDATE trigger function did not receive the expected data. Received old: ' +
94-
JSON.stringify(receivedOldValue) +
95-
', new: ' +
96-
JSON.stringify(receivedNewValue)
94+
JSON.stringify(receivedOldValue) +
95+
', new: ' +
96+
JSON.stringify(receivedNewValue)
9797
);
9898

9999
delete alasql.fn.onchangeUpdate;
@@ -118,7 +118,7 @@ describe.skip('Test 1119 - Trigger callback parameter', function () {
118118
assert(
119119
triggerReceivedCorrectData,
120120
'BEFORE DELETE trigger function did not receive the expected data. Received: ' +
121-
JSON.stringify(receivedValue)
121+
JSON.stringify(receivedValue)
122122
);
123123

124124
delete alasql.fn.onchangeDelete;
@@ -144,7 +144,7 @@ describe.skip('Test 1119 - Trigger callback parameter', function () {
144144
assert(
145145
triggerReceivedCorrectData,
146146
'INSTEAD OF INSERT trigger function did not receive the expected data. Received: ' +
147-
JSON.stringify(receivedValue)
147+
JSON.stringify(receivedValue)
148148
);
149149

150150
// Verify that the data was NOT actually inserted because it was an INSTEAD OF trigger

test/test7.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..'); // Use the provided file
4+
} else {
5+
__dirname = '.';
6+
}
7+
8+
describe.skip('Test 7 - ORDER BY on multiple UNIONs', function () {
9+
const test = '7'; // Issue number
10+
11+
before(function () {
12+
alasql('CREATE DATABASE test' + test);
13+
alasql('USE test' + test);
14+
});
15+
16+
after(function () {
17+
alasql('DROP DATABASE test' + test);
18+
});
19+
20+
it('A) Three UNION ALL with ORDER BY DESC', function () {
21+
var sql = 'SELECT 10 AS a UNION ALL SELECT 20 AS a UNION ALL SELECT 30 AS a ORDER BY a DESC';
22+
var res = alasql(sql);
23+
// According to issue #7, the current output might be [ { a: 10 }, { a: 30 }, { a: 20 } ]
24+
// The expected correct output is:
25+
var expected = [{ a: 30 }, { a: 20 }, { a: 10 }];
26+
assert.deepEqual(res, expected, 'ORDER BY DESC on three UNION ALL');
27+
});
28+
29+
it('B) Three UNION ALL with ORDER BY ASC', function () {
30+
var sql = 'SELECT 30 AS a UNION ALL SELECT 10 AS a UNION ALL SELECT 20 AS a ORDER BY a ASC';
31+
var res = alasql(sql);
32+
var expected = [{ a: 10 }, { a: 20 }, { a: 30 }];
33+
assert.deepEqual(res, expected, 'ORDER BY ASC on three UNION ALL');
34+
});
35+
36+
it('C) Four UNION ALL with ORDER BY DESC', function () {
37+
var sql =
38+
'SELECT 10 AS a UNION ALL SELECT 40 AS a UNION ALL SELECT 20 AS a UNION ALL SELECT 30 AS a ORDER BY a DESC';
39+
var res = alasql(sql);
40+
var expected = [{ a: 40 }, { a: 30 }, { a: 20 }, { a: 10 }];
41+
assert.deepEqual(res, expected, 'ORDER BY DESC on four UNION ALL');
42+
});
43+
44+
it('D) Four UNION with ORDER BY DESC (checks DISTINCT implicitly)', function () {
45+
var sql = 'SELECT 10 AS a UNION SELECT 20 AS a UNION SELECT 10 AS a UNION SELECT 30 AS a ORDER BY a DESC';
46+
var res = alasql(sql);
47+
// UNION removes duplicates before ordering
48+
var expected = [{ a: 30 }, { a: 20 }, { a: 10 }];
49+
assert.deepEqual(res, expected, 'ORDER BY DESC on four UNION');
50+
});
51+
52+
it('E) More complex data types', function () {
53+
var sql =
54+
"SELECT 'apple' AS fruit UNION ALL SELECT 'cherry' AS fruit UNION ALL SELECT 'banana' AS fruit ORDER BY fruit ASC";
55+
var res = alasql(sql);
56+
var expected = [{ fruit: 'apple' }, { fruit: 'banana' }, { fruit: 'cherry' }];
57+
assert.deepEqual(res, expected, 'ORDER BY ASC on strings with three UNION ALL');
58+
});
59+
60+
it('F) Multiple columns', function () {
61+
var sql =
62+
'SELECT 10 AS a, 100 AS b UNION ALL SELECT 20 AS a, 50 AS b UNION ALL SELECT 10 AS a, 200 AS b ORDER BY a ASC, b DESC';
63+
var res = alasql(sql);
64+
var expected = [
65+
{ a: 10, b: 200 },
66+
{ a: 10, b: 100 },
67+
{ a: 20, b: 50 },
68+
];
69+
assert.deepEqual(res, expected, 'Multiple columns ORDER BY on three UNION ALL');
70+
});
71+
});

0 commit comments

Comments
 (0)