Skip to content

Commit

Permalink
Delete convertToSquashfs, move deployAndSignPackage tests to cli, mov…
Browse files Browse the repository at this point in the history
…e retrieveSignedPackage tests to under createSignedPackage
  • Loading branch information
MilapNaik committed Mar 19, 2024
1 parent 906856e commit d065bd5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 20 deletions.
80 changes: 80 additions & 0 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,31 @@ describe('index', () => {
});

describe('createSignedPackage', () => {
let onHandler: any;
beforeEach(() => {
fsExtra.outputFileSync(`${stagingDir}/manifest`, ``);
sinon.stub(fsExtra, 'ensureDir').callsFake(((pth: string, callback: (err: Error) => void) => {
//do nothing, assume the dir gets created
}) as any);

//intercept the http request
sinon.stub(request, 'get').callsFake(() => {
let req: any = {
on: (event, callback) => {
process.nextTick(() => {
onHandler(event, callback);
});
return req;
},
pipe: async () => {
//if a write stream gets created, write some stuff and close it
const writeStream = await writeStreamPromise;
writeStream.write('test');
writeStream.close();
}
};
return req;
});
});

it('should return our error if signingPassword is not supplied', async () => {
Expand Down Expand Up @@ -1395,6 +1418,63 @@ describe('index', () => {
`Package signing cancelled: provided devId '123' does not match on-device devId '789'`
);
});

it('returns a pkg file path on success', async () => {
//the write stream should return null, which causes a specific branch to be executed
createWriteStreamStub.callsFake(() => {
return null;
});

// let onHandler: any;
onHandler = (event, callback) => {
if (event === 'response') {
callback({
statusCode: 200
});
}
};

let body = `var pkgDiv = document.createElement('div');
pkgDiv.innerHTML = '<label>Currently Packaged Application:</label><div><font face="Courier"><a href="pkgs//P6953175d5df120c0069c53de12515b9a.pkg">P6953175d5df120c0069c53de12515b9a.pkg</a> <br> package file (7360 bytes)</font></div>';
node.appendChild(pkgDiv);`;
mockDoPostRequest(body);

let error: Error;
try {
await rokuDeploy.createSignedPackage({
host: '1.2.3.4',
password: 'password',
signingPassword: options.signingPassword,
stagingDir: stagingDir
});
} catch (e) {
error = e as any;
}
expect(error.message.startsWith('Unable to create write stream for')).to.be.true;
});

it('throws when error in request is encountered', async () => {
onHandler = (event, callback) => {
if (event === 'error') {
callback(new Error('Some error'));
}
};

let body = `var pkgDiv = document.createElement('div');
pkgDiv.innerHTML = '<label>Currently Packaged Application:</label><div><font face="Courier"><a href="pkgs//P6953175d5df120c0069c53de12515b9a.pkg">P6953175d5df120c0069c53de12515b9a.pkg</a> <br> package file (7360 bytes)</font></div>';
node.appendChild(pkgDiv);`;
mockDoPostRequest(body);

await expectThrowsAsync(
rokuDeploy.createSignedPackage({
host: '1.2.3.4',
password: 'aaaa',
signingPassword: options.signingPassword,
stagingDir: stagingDir
}),
'Some error'
);
});
});

describe('prepublishToStaging', () => {
Expand Down
5 changes: 0 additions & 5 deletions src/RokuDeployOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ export interface RokuDeployOptions {
*/
devId?: string;

/**
* If true we convert to squashfs before creating the pkg file
*/
convertToSquashfs?: boolean;

/**
* If true, the publish will fail on compile error
*/
Expand Down
58 changes: 43 additions & 15 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,38 @@ describe('cli', () => {

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

describe('ExecCommand', () => {
beforeEach(() => {
fsExtra.emptyDirSync(tempDir);
//most tests depend on a manifest file existing, so write an empty one
fsExtra.outputFileSync(`${rootDir}/manifest`, '');
sinon.restore();
});
afterEach(() => {
fsExtra.removeSync(tempDir);
sinon.restore();
});
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);
});
}

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

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

expect(mock.getCall(2).args[0].url).to.equal('http://1.2.3.4:80/plugin_install');
expectPathExists(`${outDir}/roku-deploy.zip`);
Expand All @@ -293,22 +313,22 @@ describe('cli', () => {
)
);
const mock = mockDoPostRequest();
const args = {
const options = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir
};
await new ExecCommand('stage|zip|close|sideload', args).run();
await new ExecCommand('stage|zip|close|sideload', options).run();
expect(mock.getCall(0).args[0].url).to.equal('http://1.2.3.4:8060/keypress/home');
expectPathExists(`${outDir}/roku-deploy.zip`);
});

it('should delete installed channel if requested', async () => {
const spy = sinon.spy(rokuDeploy, 'deleteDevChannel');
mockDoPostRequest();
const args = {
const options = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
Expand All @@ -317,15 +337,15 @@ describe('cli', () => {
deleteDevChannel: true
};

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

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

const args = {
const options = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
Expand All @@ -334,15 +354,23 @@ describe('cli', () => {
deleteDevChannel: false
};

await new ExecCommand('stage|zip|close|sideload', args).run();
await new ExecCommand('stage|zip|close|sideload', options).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);
});
}
it('converts to squashfs if we request it to', async () => {
let stub = sinon.stub(rokuDeploy, 'convertToSquashfs').returns(Promise.resolve<any>(null));
mockDoPostRequest();
const options = {
host: '1.2.3.4',
password: 'abcd',
rootDir: rootDir,
stagingDir: stagingDir,
outDir: outDir,
deleteDevChannel: false
};

await new ExecCommand('close|stage|zip|close|sideload|squash', options).run();
expect(stub.getCalls()).to.be.lengthOf(1);
});
});

0 comments on commit d065bd5

Please sign in to comment.