Skip to content

Commit

Permalink
revert(ui): add better message when user doesn't have permission (#436)
Browse files Browse the repository at this point in the history
This reverts commit 2f2f986.

Co-authored-by: Yassine <ylakhdar@coveo.com>

CDX-541
  • Loading branch information
louis-bompart authored Aug 17, 2021
1 parent 46947b3 commit 3eb2d06
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 799 deletions.
69 changes: 0 additions & 69 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

452 changes: 0 additions & 452 deletions packages/cli/patches/@coveord+platform-client+24.1.0.patch

This file was deleted.

35 changes: 5 additions & 30 deletions packages/cli/src/commands/ui/create/angular.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jest.mock('../../../lib/decorators/preconditions/npm');
jest.mock('../../../lib/decorators/preconditions/node');
jest.mock('../../../lib/decorators/preconditions/apiKeyPrivilege');
jest.mock('../../../lib/utils/process');
jest.mock('../../../lib/oauth/oauth');
jest.mock('../../../lib/config/config');
Expand All @@ -20,7 +19,6 @@ import {Config, Configuration} from '../../../lib/config/config';
import {
IsNpmVersionInRange,
IsNodeVersionInRange,
HasNecessaryCoveoPrivileges,
} from '../../../lib/decorators/preconditions/';
import {getPackageVersion} from '../../../lib/utils/misc';
import Command from '@oclif/command';
Expand All @@ -34,12 +32,9 @@ describe('ui:create:angular', () => {
const mockedIsNpmVersionInRange = mocked(IsNpmVersionInRange, true);
const mockedIsNodeVersionInRange = mocked(IsNodeVersionInRange, true);
const angularAppExecutable = join('@angular', 'cli', 'lib', 'init.js');
const mockedApiKeyPrivilege = mocked(HasNecessaryCoveoPrivileges, true);
const mockedCreateImpersonateApiKey = jest.fn();
const preconditionStatus = {
node: true,
npm: true,
apiKey: true,
};
const doMockPreconditions = function () {
const mockNode = function (_target: Command) {
Expand All @@ -50,14 +45,8 @@ describe('ui:create:angular', () => {
const mockNpm = function (_target: Command) {
return new Promise<boolean>((resolve) => resolve(preconditionStatus.npm));
};
const mockApiKeyPrivilege = function (_target: Command) {
return new Promise<boolean>((resolve) =>
resolve(preconditionStatus.apiKey)
);
};
mockedIsNodeVersionInRange.mockReturnValue(mockNode);
mockedIsNpmVersionInRange.mockReturnValue(mockNpm);
mockedApiKeyPrivilege.mockReturnValue(mockApiKeyPrivilege);
};

const doMockSpawnProcess = () => {
Expand All @@ -84,14 +73,13 @@ describe('ui:create:angular', () => {
};

const doMockAuthenticatedClient = () => {
mockedCreateImpersonateApiKey.mockImplementation((_name: string) =>
Promise.resolve({value: 'foo'})
);

mockedAuthenticatedClient.mockImplementation(
() =>
({
createImpersonateApiKey: mockedCreateImpersonateApiKey,
createImpersonateApiKey: (_name: string) =>
Promise.resolve({
value: 'foo',
}),
getUserInfo: () =>
Promise.resolve({
username: 'bob@coveo.com',
Expand All @@ -106,7 +94,7 @@ describe('ui:create:angular', () => {
})
),
cfg: mockedConfig.getMockImplementation()!('./'),
} as unknown as AuthenticatedClient)
} as AuthenticatedClient)
);
};

Expand All @@ -128,26 +116,13 @@ describe('ui:create:angular', () => {
doMockPreconditions();
preconditionStatus.npm = true;
preconditionStatus.node = true;
preconditionStatus.apiKey = true;
});

afterEach(() => {
mockedIsNodeVersionInRange.mockClear();
mockedIsNpmVersionInRange.mockClear();
});

test
.do(() => {
preconditionStatus.apiKey = false;
})
.command(['ui:create:angular', 'myapp'])
.it(
'should not execute the command if the API key preconditions are not respected',
async () => {
expect(mockedCreateImpersonateApiKey).toHaveBeenCalledTimes(0);
}
);

test
.do(() => {
preconditionStatus.npm = false;
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/ui/create/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
IsAuthenticated,
IsNodeVersionInRange,
IsNpmVersionInRange,
HasNecessaryCoveoPrivileges,
} from '../../../lib/decorators/preconditions/';

export default class Angular extends Command {
Expand Down Expand Up @@ -52,8 +51,7 @@ export default class Angular extends Command {
@Preconditions(
IsAuthenticated(),
IsNodeVersionInRange(Angular.requiredNodeVersion),
IsNpmVersionInRange(Angular.requiredNpmVersion),
HasNecessaryCoveoPrivileges()
IsNpmVersionInRange(Angular.requiredNpmVersion)
)
public async run() {
const {args, flags} = this.parse(Angular);
Expand Down
36 changes: 5 additions & 31 deletions packages/cli/src/commands/ui/create/react.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jest.mock('../../../lib/decorators/preconditions/npx');
jest.mock('../../../lib/decorators/preconditions/node');
jest.mock('../../../lib/decorators/preconditions/apiKeyPrivilege');
jest.mock('../../../lib/utils/process');
jest.mock('../../../lib/oauth/oauth');
jest.mock('../../../lib/config/config');
Expand All @@ -21,7 +20,6 @@ import {Config, Configuration} from '../../../lib/config/config';
import {
IsNpxInstalled,
IsNodeVersionInRange,
HasNecessaryCoveoPrivileges,
} from '../../../lib/decorators/preconditions/';
import {getPackageVersion} from '../../../lib/utils/misc';
import Command from '@oclif/command';
Expand All @@ -37,16 +35,13 @@ describe('ui:create:react', () => {
const mockedAuthenticatedClient = mocked(AuthenticatedClient);
const mockedIsNpxInstalled = mocked(IsNpxInstalled, true);
const mockedIsNodeVersionInRange = mocked(IsNodeVersionInRange, true);
const mockedApiKeyPrivilege = mocked(HasNecessaryCoveoPrivileges, true);
const mockedCreateImpersonateApiKey = jest.fn();
const processExitCode = {
spawn: 0,
spawnOutput: 0,
};
const preconditionStatus = {
node: true,
npx: true,
apiKey: true,
};
const doMockPreconditions = function () {
const mockNode = function (_target: Command) {
Expand All @@ -57,14 +52,8 @@ describe('ui:create:react', () => {
const mockNpx = function (_target: Command) {
return new Promise<boolean>((resolve) => resolve(preconditionStatus.npx));
};
const mockApiKeyPrivilege = function (_target: Command) {
return new Promise<boolean>((resolve) =>
resolve(preconditionStatus.apiKey)
);
};
mockedIsNodeVersionInRange.mockReturnValue(mockNode);
mockedIsNpxInstalled.mockReturnValue(mockNpx);
mockedApiKeyPrivilege.mockReturnValue(mockApiKeyPrivilege);
};

const doMockSpawnProcess = () => {
Expand Down Expand Up @@ -101,14 +90,13 @@ describe('ui:create:react', () => {
};

const doMockAuthenticatedClient = () => {
mockedCreateImpersonateApiKey.mockImplementation((_name: string) =>
Promise.resolve({value: 'foo'})
);

mockedAuthenticatedClient.mockImplementation(
() =>
({
createImpersonateApiKey: mockedCreateImpersonateApiKey,
createImpersonateApiKey: (_name: string) =>
Promise.resolve({
value: 'foo',
}),
getUserInfo: () =>
Promise.resolve({
username: 'bob@coveo.com',
Expand All @@ -123,7 +111,7 @@ describe('ui:create:react', () => {
})
),
cfg: mockedConfig.getMockImplementation()!('./'),
} as unknown as AuthenticatedClient)
} as AuthenticatedClient)
);
};

Expand All @@ -145,29 +133,15 @@ describe('ui:create:react', () => {
doMockPreconditions();
preconditionStatus.npx = true;
preconditionStatus.node = true;
preconditionStatus.apiKey = true;
processExitCode.spawn = 0;
processExitCode.spawnOutput = 0;
});

afterEach(() => {
mockedIsNodeVersionInRange.mockClear();
mockedIsNpxInstalled.mockClear();
mockedApiKeyPrivilege.mockClear();
});

test
.do(() => {
preconditionStatus.apiKey = false;
})
.command(['ui:create:react', 'myapp'])
.it(
'should not execute the command if the API key preconditions are not respected',
async () => {
expect(mockedCreateImpersonateApiKey).toHaveBeenCalledTimes(0);
}
);

test
.do(() => {
preconditionStatus.npx = false;
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/ui/create/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
IsAuthenticated,
IsNodeVersionInRange,
IsNpxInstalled,
HasNecessaryCoveoPrivileges,
} from '../../../lib/decorators/preconditions';
import {appendCmdIfWindows} from '../../../lib/utils/os';
import {EOL} from 'os';
Expand Down Expand Up @@ -57,8 +56,7 @@ export default class React extends Command {
@Preconditions(
IsAuthenticated(),
IsNodeVersionInRange(React.requiredNodeVersion),
IsNpxInstalled(),
HasNecessaryCoveoPrivileges()
IsNpxInstalled()
)
public async run() {
const args = this.args;
Expand Down
Loading

0 comments on commit 3eb2d06

Please sign in to comment.