Skip to content

Commit

Permalink
Improved telemetry & testing setup (#15)
Browse files Browse the repository at this point in the history
* Improved telemetry & testing setup

* Tests added for all commands

* Fixing existing tests

* Adding additional tests

* Starting to add tests for numbers view

* Adding unit tests

* Fixing survey prompt test
  • Loading branch information
michaeljolley committed Mar 31, 2021
1 parent 499d17f commit f35d1a2
Show file tree
Hide file tree
Showing 38 changed files with 918 additions and 261 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [1.0.2] - 2021-03-31

### Updated

- Added additional unit tests
- Improved gathering of telemetry

## [1.0.0] - 2021-03-13

### Added
Expand Down Expand Up @@ -57,7 +64,8 @@ from using them if they weren't authenticated
- Quick access to Vonage API dashboard
- Initial README, CONTRIBUTING, etc.

[unreleased]: https://github.com/vonage/vscode/compare/1.0.0...HEAD
[unreleased]: https://github.com/vonage/vscode/compare/1.0.2...HEAD
[1.0.2]: https://github.com/vonage/vscode/compare/1.0.0...1.0.2
[1.0.0]: https://github.com/vonage/vscode/compare/0.0.10...1.0.0
[0.0.10]: https://github.com/vonage/vscode/compare/0.0.8...0.0.10
[0.0.8]: https://github.com/vonage/vscode/compare/edc07b4...0.0.8
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode",
"displayName": "Vonage",
"version": "1.0.1",
"version": "1.0.2",
"description": "A Visual Studio Code extension for accessing the Vonage communication APIs.",
"main": "./dist/extension",
"repository": {
Expand Down Expand Up @@ -494,7 +494,7 @@
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"webpack": "webpack --mode production",
"test": "node ./out/test/runTest.js"
"test": "node ./out/tests/runTest.js"
},
"dependencies": {
"@vonage/server-sdk": "^2.10.7",
Expand Down Expand Up @@ -526,7 +526,6 @@
"glob": "^7.1.4",
"mocha": "^8.2.1",
"sinon": "^9.2.1",
"source-map-support": "^0.5.12",
"ts-loader": "^8.0.14",
"typescript": "^4.2.2",
"vscode-codicons": "0.0.14",
Expand All @@ -535,4 +534,4 @@
"webpack": "^5.19.0",
"webpack-cli": "^4.4.0"
}
}
}
6 changes: 4 additions & 2 deletions src/commands/accountCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export class AccountCommands {
}

refresh = async (): Promise<void> => {
this.telemetry.sendEvent('Account', 'account.refresh');
this.accountViewDataProvider.refresh();
}

toggleBalanceView = (): void => {
this.accountViewDataProvider.toggleBalanceView();
toggleBalanceView = async (): Promise<void> => {
this.telemetry.sendEvent('Account', 'account.toggleBalance');
await this.accountViewDataProvider.toggleBalanceView();
}
}
32 changes: 16 additions & 16 deletions src/commands/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ export class ApplicationCommands {

/** Application commands */
refreshAppsList = () => {
this.telemetry.sendEvent('app.refreshAppsList');
this.telemetry.sendEvent('Applications', 'app.refreshAppsList');
this.vonageApplicationViewDataProvider.refresh();
};

addApp = () => {
this.telemetry.sendEvent('app.addApp');
this.telemetry.sendEvent('Applications', 'app.addApp');
this.vonageApplicationViewDataProvider.createApplication();
}

updateApp = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.updateApp');
this.telemetry.sendEvent('Applications', 'app.updateApp');
if (node) {
this.vonageApplicationViewDataProvider.updateApplication(node);
}
}

deleteApp = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.deleteApp');
this.telemetry.sendEvent('Applications', 'app.deleteApp');
if (node) {
this.vonageApplicationViewDataProvider.deleteApplication(node);
}
}

linkApp = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.link');
this.telemetry.sendEvent('Applications', 'app.link');
if (node) {
this.vonageApplicationViewDataProvider.linkApplication(node);
}
Expand All @@ -67,21 +67,21 @@ export class ApplicationCommands {
/** Voice commands */

voiceAdd = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.voice.add');
this.telemetry.sendEvent('Applications', 'app.voice.add');
if (node) {
this.vonageApplicationViewDataProvider.addVoice(node);
}
}

