Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exceptions on missing options #156

Merged
merged 83 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
c6d2536
Make change to assume dest folder. Delete 2 old tests that looked for…
MilapNaik Jan 2, 2024
2ba8eca
Sort files
MilapNaik Jan 2, 2024
cc92e04
Update src/RokuDeploy.ts
MilapNaik Jan 16, 2024
9bbd579
Removed redundant entry.dest is null situation
MilapNaik Jan 17, 2024
460cbf6
Added a few commands, not all are working correctly
MilapNaik Jan 19, 2024
de269ed
Merge branch 'v4' into add-cli-commands
MilapNaik Jan 19, 2024
7b9ee29
Merge branch 'fix-src-dest-handling' into add-cli-commands
MilapNaik Jan 19, 2024
6db962a
Move commands to their own file
MilapNaik Jan 31, 2024
20eb21f
More command files
MilapNaik Feb 1, 2024
4e4b66a
Change commands to help with tests
MilapNaik Feb 1, 2024
2b809e6
Add testing suite for all cli (2 tests are not working)
MilapNaik Feb 2, 2024
13f2ca4
Updated cli file after adding in commands and tests
MilapNaik Feb 2, 2024
2d13441
Fixed a few test cases
MilapNaik Feb 2, 2024
09a275f
Change name and input of table helper
MilapNaik Feb 2, 2024
e34ac97
Totally broken code, but have the right names
TwitchBronBron Feb 2, 2024
52b1bc0
Changed name of toTable
MilapNaik Feb 6, 2024
f3a0c56
Make test for objectToTable
MilapNaik Feb 6, 2024
b5f41ca
add yargs to pacjage.json
MilapNaik Feb 6, 2024
4b95943
add package-lock.json
MilapNaik Feb 6, 2024
b6c6223
add new line at eof
MilapNaik Feb 6, 2024
f15f295
Add test for coverage, also remove an unncessary '?'
MilapNaik Feb 6, 2024
08a587e
Merge branch 'add-cli-commands' into rename
MilapNaik Feb 6, 2024
6941e86
tweaks
TwitchBronBron Feb 6, 2024
ea49342
tweaks
TwitchBronBron Feb 6, 2024
616ff23
get from json stuff
TwitchBronBron Feb 6, 2024
e2f3f80
Merge branch 'v4' into rename
MilapNaik Feb 6, 2024
190a2f1
Merge branch 'v4' into rename
MilapNaik Feb 6, 2024
cacf433
Correct imports
MilapNaik Feb 7, 2024
cbd6417
Last of the fsExtra changes
MilapNaik Feb 7, 2024
ebab568
Create a load from json util, clean up cli.ts file with fleshing out …
MilapNaik Feb 21, 2024
46fe129
Adding cli tests
MilapNaik Feb 22, 2024
36502e1
Delete deployAndSignPackage tests, a deleted function in rokudeploy
MilapNaik Feb 22, 2024
c058dd6
Add defaultsFromJson tests
MilapNaik Feb 22, 2024
5859f91
Move some tests to utils test file, re add other functions that might…
MilapNaik Feb 29, 2024
8ae9ace
Change signExistingPackage to CreateSignedPackage
MilapNaik Feb 29, 2024
cc0f4b8
Delete retrieveSignedPackage
MilapNaik Feb 29, 2024
cbfcaed
Move getFilePaths
MilapNaik Feb 29, 2024
c74ef8e
Random changes I forgot to put in the other pushes
MilapNaik Feb 29, 2024
583d960
Change to different notation since getOutputZipFilePath and getOutput…
MilapNaik Feb 29, 2024
6d874a6
Change notation for normalizeDeviceInfoFieldValue since it was made p…
MilapNaik Feb 29, 2024
f5ba839
Change notation for parsedManifestFromString and ParseManifest since …
MilapNaik Feb 29, 2024
2858dd6
Change deleteInstalledChannel to deleteDevChannel, other small changes
MilapNaik Feb 29, 2024
3186e88
Add stagingDir, fix zip/deleteDevChannel/captureScreenshot function c…
MilapNaik Mar 4, 2024
55ce426
Fix commands
MilapNaik Mar 4, 2024
8d4e537
change defaults from json function, fix some tests
MilapNaik Mar 5, 2024
1d75b10
fix index, fix makezip, getfilepaths, sideload
MilapNaik Mar 5, 2024
48d07d9
Add options from json ability to each command to each command
MilapNaik Mar 5, 2024
053a3f4
remove bsconfig, fix cli file with key press commands, fix key press …
MilapNaik Mar 5, 2024
fa07787
fix getoptionsfromjson
MilapNaik Mar 5, 2024
4344666
delete unnecessary commands, fix some tests
MilapNaik Mar 6, 2024
7d9e56e
change to captureScreenshot
MilapNaik Mar 6, 2024
ebb3d22
Fix a bunch of tests
MilapNaik Mar 8, 2024
243bbdd
Fix up the last few tests and cli commands
MilapNaik Mar 11, 2024
b485ea4
Changing coverage check to false
MilapNaik Mar 11, 2024
7ad7ff0
Fix failing tests on windows
TwitchBronBron Mar 11, 2024
fad56b9
Delete comment
MilapNaik Mar 11, 2024
b51c3fc
Change publish to sideload everywhere else
MilapNaik Mar 15, 2024
0da4110
Move deploy tests to test exec command
MilapNaik Mar 18, 2024
2ad743a
Throw new error for wrong device id, and add test to test for it
MilapNaik Mar 18, 2024
e6d8752
Delete creating variable options since it was unused
MilapNaik Mar 18, 2024
200e537
Add function description
MilapNaik Mar 18, 2024
a669ee3
Inline exec command options
MilapNaik Mar 18, 2024
906856e
Remove retainsStagingDir, zipCallBackInfo, incrementBuildNumber, and …
MilapNaik Mar 19, 2024
d065bd5
Delete convertToSquashfs, move deployAndSignPackage tests to cli, mov…
MilapNaik Mar 19, 2024
0f17569
Change prepublishToStaging to stage
MilapNaik Mar 20, 2024
94fa701
Change the way close channel works
MilapNaik Mar 20, 2024
f64ab5d
Update src/RokuDeploy.ts
MilapNaik Mar 20, 2024
4ffc8f7
Add outFile to Zip, delete zipPackage
MilapNaik Mar 20, 2024
94a4d43
StagingDir is defaulted anyway so this error will never occur
MilapNaik Mar 20, 2024
782ec22
Delete MissingRequiredOptionError
MilapNaik Mar 20, 2024
895c250
Add checkRequiredOptions function to test for required options
MilapNaik Mar 20, 2024
469a62a
Add checking for required options in sendKeyEvent function, start tes…
MilapNaik Mar 20, 2024
76b1f7d
Add check for if options are part of the defined interface that they …
MilapNaik Mar 23, 2024
9e44992
Add check for various required options and add tests for each one
MilapNaik Mar 23, 2024
3734501
Merge branch 'v4' into throw-exceptions-on-missing-params
MilapNaik Mar 23, 2024
db3d782
take out it.only in tests
MilapNaik Mar 23, 2024
e11ae26
Delete old MissingRequiredOptionError tests
MilapNaik Mar 23, 2024
b298acb
fix tests
MilapNaik Mar 23, 2024
d9397d5
Fix lint error
MilapNaik Mar 23, 2024
1c4b4f1
Upgrade node to 14.7.0
MilapNaik Mar 26, 2024
9eab0ec
Undo last commit wrong branch
MilapNaik Mar 26, 2024
1b1bca3
Get rid of individual options checks
MilapNaik Mar 26, 2024
20eaeb7
Fixed option type in tests function
MilapNaik Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,3 @@ export class ConvertError extends Error {
Object.setPrototypeOf(this, ConvertError.prototype);
}
}

export class MissingRequiredOptionError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, MissingRequiredOptionError.prototype);
}
}
154 changes: 80 additions & 74 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { cwd, expectPathExists, expectPathNotExists, expectThrowsAsync, outDir,
import { createSandbox } from 'sinon';
import * as r from 'postman-request';
import type * as requestType from 'request';
import type { CaptureScreenshotOptions, ConvertToSquashfsOptions, CreateSignedPackageOptions, DeleteDevChannelOptions, GetDevIdOptions, GetDeviceInfoOptions, RekeyDeviceOptions, SendKeyEventOptions, SideloadOptions } from './RokuDeploy';
const request = r as typeof requestType;

const sinon = createSandbox();
Expand Down Expand Up @@ -646,11 +647,11 @@ describe('index', () => {

describe('generateBaseRequestOptions', () => {
it('uses default port', () => {
expect(rokuDeploy['generateBaseRequestOptions']('a_b_c', { host: '1.2.3.4', password: options.password }).url).to.equal('http://1.2.3.4:80/a_b_c');
expect(rokuDeploy['generateBaseRequestOptions']('a_b_c', { host: '1.2.3.4', password: 'password' }).url).to.equal('http://1.2.3.4:80/a_b_c');
});

it('uses overridden port', () => {
expect(rokuDeploy['generateBaseRequestOptions']('a_b_c', { host: '1.2.3.4', packagePort: 999, password: options.password }).url).to.equal('http://1.2.3.4:999/a_b_c');
expect(rokuDeploy['generateBaseRequestOptions']('a_b_c', { host: '1.2.3.4', packagePort: 999, password: 'password' }).url).to.equal('http://1.2.3.4:999/a_b_c');
});
});

Expand Down Expand Up @@ -1058,21 +1059,6 @@ describe('index', () => {
});
});

it('should return MissingRequiredOptionError if host was not provided', async () => {
mockDoPostRequest();
try {
options.host = undefined;
await rokuDeploy.convertToSquashfs({
host: options.host,
password: 'password'
});
} catch (e) {
expect(e).to.be.instanceof(errors.MissingRequiredOptionError);
return;
}
assert.fail('Should not have succeeded');
});

it('should return ConvertError if converting failed', async () => {
mockDoPostRequest();
try {
Expand Down Expand Up @@ -1181,40 +1167,6 @@ describe('index', () => {
});
});

it('should throw error if missing rekeySignedPackage option', async () => {
try {
await rokuDeploy.rekeyDevice({
host: '1.2.3.4',
password: 'password',
rekeySignedPackage: null,
signingPassword: options.signingPassword,
rootDir: options.rootDir,
devId: options.devId
});
} catch (e) {
expect(e).to.be.instanceof(errors.MissingRequiredOptionError);
return;
}
assert.fail('Exception should have been thrown');
});

it('should throw error if missing signingPassword option', async () => {
try {
await rokuDeploy.rekeyDevice({
host: '1.2.3.4',
password: 'password',
rekeySignedPackage: options.rekeySignedPackage,
signingPassword: null,
rootDir: options.rootDir,
devId: options.devId
});
} catch (e) {
expect(e).to.be.instanceof(errors.MissingRequiredOptionError);
return;
}
assert.fail('Exception should have been thrown');
});

it('should throw error if response is not parsable', async () => {
try {
mockDoPostRequest();
Expand Down Expand Up @@ -1303,17 +1255,6 @@ describe('index', () => {
});
});

it('should return our error if signingPassword is not supplied', async () => {
await expectThrowsAsync(async () => {
await rokuDeploy.createSignedPackage({
host: '1.2.3.4',
password: 'password',
signingPassword: undefined,
stagingDir: stagingDir
});
}, 'Must supply signingPassword');
});

it('should return an error if there is a problem with the network request', async () => {
let error = new Error('Network Error');
try {
Expand Down Expand Up @@ -1401,7 +1342,7 @@ describe('index', () => {
);
});

it('should return our fallback error if neither error or package link was detected', async () => {
it('should return error if dev id does not match', async () => {
mockDoGetRequest(`
<device-info>
<keyed-developer-id>789</keyed-developer-id>
Expand Down Expand Up @@ -2099,19 +2040,19 @@ describe('index', () => {
`);

mockDoPostRequest(body);
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: options.password }));
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: 'password' }));
});

it('throws when there is no response body', async () => {
// missing body
mockDoPostRequest(null);
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: options.password }));
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: 'password' }));
});

