From 307a9560ffe9dacdff3de6082daed397f61dfdf4 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 17 Jan 2025 17:51:01 +0000 Subject: [PATCH] Update query metadata to be under a subheading --- src/helpers/outputHelper.ts | 11 ++++++++--- .../__snapshots__/outputHelper.test.ts.snap | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/helpers/outputHelper.ts b/src/helpers/outputHelper.ts index 976f7d9..29d9e5a 100644 --- a/src/helpers/outputHelper.ts +++ b/src/helpers/outputHelper.ts @@ -10,7 +10,7 @@ export default class OutputHelper { outputObject = { ...result }; if (options.queryMetadata) { - outputObject = { ...outputObject, ...response.Query } + outputObject = { ...outputObject, Query: { ...response.Query } } } if (options.json) { @@ -20,11 +20,16 @@ export default class OutputHelper { return this.GetFriendlyObjectText(outputObject); } - private static GetFriendlyObjectText(object: T): string { + private static GetFriendlyObjectText(object: T, indent: string = ''): string { const output: string[] = []; for (const key in object) { - output.push(`${key} = ${object[key]}`); + if (typeof object[key] === 'object' && object[key] !== null) { + output.push(`${indent}${key}:`); + output.push(this.GetFriendlyObjectText(object[key], indent + ' ')); + } else { + output.push(`${indent}${key} = ${object[key]}`); + } } return output.join("\n"); diff --git a/tests/helpers/__snapshots__/outputHelper.test.ts.snap b/tests/helpers/__snapshots__/outputHelper.test.ts.snap index fa6efad..3d1c0fc 100644 --- a/tests/helpers/__snapshots__/outputHelper.test.ts.snap +++ b/tests/helpers/__snapshots__/outputHelper.test.ts.snap @@ -11,12 +11,13 @@ SubredditSubscribers = 654751 Title = This is my Ms Bear! Ups = 17 Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d -Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d" +Gallery: + 0 = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d" `; exports[`GenerateOutput GIVEN options.json is true, EXPECT output to be returned as JSON 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","Gallery":["https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"]}"`; -exports[`GenerateOutput GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","subreddit":"rabbits","sortBy":"hot","limit":100}"`; +exports[`GenerateOutput GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","Query":{"subreddit":"rabbits","sortBy":"hot","limit":100}}"`; exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = ` "Archived = false @@ -29,10 +30,12 @@ SubredditSubscribers = 654751 Title = This is my Ms Bear! Ups = 17 Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d -Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d -subreddit = rabbits -sortBy = hot -limit = 100" +Gallery: + 0 = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d +Query: + subreddit = rabbits + sortBy = hot + limit = 100" `; exports[`GenerateOutput GIVEN the Gallery input has more than 1 item, EXPECT Gallery line to be added 1`] = ` @@ -46,5 +49,7 @@ SubredditSubscribers = 654751 Title = This is my Ms Bear! Ups = 17 Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d -Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d,https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d" +Gallery: + 0 = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d + 1 = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d" `; -- 2.45.2