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

Add support to flash a product device with firmware #97

Merged
merged 1 commit into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 4 additions & 3 deletions src/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,21 @@ class Particle {
* Compile and flash application firmware to a device. Pass a pre-compiled binary to flash it directly to the device.
* @param {Object} options Options for this API call
* @param {String} options.deviceId Device ID or Name
* @param {String} options.product Flash device in this product ID or slug
* @param {Object} options.files Object containing files to be compiled and flashed. Keys should be the filenames, including relative path, and the values should be a path or Buffer of the file contents in Node, or a File or Blob in the browser.
* @param {String} [options.targetVersion=latest] System firmware version to compile against
* @param {String} options.auth String
* @return {Promise}
*/
flashDevice({ deviceId, files, targetVersion, auth, context }) {
flashDevice({ deviceId, product, files, targetVersion, auth, context }) {
const uri = this.deviceUri({ deviceId, product });
const form = {};
if (targetVersion) {
form.build_target_version = targetVersion;
} else {
form.latest = 'true';
}
return this.request({ uri: `/v1/devices/${deviceId}`,
files, auth, form, context, method: 'put' });
return this.request({ uri, files, auth, form, context, method: 'put' });
}

/**
Expand Down
29 changes: 21 additions & 8 deletions test/Particle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,28 @@ describe('ParticleAPI', () => {
});
});
describe('.flashDevice', () => {
it('generates request', () => {
return api.flashDevice(props).then(Common.expectDeviceUrlAndToken);
describe('user scope', () => {
it('generates request', () => {
return api.flashDevice(props).then(Common.expectDeviceUrlAndToken);
});
it('sends proper data', () => {
return api.flashDevice(props).then(({ files, form }) => {
form.should.be.instanceOf(Object);
files.should.be.instanceOf(Object);
files.should.have.property('app.ino').and.be.ok;
form.build_target_version.should.equal(props.targetVersion);
});
});
});
it('sends proper data', () => {
return api.flashDevice(props).then(({ files, form }) => {
form.should.be.instanceOf(Object);
files.should.be.instanceOf(Object);
files.should.have.property('app.ino').and.be.ok;
form.build_target_version.should.equal(props.targetVersion);
describe('product scope', () => {
it('generates request', () => {
return api.flashDevice(propsWithProduct).then((results) => {
results.should.match({
method: 'put',
uri: `/v1/products/${product}/devices/${props.deviceId}`,
auth: props.auth
});
});
});
});
});
Expand Down