99import { of } from 'rxjs' ;
1010import { Datatable } from '../../../expression_types' ;
1111import { mapColumn , MapColumnArguments } from '../map_column' ;
12- import { emptyTable , functionWrapper , testTable , sqlTable } from './utils' ;
12+ import { emptyTable , functionWrapper , testTable } from './utils' ;
1313
1414const pricePlusTwo = ( datatable : Datatable ) => of ( datatable . rows [ 0 ] . price + 2 ) ;
1515
@@ -35,66 +35,35 @@ describe('mapColumn', () => {
3535 expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'pricePlusTwo' ) ;
3636 } ) ;
3737
38- describe ( 'when the table columns have id' , ( ) => {
39- it ( 'does not require the id arg by using the name arg as column id' , async ( ) => {
40- const result = await runFn ( testTable , { name : 'name' , expression : pricePlusTwo } ) ;
41- const nameColumnIndex = result . columns . findIndex ( ( { name } ) => name === 'name' ) ;
42- const arbitraryRowIndex = 4 ;
43-
44- expect ( result . type ) . toBe ( 'datatable' ) ;
45- expect ( result . columns ) . toHaveLength ( sqlTable . columns . length ) ;
46- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name' ) ;
47- expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
48- expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'name' , 202 ) ;
49- } ) ;
38+ it ( 'allows the id arg to be optional, looking up by name instead' , async ( ) => {
39+ const result = await runFn ( testTable , { name : 'name label' , expression : pricePlusTwo } ) ;
40+ const nameColumnIndex = result . columns . findIndex ( ( { name } ) => name === 'name label' ) ;
41+ const arbitraryRowIndex = 4 ;
5042
51- it ( 'allows a duplicate name when the ids are different' , async ( ) => {
52- const result = await runFn ( testTable , {
53- id : 'new' ,
54- name : 'name label' ,
55- expression : pricePlusTwo ,
56- } ) ;
57- const nameColumnIndex = result . columns . findIndex ( ( { id } ) => id === 'new' ) ;
58- const arbitraryRowIndex = 4 ;
59-
60- expect ( result . type ) . toBe ( 'datatable' ) ;
61- expect ( result . columns ) . toHaveLength ( testTable . columns . length + 1 ) ;
62- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'id' , 'new' ) ;
63- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name label' ) ;
64- expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
65- expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'new' , 202 ) ;
66- } ) ;
43+ expect ( result . type ) . toBe ( 'datatable' ) ;
44+ expect ( result . columns ) . toHaveLength ( testTable . columns . length ) ;
45+ expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'id' , 'name' ) ;
46+ expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name label' ) ;
47+ expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
48+ expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'name' , 202 ) ;
49+ expect ( result . rows [ arbitraryRowIndex ] ) . not . toHaveProperty ( 'name label' ) ;
6750 } ) ;
6851
69- describe ( 'when the table columns do not have id' , ( ) => {
70- it ( 'uses name as unique key when id arg is also missing' , async ( ) => {
71- const result = await runFn ( sqlTable , { name : 'name' , expression : pricePlusTwo } ) ;
72- const nameColumnIndex = result . columns . findIndex ( ( { name } ) => name === 'name' ) ;
73- const arbitraryRowIndex = 4 ;
74-
75- expect ( result . type ) . toBe ( 'datatable' ) ;
76- expect ( result . columns ) . toHaveLength ( sqlTable . columns . length ) ;
77- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name' ) ;
78- expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
79- expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'name' , 202 ) ;
52+ it ( 'allows a duplicate name when the ids are different' , async ( ) => {
53+ const result = await runFn ( testTable , {
54+ id : 'new' ,
55+ name : 'name label' ,
56+ expression : pricePlusTwo ,
8057 } ) ;
58+ const nameColumnIndex = result . columns . findIndex ( ( { id } ) => id === 'new' ) ;
59+ const arbitraryRowIndex = 4 ;
8160
82- it ( 'overwrites columns matching id === name when the column is missing an id' , async ( ) => {
83- const result = await runFn ( sqlTable , {
84- id : 'name' ,
85- name : 'name is ignored' ,
86- expression : pricePlusTwo ,
87- } ) ;
88- const nameColumnIndex = result . columns . findIndex ( ( { name } ) => name === 'name is ignored' ) ;
89- const arbitraryRowIndex = 4 ;
90-
91- expect ( result . type ) . toBe ( 'datatable' ) ;
92- expect ( result . columns ) . toHaveLength ( sqlTable . columns . length ) ;
93- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'id' , 'name' ) ;
94- expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name is ignored' ) ;
95- expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
96- expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'name' , 202 ) ;
97- } ) ;
61+ expect ( result . type ) . toBe ( 'datatable' ) ;
62+ expect ( result . columns ) . toHaveLength ( testTable . columns . length + 1 ) ;
63+ expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'id' , 'new' ) ;
64+ expect ( result . columns [ nameColumnIndex ] ) . toHaveProperty ( 'name' , 'name label' ) ;
65+ expect ( result . columns [ nameColumnIndex ] . meta ) . toHaveProperty ( 'type' , 'number' ) ;
66+ expect ( result . rows [ arbitraryRowIndex ] ) . toHaveProperty ( 'new' , 202 ) ;
9867 } ) ;
9968
10069 it ( 'adds a column to empty tables' , async ( ) => {
0 commit comments