@@ -69,10 +69,8 @@ describe('FieldSelector.applyFieldSelection — base columns', () => {
6969
7070 it ( 'narrows selection to requested base columns' , ( ) => {
7171 const result = selector . applyFieldSelection ( baseSelection , [ 'name' ] , baseConfig ) ;
72- expect ( Object . keys ( result ) ) . toContain ( 'name' ) ;
73- // id is always kept (PK safeguard)
74- expect ( Object . keys ( result ) ) . toContain ( 'id' ) ;
75- expect ( Object . keys ( result ) ) . not . toContain ( 'secret' ) ;
72+ // PK guard always injects 'id'; exact membership must be correct
73+ expect ( Object . keys ( result ) . sort ( ) ) . toEqual ( [ 'id' , 'name' ] . sort ( ) ) ;
7674 } ) ;
7775
7876 it ( 'excludes hidden base columns even when explicitly requested' , ( ) => {
@@ -89,18 +87,14 @@ describe('FieldSelector.applyFieldSelection — base columns', () => {
8987describe ( 'FieldSelector.applyFieldSelection — join columns (bug fix)' , ( ) => {
9088 it ( 'includes a valid join column in the narrowed selection' , ( ) => {
9189 const result = selector . applyFieldSelection ( joinSelection , [ 'id' , 'email' ] , joinConfig ) ;
92- expect ( Object . keys ( result ) ) . toContain ( 'email' ) ;
93- expect ( Object . keys ( result ) ) . toContain ( 'id' ) ;
94- expect ( Object . keys ( result ) ) . not . toContain ( 'status' ) ;
95- expect ( Object . keys ( result ) ) . not . toContain ( 'role' ) ;
90+ // Exact: only the requested fields plus PK (already included in request)
91+ expect ( Object . keys ( result ) . sort ( ) ) . toEqual ( [ 'email' , 'id' ] . sort ( ) ) ;
9692 } ) ;
9793
9894 it ( 'includes base and join columns together' , ( ) => {
9995 const result = selector . applyFieldSelection ( joinSelection , [ 'status' , 'email' , 'role' ] , joinConfig ) ;
100- expect ( Object . keys ( result ) ) . toContain ( 'status' ) ;
101- expect ( Object . keys ( result ) ) . toContain ( 'email' ) ;
102- expect ( Object . keys ( result ) ) . toContain ( 'role' ) ;
103- expect ( Object . keys ( result ) ) . not . toContain ( 'internalNote' ) ;
96+ // Exact: requested fields + PK guard injects 'id'
97+ expect ( Object . keys ( result ) . sort ( ) ) . toEqual ( [ 'email' , 'id' , 'role' , 'status' ] . sort ( ) ) ;
10498 } ) ;
10599
106100 it ( 'excludes a hidden join column even if requested' , ( ) => {
@@ -139,7 +133,8 @@ describe('FieldSelector.applyFieldSelection — join columns (bug fix)', () => {
139133 } ;
140134
141135 const result = selector . applyFieldSelection ( selection , [ 'id' , 'avatarUrl' ] , nestedConfig ) ;
142- expect ( Object . keys ( result ) ) . toContain ( 'avatarUrl' ) ;
136+ // Exact: both requested fields (no PK injection since 'id' already in request)
137+ expect ( Object . keys ( result ) . sort ( ) ) . toEqual ( [ 'avatarUrl' , 'id' ] . sort ( ) ) ;
143138 } ) ;
144139} ) ;
145140
0 commit comments