@@ -249,73 +249,76 @@ describe('PostgisCodecPlugin', () => {
249249 const attributeHook = ( PostgisCodecPlugin as { gather : { hooks : { pgCodecs_attribute : Function } } } )
250250 . gather . hooks . pgCodecs_attribute ;
251251
252- it ( 'should store geometrySubtype for Polygon geometry column' , async ( ) => {
253- const typmod = getGISTypeModifier ( GisSubtype . Polygon , false , false , 4326 ) ;
254- const attribute : Record < string , any > = { codec : { name : 'geometry' } , extensions : { } } ;
252+ async function runAttributeHook ( {
253+ codecName,
254+ typmod,
255+ withExtensions = true ,
256+ } : {
257+ codecName : string ;
258+ typmod : number | null ;
259+ withExtensions ?: boolean ;
260+ } ) {
261+ const attribute : Record < string , any > = { codec : { name : codecName } } ;
262+ if ( withExtensions ) {
263+ attribute . extensions = { } ;
264+ }
255265 const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
256266
257267 await attributeHook ( { } , event ) ;
258- expect ( attribute . extensions . geometrySubtype ) . toBe ( 'Polygon' ) ;
259- } ) ;
260-
261- it ( 'should store geometrySubtype for Point geometry column' , async ( ) => {
262- const typmod = getGISTypeModifier ( GisSubtype . Point , false , false , 4326 ) ;
263- const attribute : Record < string , any > = { codec : { name : 'geometry' } , extensions : { } } ;
264- const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
265-
266- await attributeHook ( { } , event ) ;
267- expect ( attribute . extensions . geometrySubtype ) . toBe ( 'Point' ) ;
268- } ) ;
269-
270- it ( 'should store geometrySubtype for MultiPolygon geography column' , async ( ) => {
271- const typmod = getGISTypeModifier ( GisSubtype . MultiPolygon , false , false , 4326 ) ;
272- const attribute : Record < string , any > = { codec : { name : 'geography' } , extensions : { } } ;
273- const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
268+ return attribute ;
269+ }
270+
271+ it . each ( [
272+ [ 'geometry' , GisSubtype . Polygon , 'Polygon' ] ,
273+ [ 'geometry' , GisSubtype . Point , 'Point' ] ,
274+ [ 'geography' , GisSubtype . MultiPolygon , 'MultiPolygon' ] ,
275+ ] ) ( 'stores geometrySubtype for %s subtype %s' , async ( codecName , subtype , expected ) => {
276+ const attribute = await runAttributeHook ( {
277+ codecName,
278+ typmod : getGISTypeModifier ( subtype , false , false , 4326 ) ,
279+ } ) ;
274280
275- await attributeHook ( { } , event ) ;
276- expect ( attribute . extensions . geometrySubtype ) . toBe ( 'MultiPolygon' ) ;
281+ expect ( attribute . extensions . geometrySubtype ) . toBe ( expected ) ;
277282 } ) ;
278283
279284 it ( 'should skip unconstrained geometry (atttypmod = -1)' , async ( ) => {
280- const attribute : Record < string , any > = { codec : { name : 'geometry' } , extensions : { } } ;
281- const event = { pgAttribute : { atttypmod : - 1 } , attribute } ;
282-
283- await attributeHook ( { } , event ) ;
285+ const attribute = await runAttributeHook ( {
286+ codecName : 'geometry' ,
287+ typmod : - 1 ,
288+ } ) ;
284289 expect ( attribute . extensions . geometrySubtype ) . toBeUndefined ( ) ;
285290 } ) ;
286291
287292 it ( 'should skip when atttypmod is null' , async ( ) => {
288- const attribute : Record < string , any > = { codec : { name : 'geometry' } , extensions : { } } ;
289- const event = { pgAttribute : { atttypmod : null as number | null } , attribute } ;
290-
291- await attributeHook ( { } , event ) ;
293+ const attribute = await runAttributeHook ( {
294+ codecName : 'geometry' ,
295+ typmod : null ,
296+ } ) ;
292297 expect ( attribute . extensions . geometrySubtype ) . toBeUndefined ( ) ;
293298 } ) ;
294299
295300 it ( 'should not store subtype for base Geometry (subtype=0)' , async ( ) => {
296- const typmod = getGISTypeModifier ( GisSubtype . Geometry , false , false , 4326 ) ;
297- const attribute : Record < string , any > = { codec : { name : 'geometry' } , extensions : { } } ;
298- const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
299-
300- await attributeHook ( { } , event ) ;
301+ const attribute = await runAttributeHook ( {
302+ codecName : 'geometry' ,
303+ typmod : getGISTypeModifier ( GisSubtype . Geometry , false , false , 4326 ) ,
304+ } ) ;
301305 expect ( attribute . extensions . geometrySubtype ) . toBeUndefined ( ) ;
302306 } ) ;
303307
304308 it ( 'should skip non-geometry codec types' , async ( ) => {
305- const typmod = getGISTypeModifier ( GisSubtype . Point , false , false , 4326 ) ;
306- const attribute : Record < string , any > = { codec : { name : 'text' } , extensions : { } } ;
307- const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
308-
309- await attributeHook ( { } , event ) ;
309+ const attribute = await runAttributeHook ( {
310+ codecName : 'text' ,
311+ typmod : getGISTypeModifier ( GisSubtype . Point , false , false , 4326 ) ,
312+ } ) ;
310313 expect ( attribute . extensions . geometrySubtype ) . toBeUndefined ( ) ;
311314 } ) ;
312315
313316 it ( 'should create extensions object if not present' , async ( ) => {
314- const typmod = getGISTypeModifier ( GisSubtype . LineString , false , false , 4326 ) ;
315- const attribute : Record < string , any > = { codec : { name : 'geometry' } } ;
316- const event = { pgAttribute : { atttypmod : typmod } , attribute } ;
317-
318- await attributeHook ( { } , event ) ;
317+ const attribute = await runAttributeHook ( {
318+ codecName : 'geometry' ,
319+ typmod : getGISTypeModifier ( GisSubtype . LineString , false , false , 4326 ) ,
320+ withExtensions : false ,
321+ } ) ;
319322 expect ( attribute . extensions ) . toBeDefined ( ) ;
320323 expect ( attribute . extensions . geometrySubtype ) . toBe ( 'LineString' ) ;
321324 } ) ;
0 commit comments