Skip to content

Commit 0f83818

Browse files
authored
test: e2e tests batch-2 (#1086)
1 parent 551cf55 commit 0f83818

12 files changed

Lines changed: 359 additions & 19 deletions

File tree

src/commands/actors/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ApifyApiError } from 'apify-client';
22

33
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
44
import { Args } from '../../lib/command-framework/args.js';
5+
import { YesFlag } from '../../lib/command-framework/flags.js';
56
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
67
import { error, info, success } from '../../lib/outputs.js';
78
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -32,8 +33,13 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {
3233
}),
3334
};
3435

36+
static override flags = {
37+
...YesFlag,
38+
};
39+
3540
async run() {
3641
const { actorId } = this.args;
42+
const { yes } = this.flags;
3743

3844
const apifyClient = await getLoggedClientOrThrow();
3945

@@ -46,6 +52,7 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {
4652

4753
const confirmedDelete = await useYesNoConfirm({
4854
message: `Are you sure you want to delete this Actor?`,
55+
providedConfirmFromStdin: yes || undefined,
4956
});
5057

5158
if (!confirmedDelete) {

src/commands/builds/remove-tag.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
22
import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
5-
import { Flags } from '../../lib/command-framework/flags.js';
5+
import { Flags, YesFlag } from '../../lib/command-framework/flags.js';
66
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
77
import { error, info, success } from '../../lib/outputs.js';
88
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -36,11 +36,7 @@ export class BuildsRemoveTagCommand extends ApifyCommand<typeof BuildsRemoveTagC
3636
description: 'The tag to remove from the build.',
3737
required: true,
3838
}),
39-
yes: Flags.boolean({
40-
char: 'y',
41-
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
42-
default: false,
43-
}),
39+
...YesFlag,
4440
};
4541

4642
async run() {

src/commands/builds/rm.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
22

33
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
44
import { Args } from '../../lib/command-framework/args.js';
5+
import { YesFlag } from '../../lib/command-framework/flags.js';
56
import { useInputConfirmation } from '../../lib/hooks/user-confirmations/useInputConfirmation.js';
67
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
78
import { error, info, success } from '../../lib/outputs.js';
@@ -33,8 +34,13 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
3334
}),
3435
};
3536

37+
static override flags = {
38+
...YesFlag,
39+
};
40+
3641
async run() {
3742
const { buildId } = this.args;
43+
const { yes } = this.flags;
3844

3945
const apifyClient = await getLoggedClientOrThrow();
4046

@@ -60,11 +66,21 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
6066
}
6167

6268
// If the build is tagged, console asks you to confirm by typing in the tag. Otherwise, it asks you to confirm with a yes/no question.
63-
const confirmed = await (confirmationPrompt ? useInputConfirmation : useYesNoConfirm)({
64-
message: `Are you sure you want to delete this Actor Build?${confirmationPrompt ? ` If so, please type in "${confirmationPrompt}":` : ''}`,
65-
expectedValue: confirmationPrompt ?? '',
66-
failureMessage: 'Your provided value does not match the build tag.',
67-
});
69+
let confirmed: string | boolean;
70+
71+
if (confirmationPrompt) {
72+
confirmed = await useInputConfirmation({
73+
message: `Are you sure you want to delete this Actor Build? If so, please type in "${confirmationPrompt}":`,
74+
expectedValue: confirmationPrompt,
75+
failureMessage: 'Your provided value does not match the build tag.',
76+
providedConfirmFromStdin: yes ? confirmationPrompt : undefined,
77+
});
78+
} else {
79+
confirmed = await useYesNoConfirm({
80+
message: `Are you sure you want to delete this Actor Build?`,
81+
providedConfirmFromStdin: yes || undefined,
82+
});
83+
}
6884

6985
if (!confirmed) {
7086
info({

src/commands/datasets/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetDataset } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
@@ -34,8 +35,13 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {
3435
}),
3536
};
3637

