Skip to content
Snippets Groups Projects
Unverified Commit 832dc10c authored by Karishma Chadha's avatar Karishma Chadha Committed by GitHub
Browse files

Merge pull request #3852 from kchadha/cloud-rename-delete

Add rename and delete functionality for cloud variables
parents 9aa29d10 9fe4bc50
No related branches found
No related tags found
No related merge requests found
...@@ -113,10 +113,9 @@ class CloudProvider { ...@@ -113,10 +113,9 @@ class CloudProvider {
* @param {string} methodName The message method, indicating the action to perform. * @param {string} methodName The message method, indicating the action to perform.
* @param {string} dataName The name of the cloud variable this message pertains to * @param {string} dataName The name of the cloud variable this message pertains to
* @param {string | number} dataValue The value to set the cloud variable to * @param {string | number} dataValue The value to set the cloud variable to
* @param {number} dataIndex The index of the item to update (for cloud lists)
* @param {string} dataNewName The new name for the cloud variable (if renaming) * @param {string} dataNewName The new name for the cloud variable (if renaming)
*/ */
writeToServer (methodName, dataName, dataValue, dataIndex, dataNewName) { writeToServer (methodName, dataName, dataValue, dataNewName) {
const msg = {}; const msg = {};
msg.method = methodName; msg.method = methodName;
msg.user = this.username; msg.user = this.username;
...@@ -127,8 +126,7 @@ class CloudProvider { ...@@ -127,8 +126,7 @@ class CloudProvider {
if (dataNewName) msg.new_name = dataNewName; if (dataNewName) msg.new_name = dataNewName;
// Optional number params need different undefined check // Optional number params need different undefined check
if (typeof dataValue !== 'undefined') msg.value = dataValue; if (typeof dataValue !== 'undefined' && dataValue !== null) msg.value = dataValue;
if (typeof dataValue !== 'undefined') msg.index = dataIndex;
const dataToWrite = JSON.stringify(msg); const dataToWrite = JSON.stringify(msg);
this.sendCloudData(dataToWrite); this.sendCloudData(dataToWrite);
...@@ -163,6 +161,25 @@ class CloudProvider { ...@@ -163,6 +161,25 @@ class CloudProvider {
this.writeToServer('set', name, value); this.writeToServer('set', name, value);
} }
/**
* Provides an API for the VM's cloud IO device to rename
* a cloud variable on the server.
* @param {string} oldName The old name of the variable to rename
* @param {string} newName The new name for the cloud variable.
*/
renameVariable (oldName, newName) {
this.writeToServer('rename', oldName, null, newName);
}
/**
* Provides an API for the VM's cloud IO device to delete
* a cloud variable on the server.
* @param {string} name The name of the variable to delete
*/
deleteVariable (name) {
this.writeToServer('delete', name);
}
/** /**
* Closes the connection to the web socket and clears the cloud * Closes the connection to the web socket and clears the cloud
* provider of references related to the cloud data project. * provider of references related to the cloud data project.
......
...@@ -43,6 +43,14 @@ describe('CloudProvider', () => { ...@@ -43,6 +43,14 @@ describe('CloudProvider', () => {
cloudProvider.randomizeDuration = t => t; cloudProvider.randomizeDuration = t => t;
}); });
test('createVariable', () => {
cloudProvider.createVariable('hello', 1);
const obj = JSON.parse(cloudProvider.connection._sentMessages[0]);
expect(obj.method).toEqual('create');
expect(obj.name).toEqual('hello');
expect(obj.value).toEqual(1);
});
test('updateVariable', () => { test('updateVariable', () => {
cloudProvider.updateVariable('hello', 1); cloudProvider.updateVariable('hello', 1);
const obj = JSON.parse(cloudProvider.connection._sentMessages[0]); const obj = JSON.parse(cloudProvider.connection._sentMessages[0]);
...@@ -59,13 +67,21 @@ describe('CloudProvider', () => { ...@@ -59,13 +67,21 @@ describe('CloudProvider', () => {
expect(obj.value).toEqual(0); expect(obj.value).toEqual(0);
}); });
test('writeToServer with falsey index value', () => { test('renameVariable', () => {
cloudProvider.writeToServer('method', 'name', 5, 0); cloudProvider.renameVariable('oldName', 'newName');
const obj = JSON.parse(cloudProvider.connection._sentMessages[0]); const obj = JSON.parse(cloudProvider.connection._sentMessages[0]);
expect(obj.method).toEqual('method'); expect(obj.method).toEqual('rename');
expect(obj.name).toEqual('name'); expect(obj.name).toEqual('oldName');
expect(obj.value).toEqual(5); expect(typeof obj.value).toEqual('undefined');
expect(obj.index).toEqual(0); expect(obj.new_name).toEqual('newName');
});
test('deleteVariable', () => {
cloudProvider.deleteVariable('hello');
const obj = JSON.parse(cloudProvider.connection._sentMessages[0]);
expect(obj.method).toEqual('delete');
expect(obj.name).toEqual('hello');
expect(typeof obj.value).toEqual('undefined');
}); });
test('onMessage ack', () => { test('onMessage ack', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment