Skip to content

Commit

Permalink
feat(CLI Onboarding): Auto login if org provided or configured
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Jan 14, 2022
1 parent 3580cb9 commit dcf5273
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/cli/interactive-setup/dashboard-login.js
Expand Up @@ -18,8 +18,11 @@ const loginOrRegisterQuestion = async (stepHistory) =>

const steps = {
loginOrRegister: async (context) => {
const result = await loginOrRegisterQuestion(context.stepHistory);
if (result) {
const shouldLoginOrRegister =
context.options.org ||
context.configuration.org ||
(await loginOrRegisterQuestion(context.stepHistory));
if (shouldLoginOrRegister) {
await login({ isInteractive: true });
}
},
Expand Down Expand Up @@ -66,10 +69,18 @@ module.exports = {
return !isLoggedIn;
},
async run(context) {
legacy.write(
'Enable Serverless Dashboard to get enhanced monitoring, logs and secrets management: https://serverless.com/monitoring\n\n'
);
if (context.initial.isInServiceContext && !context.initial.isDashboardEnabled) {
const isOrgProvided = context.options.org || context.configuration.org;
if (!isOrgProvided) {
legacy.write(
'Enable Serverless Dashboard to get enhanced monitoring, logs and secrets management: https://serverless.com/monitoring\n\n'
);
}

if (
context.initial.isInServiceContext &&
!context.initial.isDashboardEnabled &&
!isOrgProvided
) {
showOnboardingWelcome(context);
}

Expand Down
40 changes: 40 additions & 0 deletions test/unit/lib/cli/interactive-setup/dashboard-login.test.js
Expand Up @@ -139,6 +139,46 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-login.test.js', function
);
});

it('Should login and skip question when user providers `org` option', async () => {
const loginStep = proxyquire('../../../../../lib/cli/interactive-setup/dashboard-login', {
'@serverless/dashboard-plugin/lib/login': loginStub,
'@serverless/platform-client': {
ServerlessSDK: ServerlessSDKMock,
},
});
const context = {
serviceDir: process.cwd(),
configuration: { provider: { name: 'aws', runtime: 'nodejs12.x' } },
configurationFilename: 'serverless.yml',
options: { org: 'someorg' },
initial: {},
inquirer,
stepHistory: new StepHistory(),
};
await loginStep.run(context);
expect(loginStub.calledOnce).to.be.true;
});

it('Should login and skip question when `org` configured', async () => {
const loginStep = proxyquire('../../../../../lib/cli/interactive-setup/dashboard-login', {
'@serverless/dashboard-plugin/lib/login': loginStub,
'@serverless/platform-client': {
ServerlessSDK: ServerlessSDKMock,
},
});
const context = {
serviceDir: process.cwd(),
configuration: { org: 'someorg', provider: { name: 'aws', runtime: 'nodejs12.x' } },
configurationFilename: 'serverless.yml',
options: {},
initial: {},
inquirer,
stepHistory: new StepHistory(),
};
await loginStep.run(context);
expect(loginStub.calledOnce).to.be.true;
});

it('Should not login when user decides not to login/register', async () => {
configureInquirerStub(inquirer, {
confirm: { shouldLoginOrRegister: false },
Expand Down

0 comments on commit dcf5273

Please sign in to comment.