2024-06-22 10:09:55 +01:00
|
|
|
import ICliOptions from "../../src/contracts/ICliOptions";
|
|
|
|
import IReturnResult from "../../src/contracts/IReturnResult";
|
|
|
|
import OutputHelper from "../../src/helpers/outputHelper";
|
|
|
|
|
|
|
|
describe("GenerateOutput", () => {
|
|
|
|
test("EXPECT standout output to be returned", () => {
|
|
|
|
// Arrange
|
|
|
|
const response = {
|
|
|
|
IsSuccess: true,
|
|
|
|
Query: {
|
|
|
|
subreddit: "rabbits",
|
|
|
|
sortBy: "hot",
|
2024-07-26 18:23:19 +01:00
|
|
|
limit: 100,
|
2024-06-22 10:09:55 +01:00
|
|
|
},
|
|
|
|
Result: {
|
|
|
|
Archived: false,
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
} as IReturnResult;
|
|
|
|
|
|
|
|
const options = {} as ICliOptions;
|
|
|
|
|
|
|
|
// Act
|
|
|
|
const result = OutputHelper.GenerateOutput(response, options);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("GIVEN options.json is true, EXPECT output to be returned as JSON", () => {
|
|
|
|
// Arrange
|
|
|
|
const response = {
|
|
|
|
IsSuccess: true,
|
|
|
|
Query: {
|
|
|
|
subreddit: "rabbits",
|
|
|
|
sortBy: "hot",
|
2024-07-26 18:23:19 +01:00
|
|
|
limit: 100,
|
2024-06-22 10:09:55 +01:00
|
|
|
},
|
|
|
|
Result: {
|
|
|
|
Archived: false,
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
} as IReturnResult;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
json: true,
|
|
|
|
} as ICliOptions;
|
|
|
|
|
|
|
|
// Act
|
|
|
|
const result = OutputHelper.GenerateOutput(response, options);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added", () => {
|
|
|
|
// Arrange
|
|
|
|
const response = {
|
|
|
|
IsSuccess: true,
|
|
|
|
Query: {
|
|
|
|
subreddit: "rabbits",
|
|
|
|
sortBy: "hot",
|
2024-07-26 18:23:19 +01:00
|
|
|
limit: 100,
|
2024-06-22 10:09:55 +01:00
|
|
|
},
|
|
|
|
Result: {
|
|
|
|
Archived: false,
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
} as IReturnResult;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
queryMetadata: true,
|
|
|
|
} as ICliOptions;
|
|
|
|
|
|
|
|
// Act
|
|
|
|
const result = OutputHelper.GenerateOutput(response, options);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|