Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MilapNaik committed Mar 23, 2024
1 parent e11ae26 commit b298acb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
39 changes: 14 additions & 25 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,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 @@ -1255,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 @@ -1353,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 @@ -2051,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 @@ -2084,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 @@ -2105,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 @@ -2129,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 @@ -2153,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 @@ -2177,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 @@ -2201,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 @@ -2225,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 @@ -2248,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
2 changes: 1 addition & 1 deletion src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class RokuDeploy {

//prevent devId mismatch (if devId is specified)
if (options.devId) {
const deviceDevId = await this.getDevId();
const deviceDevId = await this.getDevId(options);
if (options.devId !== deviceDevId) {
throw new Error(`Package signing cancelled: provided devId '${options.devId}' does not match on-device devId '${deviceDevId}'`);
}
Expand Down

0 comments on commit b298acb

Please sign in to comment.