it('throws when there is an empty response body', async () => {
// empty body
mockDoPostRequest();
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: options.password }));
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: 'password' }));
});

it('throws when there is an error downloading the image from device', async () => {
Expand All @@ -2132,7 +2073,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: options.password }));
await expectThrowsAsync(rokuDeploy.captureScreenshot({ host: options.host, password: 'password' }));
});

it('handles the device returning a png', async () => {
Expand All @@ -2153,7 +2094,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password' });
expect(result).not.to.be.undefined;
expect(path.extname(result)).to.equal('.png');
expect(fsExtra.existsSync(result));
Expand All @@ -2177,7 +2118,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password' });
expect(result).not.to.be.undefined;
expect(path.extname(result)).to.equal('.jpg');
expect(fsExtra.existsSync(result));
Expand All @@ -2201,7 +2142,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password, screenshotDir: `${tempDir}/myScreenShots` });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password', screenshotDir: `${tempDir}/myScreenShots` });
expect(result).not.to.be.undefined;
expect(util.standardizePath(`${tempDir}/myScreenShots`)).to.equal(path.dirname(result));
expect(fsExtra.existsSync(result));
Expand All @@ -2225,7 +2166,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password, screenshotDir: tempDir, screenshotFile: 'my' });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password', screenshotDir: tempDir, screenshotFile: 'my' });
expect(result).not.to.be.undefined;
expect(util.standardizePath(tempDir)).to.equal(path.dirname(result));
expect(fsExtra.existsSync(path.join(tempDir, 'my.png')));
Expand All @@ -2249,7 +2190,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password, screenshotDir: tempDir, screenshotFile: 'my.jpg' });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password', screenshotDir: tempDir, screenshotFile: 'my.jpg' });
expect(result).not.to.be.undefined;
expect(util.standardizePath(tempDir)).to.equal(path.dirname(result));
expect(fsExtra.existsSync(path.join(tempDir, 'my.jpg.png')));
Expand All @@ -2273,7 +2214,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password' });
expect(result).not.to.be.undefined;
expect(fsExtra.existsSync(result));
});
Expand All @@ -2296,7 +2237,7 @@ describe('index', () => {
};

mockDoPostRequest(body);
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: options.password, screenshotFile: 'myFile' });
let result = await rokuDeploy.captureScreenshot({ host: options.host, password: 'password', screenshotFile: 'myFile' });
expect(result).not.to.be.undefined;
expect(path.basename(result)).to.equal('myFile.jpg');
expect(fsExtra.existsSync(result));
Expand Down Expand Up @@ -3175,6 +3116,71 @@ describe('index', () => {
});
});

describe('checkRequiredOptions', () => {
async function testRequiredOptions(action: string, requiredOptions: Partial<RokuDeployOptions>, testedOption: string) {
const newOptions = { ...requiredOptions };
delete newOptions[testedOption];
await expectThrowsAsync(async () => {
await rokuDeploy[action](newOptions);
}, `Missing required option: ${testedOption}`);
}

it('throws error when sendKeyEvent is missing required options', async () => {
const requiredOptions: Partial<SendKeyEventOptions> = { host: '1.2.3.4', key: 'string' };
await testRequiredOptions('sendKeyEvent', requiredOptions, 'host');
await testRequiredOptions('sendKeyEvent', requiredOptions, 'key');
});

it('throws error when sideload is missing required options', async () => {
const requiredOptions: Partial<SideloadOptions> = { host: '1.2.3.4', password: 'abcd' };
await testRequiredOptions('sideload', requiredOptions, 'host');
await testRequiredOptions('sideload', requiredOptions, 'password');
});

it('throws error when convertToSquashfs is missing required options', async () => {
const requiredOptions: Partial<ConvertToSquashfsOptions> = { host: '1.2.3.4', password: 'abcd' };
await testRequiredOptions('convertToSquashfs', requiredOptions, 'host');
await testRequiredOptions('convertToSquashfs', requiredOptions, 'password');
});

it('throws error when rekeyDevice is missing required options', async () => {
const requiredOptions: Partial<RekeyDeviceOptions> = { host: '1.2.3.4', password: 'abcd', rekeySignedPackage: 'abcd', signingPassword: 'abcd' };
await testRequiredOptions('rekeyDevice', requiredOptions, 'host');
await testRequiredOptions('rekeyDevice', requiredOptions, 'password');
await testRequiredOptions('rekeyDevice', requiredOptions, 'rekeySignedPackage');
await testRequiredOptions('rekeyDevice', requiredOptions, 'signingPassword');
});

it('throws error when createSignedPackage is missing required options', async () => {
const requiredOptions: Partial<CreateSignedPackageOptions> = { host: '1.2.3.4', password: 'abcd', signingPassword: 'abcd' };
await testRequiredOptions('createSignedPackage', requiredOptions, 'host');
await testRequiredOptions('createSignedPackage', requiredOptions, 'password');
await testRequiredOptions('createSignedPackage', requiredOptions, 'signingPassword');
});

it('throws error when deleteDevChannel is missing required options', async () => {
const requiredOptions: Partial<DeleteDevChannelOptions> = { host: '1.2.3.4', password: 'abcd' };
await testRequiredOptions('deleteDevChannel', requiredOptions, 'host');
await testRequiredOptions('deleteDevChannel', requiredOptions, 'password');
});

it('throws error when captureScreenshot is missing required options', async () => {
const requiredOptions: Partial<CaptureScreenshotOptions> = { host: '1.2.3.4', password: 'abcd' };
await testRequiredOptions('captureScreenshot', requiredOptions, 'host');
await testRequiredOptions('captureScreenshot', requiredOptions, 'password');
});

it('throws error when getDeviceInfo is missing required options', async () => {
const requiredOptions: Partial<GetDeviceInfoOptions> = { host: '1.2.3.4' };
await testRequiredOptions('getDeviceInfo', requiredOptions, 'host');
});

it('throws error when getDevId is missing required options', async () => {
const requiredOptions: Partial<GetDevIdOptions> = { host: '1.2.3.4' };
await testRequiredOptions('getDevId', requiredOptions, 'host');
});
});

describe('downloadFile', () => {
it('waits for the write stream to finish writing before resolving', async () => {
let downloadFileIsResolved = false;
Expand Down
Loading