Skip to content

Commit

Permalink
Move deploy tests to test exec command
Browse files Browse the repository at this point in the history
  • Loading branch information
MilapNaik committed Mar 18, 2024
1 parent b51c3fc commit 0da4110
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
77 changes: 77 additions & 0 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DeleteDevChannelCommand } from './commands/DeleteDevChannelCommand';
import { CaptureScreenshotCommand } from './commands/CaptureScreenshotCommand';
import { GetDeviceInfoCommand } from './commands/GetDeviceInfoCommand';
import { GetDevIdCommand } from './commands/GetDevIdCommand';
import { ExecCommand } from './commands/ExecCommand';

const sinon = createSandbox();

Expand Down Expand Up @@ -268,4 +269,80 @@ describe('cli', () => {

expectPathExists(`${outDir}/roku-deploy.zip`);
});

it('does the whole migration', async () => {
const mock = mockDoPostRequest();

const args = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir
};
await new ExecCommand('stage|zip|close|sideload', args).run();

expect(mock.getCall(2).args[0].url).to.equal('http://1.2.3.4:80/plugin_install');
expectPathExists(`${outDir}/roku-deploy.zip`);
});

it('continues with deploy if deleteDevChannel fails', async () => {
sinon.stub(rokuDeploy, 'deleteDevChannel').returns(
Promise.reject(
new Error('failed')
)
);
const mock = mockDoPostRequest();
const args = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir
};
await new ExecCommand('stage|zip|close|sideload', args).run();
expect(mock.getCall(0).args[0].url).to.equal('http://1.2.3.4:8060/keypress/home');
expectPathExists(`${outDir}/roku-deploy.zip`);
});

it.only('should delete installed channel if requested', async () => {
const spy = sinon.spy(rokuDeploy, 'deleteDevChannel');
mockDoPostRequest();
const args = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir,
deleteDevChannel: true
};

await new ExecCommand('stage|zip|close|sideload', args).run();
expect(spy.called).to.equal(true);
});

it.only('should not delete installed channel if not requested', async () => {
const spy = sinon.spy(rokuDeploy, 'deleteDevChannel');
mockDoPostRequest();

const args = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir,
deleteDevChannel: false
};

await new ExecCommand('stage|zip|close|sideload', args).run();
expect(spy.notCalled).to.equal(true);
});

function mockDoPostRequest(body = '', statusCode = 200) {
return sinon.stub(rokuDeploy as any, 'doPostRequest').callsFake((params) => {
let results = { response: { statusCode: statusCode }, body: body };
rokuDeploy['checkRequest'](results);
return Promise.resolve(results);
});
}
});
5 changes: 2 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ZipCommand } from './commands/ZipCommand';
import { KeyPressCommand } from './commands/KeyPressCommand';
import { KeyUpCommand } from './commands/KeyUpCommand';
import { KeyDownCommand } from './commands/KeyDownCommand';
import type { RokuDeploy } from './RokuDeploy';

void yargs

Expand Down Expand Up @@ -49,7 +48,7 @@ void yargs
.option('deleteDevChannel', { type: 'boolean', description: 'Should the dev channel be deleted', demandOption: false });
}, (args: any) => {
return new ExecCommand(
'stage|zip|delete|close|sideload',
'stage|zip|close|sideload',
args
).run();
})
Expand All @@ -74,7 +73,7 @@ void yargs
.option('stagingDir', { type: 'string', description: 'The selected staging folder', demandOption: false });
}, (args: any) => {
return new ExecCommand(
'close|rekey|stage|zip|delete|close|sideload|squash|sign',
'close|rekey|stage|zip|close|sideload|squash|sign',
args
).run();
})
Expand Down
6 changes: 5 additions & 1 deletion src/commands/ExecCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class ExecCommand {
}

if (this.actions.includes('delete')) {
await rokuDeploy.deleteDevChannel(this.options as DeleteDevChannelOptions);
try {
await rokuDeploy.deleteDevChannel(this.options as DeleteDevChannelOptions);
} catch (e) {
// note we don't report the error; as we don't actually care that we could not delete - it's just useless noise to log it.
}
}

if (this.actions.includes('close')) {
Expand Down

0 comments on commit 0da4110

Please sign in to comment.