Skip to content

Commit

Permalink
test: Change stubs in outputCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Mar 2, 2021
1 parent 7ff34f6 commit a0b0b53
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 147 deletions.
182 changes: 36 additions & 146 deletions lib/outputCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,6 @@ const runServerless = require('../test/run-serverless');
const platformClientPath = require.resolve('@serverless/platform-client');
const configUtilsPath = require.resolve('@serverless/utils/config');

const getStateVariableStub = sinon.stub().resolves({
value: 'output-value',
});

const getServiceStub = sinon.stub().resolves({
stagesAndRegions: {
dev: {
'us-east-1': {
outputs: {
stringOutputName: 'stringOutputValue',
objectOutputName: { objectOutputPropName: 'objectOutputPropValue' },
arrayOutputName: ['arrayOutputItem', 'item2'],
},
},
'us-east-2': {
outputs: {
usEast2OutputName: 'usEast2OutputValue',
},
},
},
other: {
'us-east-1': {
outputs: {
otherOutputName: 'otherOutputValue',
},
},
},
},
});

const modulesCacheStub = {
[configUtilsPath]: {
...configUtils,
Expand All @@ -49,8 +19,34 @@ const modulesCacheStub = {
ServerlessSDK: class ServerlessSDK {
constructor() {
this.services = {
get: getServiceStub,
getStateVariable: getStateVariableStub,
get: async () => ({
stagesAndRegions: {
dev: {
'us-east-1': {
outputs: {
stringOutputName: 'stringOutputValue',
objectOutputName: { objectOutputPropName: 'objectOutputPropValue' },
arrayOutputName: ['arrayOutputItem', 'item2'],
},
},
'us-east-2': {
outputs: {
usEast2OutputName: 'usEast2OutputValue',
},
},
},
other: {
'us-east-1': {
outputs: {
otherOutputName: 'otherOutputValue',
},
},
},
},
}),
getStateVariable: async () => ({
value: 'output-value',
}),
};
}

Expand Down Expand Up @@ -126,21 +122,11 @@ describe('outputCommand', function () {
}
});
it('Should support `--org` `--app` CLI params', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'list', '--org', 'some-org', '--app', 'some-app'],
modulesCacheStub,
});
expect(getServiceStub.args[0][0]).to.deep.equal({
appName: 'some-app',
orgName: 'some-org',
serviceName,
});

expect(stdoutData).to.include('stringOutputName');
expect(stdoutData).to.include('stringOutputValue');
Expand All @@ -166,12 +152,6 @@ describe('outputCommand', function () {
modulesCacheStub,
});

expect(getServiceStub.args[0][0]).to.deep.equal({
appName: 'some-app',
orgName: 'some-org',
serviceName: 'cli-service',
});

expect(stdoutData).to.include('stringOutputName');
expect(stdoutData).to.include('stringOutputValue');
expect(stdoutData).to.include('objectOutputName');
Expand All @@ -182,62 +162,32 @@ describe('outputCommand', function () {
});

it('Should support `--stage` CLI param', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'list', '--stage', 'other'],
modulesCacheStub,
});
expect(getServiceStub.args[0][0]).to.deep.equal({
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName,
});

expect(stdoutData).to.include('otherOutputName');
expect(stdoutData).to.include('otherOutputName');
});
it('Should support `--region` CLI param', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'list', '--region', 'us-east-2'],
modulesCacheStub,
});
expect(getServiceStub.args[0][0]).to.deep.equal({
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName,
});

expect(stdoutData).to.include('usEast2OutputName');
expect(stdoutData).to.include('usEast2OutputValue');
});

it('Should read configuration from config file', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'list'],
modulesCacheStub,
});
expect(getServiceStub.args[0][0]).to.deep.equal({
serviceName,
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
});
expect(stdoutData).to.include('stringOutputName');
expect(stdoutData).to.include('stringOutputValue');
expect(stdoutData).to.include('objectOutputName');
Expand Down Expand Up @@ -325,12 +275,7 @@ describe('outputCommand', function () {
}
});
it('Should support `--org` and `--app` CLI params', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: [
'output',
Expand All @@ -344,14 +289,6 @@ describe('outputCommand', function () {
],
modulesCacheStub,
});
expect(getStateVariableStub.args[0][0]).to.deep.equal({
variableName: 'stringOutputName',
stageName: 'dev',
appName: 'some-app',
orgName: 'some-org',
serviceName,
regionName: 'us-east-1',
});
expect(stdoutData).to.include('output-value');
});
it('Should support `--service` CLI params', async () => {
Expand All @@ -360,80 +297,33 @@ describe('outputCommand', function () {
cliArgs: ['output', 'get', '--name', 'stringOutputName', '--service', 'other-service'],
modulesCacheStub,
});
expect(getStateVariableStub.args[0][0]).to.deep.equal({
variableName: 'stringOutputName',
stageName: 'dev',
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName: 'other-service',
regionName: 'us-east-1',
});
expect(stdoutData).to.include('output-value');
});

it('Should support `--stage` CLI param', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'get', '--name', 'stringOutputName', '--stage', 'foo'],
modulesCacheStub,
});
expect(getStateVariableStub.args[0][0]).to.deep.equal({
variableName: 'stringOutputName',
stageName: 'foo',
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName,
regionName: 'us-east-1',
});
expect(stdoutData).to.include('output-value');
});

it('Should support `--region` CLI param', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'get', '--name', 'stringOutputName', '--region', 'us-east-2'],
modulesCacheStub,
});
expect(getStateVariableStub.args[0][0]).to.deep.equal({
variableName: 'stringOutputName',
stageName: 'dev',
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName,
regionName: 'us-east-2',
});
expect(stdoutData).to.include('output-value');
});

it('Should read configuration from config file', async () => {
const {
stdoutData,
fixtureData: {
serviceConfig: { service: serviceName },
},
} = await runServerless({
const { stdoutData } = await runServerless({
fixture: 'aws-monitored-service',
cliArgs: ['output', 'get', '--name', 'stringOutputName'],
modulesCacheStub,
});
expect(getStateVariableStub.args[0][0]).to.deep.equal({
variableName: 'stringOutputName',
stageName: 'dev',
appName: 'some-aws-service-app',
orgName: 'testinteractivecli',
serviceName,
regionName: 'us-east-1',
});
expect(stdoutData).to.include('output-value');
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/paramCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const modulesCacheStub = {
ServerlessSDK: class ServerlessSDK {
constructor() {
this.deploymentProfiles = {
get: () => ({
get: async () => ({
secretValues: [
{ secretName: 'first-param-name', secretProperties: { value: 'first-param-value' } },
{
Expand Down

0 comments on commit a0b0b53

Please sign in to comment.