Skip to content

Commit 824e62b

Browse files
committed
QueryResult to RPG data structure test
1 parent 51e4adc commit 824e62b

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/views/results/codegen.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assert, expect, test } from 'vitest'
2-
import { columnToRpgDefinition } from './codegen';
2+
import { columnToRpgDefinition, queryResultToRpgDs } from './codegen';
3+
import { QueryResult } from '@ibm/mapepire-js';
34

45
test('Column to RPG definition', () => {
56
let rpgdef;
@@ -41,3 +42,51 @@ test('Column to RPG definition', () => {
4142
expect(rpgdef).toBe('// type:SOME_UNKNOWN_TYPE precision:0 scale:0');
4243
});
4344

45+
test('QueryResult to RPG data structure', () => {
46+
const queryResult: QueryResult<any> = {
47+
metadata: {
48+
column_count: 3,
49+
columns: [
50+
{
51+
display_size: 0,
52+
label: 'id',
53+
name: 'id',
54+
type: 'INTEGER',
55+
precision: 0,
56+
scale: 0
57+
},
58+
{
59+
display_size: 0,
60+
label: 'name',
61+
name: 'name',
62+
type: 'VARCHAR',
63+
precision: 80,
64+
scale: 0
65+
},
66+
{
67+
display_size: 0,
68+
label: 'salary',
69+
name: 'salary',
70+
type: 'DECIMAL',
71+
precision: 13,
72+
scale: 2
73+
},
74+
]
75+
},
76+
is_done: true,
77+
has_results: true,
78+
update_count: 0,
79+
data: [],
80+
id: '',
81+
success: true,
82+
sql_rc: 0,
83+
sql_state: '',
84+
execution_time: 0
85+
};
86+
const ds = queryResultToRpgDs(queryResult);
87+
const lines = ds.split('\n').filter(l => l !== '');
88+
expect(lines.length).toBe(5);
89+
expect(lines.at(0)).toBe('dcl-ds row_t qualified template;');
90+
expect(lines.at(4)).toBe('end-ds;');
91+
});
92+

0 commit comments

Comments
 (0)