Skip to content

Commit

Permalink
feat(snapshot): add a --wait flag on all org:config:* commands (#397
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar and louis-bompart authored Aug 11, 2021
1 parent 2fde919 commit a74c1de
Show file tree
Hide file tree
Showing 16 changed files with 631 additions and 408 deletions.
170 changes: 86 additions & 84 deletions packages/angular/package-lock.json

Large diffs are not rendered by default.

391 changes: 268 additions & 123 deletions packages/cli/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@angular/cli": "^12.1.1",
"@coveo/bueno": "^0.32.0",
"@coveo/push-api-client": "^1.1.2",
"@coveord/platform-client": "^24.0.0",
"@coveord/platform-client": "^24.1.0",
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^3",
Expand All @@ -26,7 +26,6 @@
"coveo.analytics": "^2.18.4",
"create-react-app": "^4.0.3",
"decompress": "^4.2.1",
"exponential-backoff": "^3.1.0",
"extract-zip": "^2.0.1",
"fs-extra": "^10.0.0",
"isomorphic-fetch": "^3.0.0",
Expand All @@ -45,6 +44,7 @@
"@oclif/errors": "1.3.5",
"@oclif/test": "1.2.8",
"@types/archiver": "5.1.1",
"@types/async-retry": "^1.4.3",
"@types/cli-progress": "3.9.2",
"@types/fs-extra": "9.0.12",
"@types/jest": "26.0.24",
Expand Down
33 changes: 17 additions & 16 deletions packages/cli/src/commands/org/config/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
Preconditions,
} from '../../../lib/decorators/preconditions';
import {ReportViewerStyles} from '../../../lib/snapshot/reportPreviewer/reportPreviewerStyles';
import {Snapshot, waitUntilDoneOptions} from '../../../lib/snapshot/snapshot';
import {Snapshot, WaitUntilDoneOptions} from '../../../lib/snapshot/snapshot';
import {
waitFlag,
getTargetOrg,
handleSnapshotError,
} from '../../../lib/snapshot/snapshotCommon';
Expand All @@ -22,6 +23,7 @@ export default class Monitor extends Command {
public static description = 'Monitor a Snapshot operation';

public static flags = {
...waitFlag,
target: flags.string({
char: 't',
description:
Expand All @@ -43,9 +45,9 @@ export default class Monitor extends Command {

@Preconditions(IsAuthenticated())
public async run() {
const snapshot = await this.getSnapshot();
this.printHeader();

this.printHeader(snapshot.id);
const snapshot = await this.getSnapshot();

await this.monitorSnapshot(snapshot);
this.config.runHook('analytics', buildAnalyticsSuccessHook(this, flags));
Expand All @@ -66,19 +68,19 @@ export default class Monitor extends Command {
this.getReportStatus(snapshot.latestReport)
);

// TODO: revisit with a progress bar once the response contains the remaining resources to process
const iteratee = (report: ResourceSnapshotsReportModel) =>
this.refresh(report);
await snapshot.waitUntilDone(this.waitOptions, iteratee);
await snapshot.waitUntilDone(this.waitOption);

cli.action.stop(this.getReportStatus(snapshot.latestReport));
}

private printHeader(snapshotId: string) {
private printHeader() {
const {args} = this.parse(Monitor);
const snapshotId = args.snapshotId;
const header = ReportViewerStyles.header(
`\nMonitoring snapshot ${snapshotId}:`
`Monitoring snapshot ${snapshotId}`
);
cli.log(header);
cli.log('');
cli.action.start(header);
}

private prettyPrint(str: string): string {
Expand Down Expand Up @@ -109,13 +111,12 @@ export default class Monitor extends Command {
return SnapshotFactory.createFromExistingSnapshot(snapshotId, target);
}

private get waitOptions(): waitUntilDoneOptions {
private get waitOption(): WaitUntilDoneOptions {
const {flags} = this.parse(Monitor);
return {
waitOptions: {
numOfAttempts: Infinity,
delayFirstAttempt: false,
maxDelay: 10e3,
},
wait: flags.wait,
// TODO: revisit with a progress bar once the response contains the remaining resources to process
onRetryCb: (report: ResourceSnapshotsReportModel) => this.refresh(report),
};
}

Expand Down
30 changes: 26 additions & 4 deletions packages/cli/src/commands/org/config/preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ describe('org:config:preview', () => {
.it('should work with default connected org', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo'
'foo',
expect.objectContaining({})
);
});

Expand All @@ -134,20 +135,41 @@ describe('org:config:preview', () => {
.it('should work with specified target org', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'myorg'
'myorg',
expect.objectContaining({})
);
});

test
.command(['org:config:preview'])
.it('should set a 60 seconds wait', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo',
{wait: 60}
);
});

test
.command(['org:config:preview', '-m', '312'])
.it('should set a 312 seconds wait', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo',
{wait: 312}
);
});

test
.command(['org:config:preview'])
.it('#validate should not take into account missing resources', () => {
expect(mockedValidateSnapshot).toHaveBeenCalledWith(false);
expect(mockedValidateSnapshot).toHaveBeenCalledWith(false, {wait: 60});
});

test
.command(['org:config:preview', '-d'])
.it('#validate should take into account missing resoucres', () => {
expect(mockedValidateSnapshot).toHaveBeenCalledWith(true);
expect(mockedValidateSnapshot).toHaveBeenCalledWith(true, {wait: 60});
});

test
Expand Down
20 changes: 13 additions & 7 deletions packages/cli/src/commands/org/config/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import {
displayInvalidSnapshotError,
displaySnapshotSynchronizationWarning,
dryRun,
DryRunOptions,
getTargetOrg,
handleSnapshotError,
waitFlag,
DryRunOptions,
} from '../../../lib/snapshot/snapshotCommon';

export default class Preview extends Command {
public static description = 'Preview resource updates';

public static flags = {
...waitFlag,
target: flags.string({
char: 't',
description:
Expand Down Expand Up @@ -55,17 +57,13 @@ export default class Preview extends Command {
public async run() {
const {flags} = this.parse(Preview);
const target = await getTargetOrg(this.configuration, flags.target);
const options: DryRunOptions = {
deleteMissingResources: flags.showMissingResources,
snapshotId: flags.snapshotId,
};
const {reporter, snapshot, project} = await dryRun(
target,
this.projectPath,
options
this.options
);

await snapshot.preview(project, options.deleteMissingResources);
await snapshot.preview(project, this.options.deleteMissingResources);

if (reporter.isSuccessReport()) {
await snapshot.delete();
Expand Down Expand Up @@ -116,6 +114,14 @@ export default class Preview extends Command {
displayInvalidSnapshotError(snapshot, cfg, this.projectPath);
}

private get options(): DryRunOptions {
const {flags} = this.parse(Preview);
return {
deleteMissingResources: flags.showMissingResources,
waitUntilDone: {wait: flags.wait},
};
}

private get configuration() {
return new Config(this.config.configDir, this.error);
}
Expand Down
26 changes: 24 additions & 2 deletions packages/cli/src/commands/org/config/pull.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ describe('org:config:pull', () => {
'SEARCH_PAGE',
'EXTENSION',
]),
'default-org'
'default-org',
expect.objectContaining({})
);
});

Expand All @@ -90,7 +91,28 @@ describe('org:config:pull', () => {
.it('should select specified resource types', () => {
expect(mockedSnapshotFactory.createFromOrg).toHaveBeenCalledWith(
['FIELD', 'FEATURED_RESULT', 'SOURCE'],
'default-org'
'default-org',
expect.objectContaining({})
);
});

test
.command(['org:config:pull'])
.it('should set a 60 seconds timeout', () => {
expect(mockedSnapshotFactory.createFromOrg).toHaveBeenCalledWith(
expect.arrayContaining([]),
'default-org',
{wait: 60}
);
});

test
.command(['org:config:pull', '-m', '78'])
.it('should set a 78 seconds timeout', () => {
expect(mockedSnapshotFactory.createFromOrg).toHaveBeenCalledWith(
expect.arrayContaining([]),
'default-org',
{wait: 78}
);
});

Expand Down
15 changes: 12 additions & 3 deletions packages/cli/src/commands/org/config/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
import {IsGitInstalled} from '../../../lib/decorators/preconditions/git';
import {SnapshotOperationTimeoutError} from '../../../lib/errors';
import {Project} from '../../../lib/project/project';
import {Snapshot} from '../../../lib/snapshot/snapshot';
import {Snapshot, WaitUntilDoneOptions} from '../../../lib/snapshot/snapshot';
import {
waitFlag,
getTargetOrg,
handleSnapshotError,
} from '../../../lib/snapshot/snapshotCommon';
Expand All @@ -26,6 +27,7 @@ export default class Pull extends Command {
public static description = 'Pull resources from an organization';

public static flags = {
...waitFlag,
target: flags.string({
char: 't',
helpValue: 'destinationorganizationg7dg3gd',
Expand Down Expand Up @@ -115,16 +117,23 @@ export default class Pull extends Command {
cli.action.start('Retrieving Snapshot');
return SnapshotFactory.createFromExistingSnapshot(
flags.snapshotId,
target
target,
this.waitOption
);
}
cli.action.start('Creating Snapshot');
return SnapshotFactory.createFromOrg(
this.resourceSnapshotTypesToExport,
target
target,
this.waitOption
);
}

private get waitOption(): WaitUntilDoneOptions {
const {flags} = this.parse(Pull);
return {wait: flags.wait};
}

private get configuration() {
return new Config(this.config.configDir, this.error);
}
Expand Down
32 changes: 28 additions & 4 deletions packages/cli/src/commands/org/config/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ describe('org:config:push', () => {
.it('should work with default connected org', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo'
'foo',
expect.objectContaining({})
);
});

Expand All @@ -168,22 +169,45 @@ describe('org:config:push', () => {
.it('should work with specified target org', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'myorg'
'myorg',
expect.objectContaining({})
);
});

test
.stub(cli, 'confirm', () => async () => true)
.command(['org:config:push'])
.it('should set a 60 seconds wait', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo',
{wait: 60}
);
});

test
.stub(cli, 'confirm', () => async () => true)
.command(['org:config:push', '-m', '99'])
.it('should set a 99 seconds wait', () => {
expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith(
normalize(join('path', 'to', 'resources.zip')),
'foo',
{wait: 99}
);
});

test
.stub(cli, 'confirm', () => async () => true)
.command(['org:config:push'])
.it('#should not apply missing resources', () => {
expect(mockedApplySnapshot).toHaveBeenCalledWith(false);
expect(mockedApplySnapshot).toHaveBeenCalledWith(false, {wait: 60});
});

test
.stub(cli, 'confirm', () => async () => true)
.command(['org:config:push', '-d'])
.it('should apply missing resoucres', () => {
expect(mockedApplySnapshot).toHaveBeenCalledWith(true);
expect(mockedApplySnapshot).toHaveBeenCalledWith(true, {wait: 60});
});

test
Expand Down
Loading

0 comments on commit a74c1de

Please sign in to comment.