Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fileignoreconfig:
- filename: src/commands/launch/logs/get.test.ts
checksum: d94d390de150956c799f64a84adfe0e02b5b21c66ddcc5cf55a1329aa67ec1a7
- filename: src/core/failure.test.ts
checksum: d8be306f3bde77249360475bbb76093ce67458f3530c3b4c5bd7e6a516a910aa
checksum: 3f5c731861dc816d141f6314c32bec55bc5197241447a4375bc76fa9f85339f0
- filename: test/integration/retired-commands.test.ts
checksum: c38d6e8dae6bd4d2034ff48bff488e89cc00d950a7417c6df890168ac743ae37
- filename: test/integration/manage-base-path.test.ts
Expand Down Expand Up @@ -116,7 +116,7 @@ fileignoreconfig:
allowed_patterns:
- "assertArray\\(response, key, `\\$\\{key\\} response`\\)"
- filename: src/environments/environment.inputs.ts
checksum: 3fc2802c79457f7c7e93cd5f32c00a7986dc6f686fe3c346de4b8436a66cc0b9
checksum: fd3a8f925444e44b0477d7c907d77526d5a4315d627bf29768912b6799a45c80
ignore_detectors:
- filename
- filename: src/environments/environment.builder.ts
Expand All @@ -127,11 +127,11 @@ fileignoreconfig:
- filename
checksum: 8b7e3207630f19170dd08ca639ebca8af6bc0d70db633b98e66eedde6d2ea641
- filename: src/environments/environment.update.ts
checksum: b1e15e174f98a875f97e0683182638f93966ef4c498135d36df620a28338aacb
checksum: 85b625c571ef1a4e0c177b78fe5538f6c9506c4b692c6212d9faa63681d77ffe
ignore_detectors:
- filename
- filename: src/environments/environment.update.test.ts
checksum: 5e90c3dd231ede1b890f7c750c7063412116a2e4be536d2f290d56d28205ceae
checksum: 451f42cd81d25088ec05f5ededc9375bfcac7cda6a29db60ccda792768afdd0e
ignore_detectors:
- filename
- filename: src/environments/environment.create.ts
Expand All @@ -145,19 +145,19 @@ fileignoreconfig:
ignore_detectors:
- filename
- filename: src/environments/environment.update.prompt.ts
checksum: 5f2da5ae044eda92f9e555c997d23f065b5454cda8a340c12595597795ecfbb9
checksum: 992d52bfb924105691c90fbdee53ca66fc0a585bb3273e7bcb23974ec2ef4c5c
ignore_detectors:
- filename
- filename: src/environments/environment.update.prompt.test.ts
checksum: 6653e245baac00cef348acfc0aa2f32d03a7ff63ca3c320ee56a0c6250775004
checksum: 2be66b5b7a394e0f2440163ee94c46fdd3884e594673b03de9d8c2eef0ca1ed0
ignore_detectors:
- filename
- filename: src/environments/environment.presenter.ts
checksum: 3ca3e566a136fb0100cd794e9e973fce70a80c88224b6f93027d8190ac0b6882
checksum: 3808d26ca5eb7f345568b56fe48f5756e14f0cdb15ef68b2ae72e9556bc6bab2
ignore_detectors:
- filename
- filename: src/environments/environment.presenter.test.ts
checksum: f5f6e5ec469a16ca8e1c9175ec88aa406a24c6318ef95520d534c444fdd3ab88
checksum: 3e28f6188a450b47d874453a37e22193d9e5036762d34f55315118ed54a73c0a
ignore_detectors:
- filename
- filename: src/environments/environment.resolver.ts
Expand Down Expand Up @@ -311,9 +311,9 @@ fileignoreconfig:
- filename: test/credential-guard.setup.ts
checksum: 519ccbeb0552fdb1d5f27308c56477c0258ee6cc0adec8f618e8e5bc047cbf6d
- filename: src/environments/types.ts
checksum: 2825d0e70757022e518465b134878b8cc8f9eccaf4e9ad088d73a31b9a35a826
checksum: d5506fb4ea67ef8cac77b43724ad6b0e438503d7198d68db8fb2f6d718e89f00
- filename: src/commands/launch/env/get.test.ts
checksum: 6e739ef12bc0d887e652e23ee54d9fac30dd6a3505cf464cdaefc0e696cf3e51
checksum: 6b79822734553c7417c0a8774fae221609d008be22834113661c9925f17017b9
- filename: test/integration/environments-delete.test.ts
checksum: a6f002256162971e5f4ace879153454c95199101d2acc853f2a54b39d1d48914
- filename: src/commands/launch/env/delete.test.ts
Expand All @@ -327,11 +327,11 @@ fileignoreconfig:
- filename: test/integration/environments-update.test.ts
checksum: 249f27ad679b68f40eac3af90c616229838bceffad57ba508dd298ab053fa51a
- filename: src/commands/launch/env/update.ts
checksum: 06add97108d878eaf415e32160439b8963683e63a0e37ce77a56f66b88383c7a
checksum: 981c3267005bca0453131b532c9b62ca501bc67cfd25511c261e99082677882a
- filename: src/commands/launch/env/update.test.ts
checksum: 2da219594e7bdd589adc0eff9ff035252a75aaa51dfa20514b18fd3266d7b752
checksum: 82c76af721bfdfd8eb7cf49494ffbe15d98b988e98bca1015b9d34b42b5226bd
- filename: README.md
checksum: a3c7d1fc273e7b5b818f0a7f05664fd7ddbb05c2f2eb44c28b5d496aad828508
checksum: 6386fbf38075484d6c0eb32bb40ab246a1c94dff41a107e14713f944b4f1d2b5
allowed_patterns:
- "password-protection"
- "-p, --password"
Expand Down Expand Up @@ -433,17 +433,17 @@ fileignoreconfig:
- filename: src/commands/launch/deployments/list.test.ts
checksum: e493cd51e7c65bbf5b4f71704478b7a669bca4342efc865a1363bc508fe6f9f0
- filename: src/deployments/deployment.presenter.test.ts
checksum: e393d6bb6ce3fd92920f5003603b161186085ea8939fae704e6f71bd9e1778bc
checksum: f5a8d7ccd1118e79abd5f2717d6535ca13c576b92bd686ee429ae72aaafa955a
- filename: test/integration/deployments-create.test.ts
checksum: fef71ae5b4bed7bcca111e90870238a26518e7a376475aa55768f5ffbe07ba36
- filename: src/deployments/deployment.watcher.test.ts
checksum: b04213c987716247cfb4f1ccac37ba96f0c9a73b4564bd45b4da8ee5def0b9ca
- filename: src/deployments/deployment.create.ts
checksum: ca64f3b29a68c4a2755a88a141e2cd9dbd6fa851a2776876d78c40f3168492e3
- filename: src/commands/launch/deployments/create.test.ts
checksum: bcbb2f85e0a78d38036af4723a0ce691f2692de05f5c7c9c3f97a5cca13497a6
checksum: 9f5c60d5f6367250aa8f932acf0e5a7ece933f3fc1ca173fa908e80724d1d579
- filename: src/deployments/deployment.create.test.ts
checksum: 6545afa21a23b7e5de18ad8ff417f88a184577e7042713cfda90758ccbcd9869
checksum: aceeba27a10ffe7bcf7f78af4c88cb19e017a46c898f02a07e314f949775841a
- filename: test/integration/deployments-rollback.test.ts
checksum: 98a9f7001eb5bf01e0e2f46677eeea61ad5d38c595d17ef27d366c93e603f0d5
- filename: test/integration/deployments-cancel.test.ts
Expand Down
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,31 +851,26 @@ _See code: [src/commands/launch/secrets/unset.ts](https://github.com/contentstac

## `csdx launch:site:open`

Open an environment's live site in your browser, or print its URL when there is no terminal. On a terminal, when the environment has more than one domain, you choose which one to open; --deployment opens that deployment's preview URL without asking.
Open an environment's live site in your browser, or print its URL when there is no terminal. On a terminal, when the environment has more than one domain, you choose which one to open.

```
USAGE
$ csdx launch:site:open [--config <value>] [-d <value>] [--org <value>] [--project <value>] [--env <value>]
[--deployment <value>]

FLAGS
-d, --data-dir=<value> Current working directory
--config=<value> Path to the local '.cs-launch.json' file
--deployment=<value> Deployment UID
--env=<value> Environment name or UID
--org=<value> Organization UID
--project=<value> Project name or UID
-d, --data-dir=<value> Current working directory
--config=<value> Path to the local '.cs-launch.json' file
--env=<value> Environment name or UID
--org=<value> Organization UID
--project=<value> Project name or UID

DESCRIPTION
Open an environment's live site in your browser, or print its URL when there is no terminal. On a terminal, when the
environment has more than one domain, you choose which one to open; --deployment opens that deployment's preview URL
without asking.
environment has more than one domain, you choose which one to open.

EXAMPLES
$ csdx launch:site:open --org <org-uid> --project <name-or-uid> --env <name-or-uid>

$ csdx launch:site:open --org <org-uid> --project <name-or-uid> --env <name-or-uid> --deployment <uid>

$ url=$(csdx launch:site:open --org <org-uid> --project <name-or-uid> --env <name-or-uid>)
```

Expand Down
2 changes: 1 addition & 1 deletion src/commands/launch/deployments/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function commandUnderTest(resolved: Record<string, unknown>, projectType = 'GITP
created.push(params);
return { uid: 'd1', status: 'QUEUED' };
},
get: async () => ({ uid: 'd1', status: 'LIVE' }),
get: async () => ({ uid: 'd1', status: 'LIVE', deploymentUrl: 'my-site.example.test' }),
},
deploymentLogs: { after: async () => [] },
},
Expand Down
153 changes: 5 additions & 148 deletions src/commands/launch/site/open.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { randomBytes } from 'node:crypto';

