Add test command to test status of set list of local routes (#29)
This commit is contained in:
@@ -7,7 +7,14 @@ const command: GluegunCommand = {
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { print } = toolbox;
|
||||
print.info('Welcome to photowall CLI for everything, almost 😬');
|
||||
await toolbox.menu.showMenu(null);
|
||||
await toolbox.menu.showMenu(null, {
|
||||
sections: [
|
||||
{
|
||||
name: 'test',
|
||||
description: 'Test commands',
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -105,11 +105,15 @@ module.exports = {
|
||||
print.info(
|
||||
`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`,
|
||||
);
|
||||
|
||||
if (!config) {
|
||||
config = {
|
||||
gh_token: '',
|
||||
photowall_repo: '',
|
||||
mandrill_api_key: '',
|
||||
localhost_url: '',
|
||||
localhost_username: '',
|
||||
localhost_password: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -130,6 +134,21 @@ module.exports = {
|
||||
initial: config.mandrill_api_key,
|
||||
}).run();
|
||||
|
||||
config.localhost_url = await new Input({
|
||||
message: `If you want to be able to run route tests against localhost, please enter the base URL for localhost (e.g. https://www.photowall-local.se:8080) >`,
|
||||
initial: config.localhost_url,
|
||||
}).run();
|
||||
|
||||
config.localhost_username = await new Input({
|
||||
message: `If you want to be able to run route tests against localhost, please enter the username for localhost >`,
|
||||
initial: config.localhost_username,
|
||||
}).run();
|
||||
|
||||
config.localhost_password = await new Input({
|
||||
message: `If you want to be able to run route tests against localhost, please enter the password for localhost >`,
|
||||
initial: config.localhost_password,
|
||||
}).run();
|
||||
|
||||
print.info(`
|
||||
|
||||
${JSON.stringify(config)}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { GluegunCommand } from 'gluegun';
|
||||
import { getSettings } from '../../globals';
|
||||
import { Agent } from 'https';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const PATHS = [
|
||||
'/',
|
||||
'/forest-fun-tapet',
|
||||
'/foggy-forest-4-tapet',
|
||||
'/sweet-safari-sky-rose-tapet',
|
||||
'/rough-watercolors-tavla',
|
||||
'/adorable-animals-in-the-forest-beige-poster',
|
||||
'/farg',
|
||||
'/vegas-farg',
|
||||
'/fototapet',
|
||||
'/canvas',
|
||||
'/posters',
|
||||
'/egen-fototapet/2239465/882eae1e',
|
||||
'/api/product/data?p=94054&group=wallpaper',
|
||||
'/api/price/wallpaper_product?height=321&width=123&unit=cm&productId=73543&materialId=4',
|
||||
'/favoriter',
|
||||
'/kollektioner',
|
||||
'/inspiration',
|
||||
'/magazine',
|
||||
'/influencer-collections/emily-vanwagenen-x-photowall',
|
||||
];
|
||||
|
||||
const command: GluegunCommand = {
|
||||
name: 'routes (r)',
|
||||
alias: ['r'],
|
||||
description:
|
||||
'Test pre-configured routes for 200 status, defaults to run on configured localhost',
|
||||
run: async (toolbox) => {
|
||||
const { print } = toolbox;
|
||||
const config = await getSettings(toolbox);
|
||||
if (!config || !config.localhost_url) {
|
||||
print.error(
|
||||
'No localhost URL set in settings. Please run "pwcli setup settings" and set localhost_url.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
const HOST = config.localhost_url;
|
||||
const USERNAME = config.localhost_username;
|
||||
const PASSWORD = config.localhost_password;
|
||||
|
||||
const httpsAgent = new Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
PATHS.map(async (path) => {
|
||||
try {
|
||||
console.log(`Fetching ${HOST + path} ...`);
|
||||
const res = await fetch(HOST + path, {
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic ' +
|
||||
Buffer.from(`${USERNAME}:${PASSWORD}`).toString('base64'),
|
||||
},
|
||||
agent: httpsAgent,
|
||||
});
|
||||
return { path, status: res.status, message: res.statusText };
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return { path, message: e.message || 'error' };
|
||||
}
|
||||
}),
|
||||
);
|
||||
for (const { path, status, message } of results) {
|
||||
const msg =
|
||||
status === 200 ? '✅' : `${message}${status ? ` (${status})` : ''}`;
|
||||
if (status === 200) {
|
||||
print.success(`${HOST}${path}: ${msg}`);
|
||||
} else {
|
||||
print.error(`${HOST}${path}: ${msg}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = command;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import { GluegunCommand } from 'gluegun';
|
||||
|
||||
const command: GluegunCommand = {
|
||||
name: 'test',
|
||||
description: 'Test commands (t)',
|
||||
alias: ['t'],
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('test');
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = command;
|
||||
@@ -11,6 +11,9 @@ export type TConfig = {
|
||||
gh_token: string;
|
||||
photowall_repo: string;
|
||||
mandrill_api_key: string;
|
||||
localhost_url?: string;
|
||||
localhost_username?: string;
|
||||
localhost_password?: string;
|
||||
};
|
||||
export const getSettings = async (toolbox): Promise<TConfig | null> => {
|
||||
const { filesystem, print } = toolbox;
|
||||
|
||||
Reference in New Issue
Block a user