voiceUpdate = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.voice.update');
this.telemetry.sendEvent('Applications', 'app.voice.update');
if (node) {
this.vonageApplicationViewDataProvider.updateVoice(node);
}
}

voiceDelete = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.voice.delete');
this.telemetry.sendEvent('Applications', 'app.voice.delete');
if (node) {
this.vonageApplicationViewDataProvider.deleteVoice(node);
}
Expand All @@ -90,21 +90,21 @@ export class ApplicationCommands {
/** RTC commands */

rtcAdd = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.rtc.add');
this.telemetry.sendEvent('Applications', 'app.rtc.add');
if (node) {
this.vonageApplicationViewDataProvider.addRTC(node);
}
}

rtcUpdate = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.rtc.update');
this.telemetry.sendEvent('Applications', 'app.rtc.update');
if (node) {
this.vonageApplicationViewDataProvider.updateRTC(node);
}
}

rtcDelete = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.rtc.delete');
this.telemetry.sendEvent('Applications', 'app.rtc.delete');
if (node) {
this.vonageApplicationViewDataProvider.deleteRTC(node);
}
Expand All @@ -113,21 +113,21 @@ export class ApplicationCommands {
/** Messages commands */

messagesAdd = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.messages.add');
this.telemetry.sendEvent('Applications', 'app.messages.add');
if (node) {
this.vonageApplicationViewDataProvider.addMessages(node);
}
}

messagesUpdate = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.messages.update');
this.telemetry.sendEvent('Applications', 'app.messages.update');
if (node) {
this.vonageApplicationViewDataProvider.updateMessages(node);
}
}

messagesDelete = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.messages.delete');
this.telemetry.sendEvent('Applications', 'app.messages.delete');
if (node) {
this.vonageApplicationViewDataProvider.deleteMessages(node);
}
Expand All @@ -136,14 +136,14 @@ export class ApplicationCommands {
/** VBC commands */

vbcAdd = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.vbc.add');
this.telemetry.sendEvent('Applications', 'app.vbc.add');
if (node) {
this.vonageApplicationViewDataProvider.addVBC(node);
}
}

vbcDelete = (node?: ApplicationTreeItem) => {
this.telemetry.sendEvent('app.vbc.delete');
this.telemetry.sendEvent('Applications', 'app.vbc.delete');
if (node) {
this.vonageApplicationViewDataProvider.deleteVBC(node);
}
Expand Down
21 changes: 12 additions & 9 deletions src/commands/authCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ export class AuthCommands {
* in order to use extension.
*/
login = async (): Promise<void> => {
this.telemetry.sendEvent('login');
this.telemetry.sendEvent('Auth', 'login');

const state = await LoginFlow.collectInputs();

await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: `Configuring extension"...`
}, async () => {
await Auth.login(state.api_key, state.api_secret);
});

if (state.api_key?.length > 0 && state.api_secret?.length > 0) {
await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: `Configuring extension"...`
}, async () => {
await Auth.login(state.api_key, state.api_secret);
});
} else {
vscode.window.showErrorMessage('Your Vonage API key & secret are required to use the Vonage for VS Code extension.');
}
}

logout = async (): Promise<void> => {
this.telemetry.sendEvent('logout');
this.telemetry.sendEvent('Auth', 'logout');
await Auth.logout();
}
}
9 changes: 5 additions & 4 deletions src/commands/helpCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class HelpCommands {
}

refresh = async () => {
this.telemetry.sendEvent('Help', 'help.refresh');
this.vonageHelpViewDataProvider.refresh();
}