import { CancelledError, UsageError } from '../../../core/errors';
import type { UxLike } from '../../../core/prompt';
import { DEPLOYMENT_ERROR_MESSAGES } from '../../../deployments/deployment.errors';
import { ENVIRONMENT_ERROR_MESSAGES } from '../../../environments/environment.errors';
import { LaunchApiError } from '../../../transport/errors';
import SiteOpen from './open';

const SCOPE = { org: 'org1', project: 'proj1', environment: 'env1' };
const DEPLOYMENT_UID = randomBytes(12).toString('hex');
const DEPLOYMENT_SCOPE = { ...SCOPE, deployment: DEPLOYMENT_UID };
const PREVIEW_URL = 'https://preview-1a2b.contentstackapps.com';
const LIVE_URL = 'https://my-site.contentstackapps.com';
const DOMAIN_URL = 'https://www.example.com';
const OTHER_DOMAIN_URL = 'https://shop.example.com';
Expand All @@ -25,9 +19,6 @@ interface Harness {
environmentFails?: Error;
latest?: unknown;
latestFails?: Error;
deployment?: string;
fetched?: unknown;
fetchFails?: Error;
}

function commandUnderTest(harness: Harness = {}) {
Expand Down Expand Up @@ -55,7 +46,7 @@ function commandUnderTest(harness: Harness = {}) {

Object.assign(command, {
ux,
resolved: { org: 'org1', project: 'proj1', env: 'env1', deployment: harness.deployment },
resolved: { org: 'org1', project: 'proj1', env: 'env1' },
services: {
ux,
isTTY: harness.isTTY ?? true,
Expand All @@ -75,16 +66,6 @@ function commandUnderTest(harness: Harness = {}) {
},
},
deployments: {
get: async (params: unknown) => {
calls.push('deployments.get');
got.push(params);

if (harness.fetchFails) {
throw harness.fetchFails;
}

return harness.fetched;
},
latest: async (params: unknown) => {
calls.push('deployments.latest');
got.push(params);
Expand Down Expand Up @@ -227,115 +208,6 @@ describe('launch:site:open', () => {
expect(opened).toEqual([]);
});

it("opens the named deployment's preview url, not its deployment url, reading the environment first and never the latest", async () => {
const { command, stdout, calls, got, opened } = commandUnderTest({
deployment: DEPLOYMENT_UID,
fetched: { uid: DEPLOYMENT_UID, deploymentUrl: LIVE_URL, previewUrl: 'preview-1a2b.contentstackapps.com' },
environment: { uid: 'env1', domains: [{ url: 'https://www.example.com' }] },
});

await command.run();

expect(calls).toEqual(['environments.get', 'deployments.get']);
expect(got).toEqual([SCOPE, DEPLOYMENT_SCOPE]);
expect(stdout).toEqual([`\u001b[32m✔ Opening ${PREVIEW_URL} in your browser...\u001b[39m`]);
expect(opened).toEqual([PREVIEW_URL]);
});

it('prints only the preview url and starts no browser for a named deployment when stdout is not a terminal', async () => {
const { command, stdout, stderr, opened } = commandUnderTest({
outputIsTTY: false,
deployment: DEPLOYMENT_UID,
fetched: { uid: DEPLOYMENT_UID, previewUrl: PREVIEW_URL },
});

await command.run();

expect(stdout).toEqual([PREVIEW_URL]);
expect(stderr).toEqual([]);
expect(opened).toEqual([]);
});

it.each([
['absent', undefined],
['empty', ''],
['whitespace only', ' '],
])(
'says the website url was not found in yellow on stdout and exits 2 when the named deployment has a %s preview url',
async (_label, previewUrl) => {
const { command, stdout, stderr, calls, got, opened } = commandUnderTest({
deployment: DEPLOYMENT_UID,
fetched: { uid: DEPLOYMENT_UID, deploymentUrl: LIVE_URL, ...(previewUrl === undefined ? {} : { previewUrl }) },
environment: { uid: 'env1', domains: [{ url: 'https://www.example.com' }] },
});

const code = await exitCodeOf(command.run());

expect(code).toBe(2);
expect(stdout).toEqual(['\u001b[33mWebsite URL not found.\u001b[39m']);
expect(stderr).toEqual([]);
expect(opened).toEqual([]);
expect(calls).toEqual(['environments.get', 'deployments.get']);
expect(got).toEqual([SCOPE, DEPLOYMENT_SCOPE]);
},
);

it('writes the plain message to stderr, nothing to stdout, and exits 2 for a named deployment without a preview url and no terminal', async () => {
const { command, stdout, stderr, opened } = commandUnderTest({
outputIsTTY: false,
deployment: DEPLOYMENT_UID,
fetched: { uid: DEPLOYMENT_UID, deploymentUrl: LIVE_URL },
});

const code = await exitCodeOf(command.run());

expect(code).toBe(2);
expect(stdout).toEqual([]);
expect(stderr).toEqual(['Website URL not found.\n']);
expect(opened).toEqual([]);
});

it('reports a deployment the environment does not have as a usage error in the api wording, printing and opening nothing', async () => {
const notFound = new LaunchApiError(404, [{ code: 'launch.DEPLOYMENT.NOT_FOUND' }], DEPLOYMENT_ERROR_MESSAGES);
const { command, calls, stdout, stderr, opened } = commandUnderTest({
deployment: DEPLOYMENT_UID,
fetchFails: notFound,
});

const error = (await command.run().catch((thrown: unknown) => thrown)) as UsageError;

expect(error).toBeInstanceOf(UsageError);
expect(error.exitCode).toBe(2);
expect(error.message).toBe('No deployment found with that UID.');
expect(calls).toEqual(['environments.get', 'deployments.get']);
expect(stdout).toEqual([]);
expect(stderr).toEqual([]);
expect(opened).toEqual([]);
});

it('propagates any other failure reading the named deployment untouched, printing and opening nothing', async () => {
const failure = new LaunchApiError(500, []);
const { command, calls, stdout, stderr, opened } = commandUnderTest({
deployment: DEPLOYMENT_UID,
fetchFails: failure,
});

await expect(command.run()).rejects.toBe(failure);
expect(failure.exitCode).toBe(1);
expect(calls).toEqual(['environments.get', 'deployments.get']);
expect(stdout).toEqual([]);
expect(stderr).toEqual([]);
expect(opened).toEqual([]);
});

it('reads no deployment when the environment is missing, even with --deployment', async () => {
const failure = new LaunchApiError(500, []);
const { command, calls } = commandUnderTest({ deployment: DEPLOYMENT_UID, environmentFails: failure });

await expect(command.run()).rejects.toBe(failure);
expect(calls).toEqual(['environments.get']);
});

it('asks which domain to open, as a single-select list with the default preselected, and opens only the one picked', async () => {
const { command, stdout, calls, opened, asked } = commandUnderTest({
environment: { uid: 'env1', domains: [{ url: DOMAIN_URL }, { url: 'shop.example.com' }] },
Expand Down Expand Up @@ -452,20 +324,6 @@ describe('launch:site:open', () => {
expect(opened).toEqual([LIVE_URL]);
});

it('asks nothing for a named deployment even when the environment has domains', async () => {
const { command, calls, opened, asked } = commandUnderTest({
deployment: DEPLOYMENT_UID,
fetched: { uid: DEPLOYMENT_UID, previewUrl: PREVIEW_URL },
environment: { uid: 'env1', domains: [{ url: DOMAIN_URL }, { url: OTHER_DOMAIN_URL }] },
});

await command.run();

expect(asked).toEqual([]);
expect(opened).toEqual([PREVIEW_URL]);
expect(calls).toEqual(['environments.get', 'deployments.get']);
});

it.each([[[]], [[{ url: DOMAIN_URL }, { url: OTHER_DOMAIN_URL }]]])(
'exits 2 with the website url not found line and asks nothing when there is no deployment and domains %j',
async (domains) => {
Expand All @@ -483,24 +341,23 @@ describe('launch:site:open', () => {
},
);

it('declares no --domain flag', () => {
expect(Object.keys(SiteOpen.flags)).not.toContain('domain');
it.each([['domain'], ['deployment']])('declares no --%s flag', (flag) => {
expect(Object.keys(SiteOpen.flags)).not.toContain(flag);
});

it('describes the domain prompt in its help', () => {
expect(SiteOpen.description).toContain('choose which one to open');
expect(SiteOpen.description).toContain('--deployment');
expect(SiteOpen.description).not.toContain('--deployment');
expect(SiteOpen.examples).toContain(
'$ url=$(csdx launch:site:open --org <org-uid> --project <name-or-uid> --env <name-or-uid>)',
);
});

it('declares org, project and env as required inputs and --deployment as optional', () => {
it('declares org, project and env as its only inputs, all required', () => {
expect(SiteOpen.inputs).toEqual({
org: { required: true },
project: { required: true },
env: { required: true },
deployment: {},
});
});
});
Loading
Loading