Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrauskopf committed Oct 28, 2020
1 parent 9feb6cd commit 5be63ba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { loadApp } from "@shipengine/connect-loader";
import Login from './login';
import { ApiClientErrors } from '../core/api-client'
import Table from 'cli-table';
import { createOrFindTestAccount } from '../core/utils/create-or-find-test-account';

export default class Info extends BaseCommand {
public static description = "Get the current information about your app";
Expand Down Expand Up @@ -45,6 +46,8 @@ export default class Info extends BaseCommand {

const latestDeployment = paginatedDeployments.items[0];

const accountInfo = await createOrFindTestAccount(apiClient, platformApp);

const table = new Table();

table.push(
Expand All @@ -53,6 +56,9 @@ export default class Info extends BaseCommand {
{ 'Type': [platformApp.type] },
{ 'Status': [latestDeployment.status] },
{ 'Created At': [latestDeployment.createdAt] },
{ 'Email': [accountInfo.email] },
{ 'Password': [accountInfo.password] },
{ 'Test URL': [accountInfo.testUrl] }
);
this.log(table.toString());
} catch (error) {
Expand Down
28 changes: 10 additions & 18 deletions src/core/publish-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { watchDeployment } from "./publish-app/watch-deployment";
import { green, red } from "chalk";
import parseDeploymentErrors from './utils/parse-deployment-errors';
import Table from 'cli-table';
import { ConnectApp } from './types'
import { createOrFindTestAccount, TestAccountInfo } from './utils/create-or-find-test-account';

class AppFailedToPackageError extends Error {
code: string;
Expand Down Expand Up @@ -129,36 +129,28 @@ export default async function publishApp(
console.log(
green(`Your app was published successfully ${logSymbols.success} `),
);
await createOrFindTestAccount(client, platformApp);
const accountInfo = await createOrFindTestAccount(client, platformApp);
displayAccountInfo(accountInfo);
}

return newDeployment;
}

await createOrFindTestAccount(client, platformApp);
const accountInfo = await createOrFindTestAccount(client, platformApp);
displayAccountInfo(accountInfo);

return newDeployment;
}

const createOrFindTestAccount = async (client: APIClient, platformApp: ConnectApp) => {
const sellers = await client.sellers.getSellersForAppId(platformApp.id)
const email = `${platformApp.id}@test.com`;

if (!sellers.some((seller) => seller.email === email)) {
cli.action.start("Creating test account");
await client.sellers.createSeller(platformApp.id, email, platformApp.id)
cli.action.stop(`${logSymbols.success}`);
}

const productInfo = platformApp.productInfos.find((info) => info.product === "ShipStation")
const testUrl = productInfo && productInfo.loginUrl;
function displayAccountInfo(accountInfo: TestAccountInfo) {
const table = new Table();

table.push(
{ 'Email': [email] },
{ 'Password': [platformApp.id] },
{ 'Test URL': [testUrl] }
{ 'Email': [accountInfo.email] },
{ 'Password': [accountInfo.password] },
{ 'Test URL': [accountInfo.testUrl] }
);

console.log("Test your app with the account below:");
console.log(table.toString());
}
32 changes: 32 additions & 0 deletions src/core/utils/create-or-find-test-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import APIClient from '../api-client';
import { ConnectApp } from '../types';
import logSymbols from "log-symbols";
import cli from "cli-ux";

export interface TestAccountInfo {
email: string;
password: string;
testUrl?: string
}
/**
* Find or create a test account and return the information.
*/
export async function createOrFindTestAccount(client: APIClient, platformApp: ConnectApp): Promise<TestAccountInfo> {
const sellers = await client.sellers.getSellersForAppId(platformApp.id)
const email = `${platformApp.id}@test.com`;

if (!sellers.some((seller) => seller.email === email)) {
cli.action.start("Creating test account");
await client.sellers.createSeller(platformApp.id, email, platformApp.id)
cli.action.stop(`${logSymbols.success}`);
}

const productInfo = platformApp.productInfos.find((info) => info.product === "ShipStation")
const testUrl = productInfo && productInfo.loginUrl;

return {
email,
password: platformApp.id,
testUrl
}
}

0 comments on commit 5be63ba

Please sign in to comment.