Expand All @@ -27,7 +28,7 @@ export class HelpCommands {
* Ideally will open documentation for the extension.
*/
openDocs = () => {
this.telemetry.sendEvent('help.openDocs');
this.telemetry.sendEvent('Help', 'help.openDocs');
vscode.env.openExternal(vscode.Uri.parse('https://developer.nexmo.com'));
};

Expand All @@ -36,7 +37,7 @@ export class HelpCommands {
* to provide feedback on the extension.
*/
openReportIssue = () => {
this.telemetry.sendEvent('help.openReportIssue');
this.telemetry.sendEvent('Help', 'help.openReportIssue');
const { name, publisher } = getExtensionInfo();

vscode.commands.executeCommand('vscode.openIssueReporter', {
Expand All @@ -49,7 +50,7 @@ export class HelpCommands {
* users to provide feedback on the extension.
*/
openSurvey = () => {
this.telemetry.sendEvent('help.openSurvey');
this.telemetry.sendEvent('Help', 'help.openSurvey');
const extensionInfo = getExtensionInfo();

const query = querystring.stringify({
Expand All @@ -68,7 +69,7 @@ export class HelpCommands {
* the user can learn more.
*/
openTelemetryInfo = () => {
this.telemetry.sendEvent('help.openTelemetryInfo');
this.telemetry.sendEvent('Help', 'help.openTelemetryInfo');
vscode.env.openExternal(
vscode.Uri.parse('https://code.visualstudio.com/docs/getstarted/telemetry'),
);
Expand Down
12 changes: 6 additions & 6 deletions src/commands/numbersCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ export class NumbersCommands {

/** Number commands */
refreshNumbersList = () => {
this.telemetry.sendEvent('number.refreshList');
this.telemetry.sendEvent('Numbers', 'number.refreshList');
this.vonageNumbersViewDataProvider.refresh();
};

buyNumber = () => {
this.telemetry.sendEvent('number.buy');
this.telemetry.sendEvent('Numbers', 'number.buy');
this.vonageNumbersViewDataProvider.buyNumber();
}

cancelNumber = (node?: NumberTreeItem) => {
this.telemetry.sendEvent('number.cancel');
this.telemetry.sendEvent('Numbers', 'number.cancel');
if (node) {
this.vonageNumbersViewDataProvider.cancelNumber(node);
}
}

assignNumber = (node?: NumberTreeItem) => {
this.telemetry.sendEvent('number.assign');
this.telemetry.sendEvent('Numbers', 'number.assign');
if (node) {
this.vonageNumbersViewDataProvider.assignNumber(node);
}
}

unassignNumber = (node?: NumberTreeItem) => {
this.telemetry.sendEvent('number.unassign');
this.telemetry.sendEvent('Numbers', 'number.unassign');
if (node) {
this.vonageNumbersViewDataProvider.unassignNumber(node);
}
}

copyNumber = (node?: NumberTreeItem) => {
this.telemetry.sendEvent('number.copy');
this.telemetry.sendEvent('Numbers', 'number.copy');
if (node) {
this.vonageNumbersViewDataProvider.copyNumber(node);
}
Expand Down
4 changes: 1 addition & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from './commands';
import { Auth } from './auth';
import { Credentials } from './models';
import { StorageKeys } from './enums';

let activeExtension: Extension;
let _context: vscode.ExtensionContext;
Expand Down Expand Up @@ -53,7 +52,7 @@ export class Extension {
* and Vonage specific telemetry settings are allowed.
*/
const telemetry = getTelemetry();
telemetry.sendEvent('activate');
telemetry.sendEvent('Activation', 'activate');


/**
Expand Down Expand Up @@ -155,7 +154,6 @@ export async function deactivate() {
*/
function getTelemetry() {
if (process.env.EXTENSION_MODE === 'development' || vscode.env.sessionId === 'someValue.sessionId') {
console.log('Extension is running in development mode. Using local telemetry instance');
return new LocalTelemetry();
} else {
return GoogleAnalyticsTelemetry.getInstance();
Expand Down
5 changes: 1 addition & 4 deletions src/prompts/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { StorageKeys } from '../enums';
* form of a survey on the learn.vonage.com site
*/
export class SurveyPrompt {
private storage: vscode.Memento;

constructor(state: vscode.Memento) {
this.storage = state;
}
constructor(private storage: vscode.Memento) {}

/**
* Prompt user concerning the survey
Expand Down
Loading

0 comments on commit f35d1a2

Please sign in to comment.