38+
static override flags = {
39+
...YesFlag,
40+
};
41+
3742
async run() {
3843
const { datasetNameOrId } = this.args;
44+
const { yes } = this.flags;
3945

4046
const client = await getLoggedClientOrThrow();
4147

@@ -51,6 +57,7 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {
5157

5258
const confirmed = await useYesNoConfirm({
5359
message: `Are you sure you want to delete this Dataset?`,
60+
providedConfirmFromStdin: yes || undefined,
5461
});
5562

5663
if (!confirmed) {

src/commands/init.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'node:process';
33

44
import { ApifyCommand } from '../lib/command-framework/apify-command.js';
55
import { Args } from '../lib/command-framework/args.js';
6-
import { Flags } from '../lib/command-framework/flags.js';
6+
import { Flags, YesFlag } from '../lib/command-framework/flags.js';
77
import { CommandExitCodes, DEFAULT_LOCAL_STORAGE_DIR, EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH } from '../lib/consts.js';
88
import { useActorConfig } from '../lib/hooks/useActorConfig.js';
99
import { ProjectLanguage, useCwdProject } from '../lib/hooks/useCwdProject.js';
@@ -55,12 +55,7 @@ export class InitCommand extends ApifyCommand<typeof InitCommand> {
5555
};
5656

5757
static override flags = {
58-
yes: Flags.boolean({
59-
char: 'y',
60-
description:
61-
'Automatic yes to prompts; assume "yes" as answer to all prompts. Note that in some cases, the command may still ask for confirmation.',
62-
required: false,
63-
}),
58+
...YesFlag,
6459
dockerfile: Flags.string({
6560
description: 'Path to a Dockerfile to use for the Actor (e.g., "./Dockerfile" or "./docker/Dockerfile").',
6661
required: false,

src/commands/key-value-stores/delete-value.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info } from '../../lib/outputs.js';
@@ -38,8 +39,13 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal
3839
}),
3940
};
4041

42+
static override flags = {
43+
...YesFlag,
44+
};
45+
4146
async run() {
4247
const { storeId, itemKey } = this.args;
48+
const { yes } = this.flags;
4349

4450
const apifyClient = await getLoggedClientOrThrow();
4551
const maybeStore = await tryToGetKeyValueStore(apifyClient, storeId);
@@ -65,6 +71,7 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal
6571

6672
const confirm = await useYesNoConfirm({
6773
message: `Are you sure you want to delete this record?`,
74+
providedConfirmFromStdin: yes || undefined,
6875
});
6976

7077
if (!confirm) {

src/commands/key-value-stores/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
@@ -34,8 +35,13 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR
3435
}),
3536
};
3637

38+
static override flags = {
39+
...YesFlag,
40+
};
41+
3742
async run() {
3843
const { keyValueStoreNameOrId } = this.args;
44+
const { yes } = this.flags;
3945

4046
const client = await getLoggedClientOrThrow();
4147

@@ -51,6 +57,7 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR
5157

5258
const confirmed = await useYesNoConfirm({
5359
message: `Are you sure you want to delete this Key-value store?`,
60+
providedConfirmFromStdin: yes || undefined,
5461
});
5562

5663
if (!confirmed) {

src/commands/runs/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ACTOR_JOB_STATUSES } from '@apify/consts';
44

55
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
66
import { Args } from '../../lib/command-framework/args.js';
7+
import { YesFlag } from '../../lib/command-framework/flags.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
910
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -41,8 +42,13 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
4142
}),
4243
};
4344

45+
static override flags = {
46+
...YesFlag,
47+
};
48+
4449
async run() {
4550
const { runId } = this.args;
51+
const { yes } = this.flags;
4652

4753
const apifyClient = await getLoggedClientOrThrow();
4854

@@ -63,6 +69,7 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
6369

6470
const confirmedDelete = await useYesNoConfirm({
6571
message: `Are you sure you want to delete this Actor Run?`,
72+
providedConfirmFromStdin: yes || undefined,
6673
});
6774

6875
if (!confirmedDelete) {

src/lib/command-framework/flags.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export const Flags = {
6464
integer: integerFlag,
6565
};
6666

67+
/** Reusable `--yes` / `-y` flag for commands with confirmation prompts. */
68+
export const YesFlag = {
69+
yes: Flags.boolean({
70+
char: 'y',
71+
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
72+
default: false,
73+
}),
74+
};
75+
6776
function stringFlag<const Choices extends string[], const T extends StringFlagOptions<readonly string[]>>(
6877
options: T & { choices?: Choices },
6978
): TaggedFlagBuilder<'string', Choices, T['default'] extends string ? true : T['required'], T['default']> {

test/e2e/commands/builds/create-info-ls.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('[e2e][api] builds namespace', () => {
4545
const me = await client.user('me').get();
4646
await client.actor(`${me.username}/${actor.name}`).delete();
4747
} catch {
48-
// Best-effort cleanup
48+
// Do nothing
4949
}
5050
}
5151

0 commit comments

Comments
 (0)