Skip to content

Commit

Permalink
Cleanup App Engine samples and re-work tests. (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored and Ace Nassri committed Apr 24, 2017
1 parent e9c0f92 commit 1a91f3d
Show file tree
Hide file tree
Showing 10 changed files with 6,033 additions and 213 deletions.
14 changes: 6 additions & 8 deletions cloud-language/snippets/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function analyzeSentimentOfText (text) {
document.detectSentiment()
.then((results) => {
const sentiment = results[1].documentSentiment;
console.log(`Document sentiment:`)
console.log(`Document sentiment:`);
console.log(` Score: ${sentiment.score}`);
console.log(` Magnitude: ${sentiment.magnitude}`);

Expand Down Expand Up @@ -76,7 +76,7 @@ function analyzeSentimentInFile (bucketName, fileName) {
document.detectSentiment()
.then((results) => {
const sentiment = results[1].documentSentiment;
console.log(`Document sentiment:`)
console.log(`Document sentiment:`);
console.log(` Score: ${sentiment.score}`);
console.log(` Magnitude: ${sentiment.magnitude}`);

Expand Down Expand Up @@ -263,7 +263,7 @@ function analyzeEntitySentimentOfText (text) {
.then((results) => {
const entities = results[0].entities;

console.log(`Entities and sentiments:`)
console.log(`Entities and sentiments:`);
entities.forEach((entity) => {
console.log(` Name: ${entity.name}`);
console.log(` Type: ${entity.type}`);
Expand All @@ -279,13 +279,11 @@ function analyzeEntitySentimentOfText (text) {

function analyzeEntitySentimentInFile (bucketName, fileName) {
// [START language_entity_sentiment_file]
// Imports the Google Cloud client libraries
// Imports the Google Cloud client library
const Language = require('@google-cloud/language').v1beta2();
const Storage = require('@google-cloud/storage');

// Instantiates the clients
const language = Language.languageServiceClient();
const storage = Storage();

// The name of the bucket where the file resides, e.g. "my-bucket"
// const bucketName = 'my-bucket';
Expand All @@ -306,7 +304,7 @@ function analyzeEntitySentimentInFile (bucketName, fileName) {
.then((results) => {
const entities = results[0].entities;

console.log(`Entities and sentiments:`)
console.log(`Entities and sentiments:`);
entities.forEach((entity) => {
console.log(` Name: ${entity.name}`);
console.log(` Type: ${entity.type}`);
Expand All @@ -320,7 +318,7 @@ function analyzeEntitySentimentInFile (bucketName, fileName) {
// [END language_entity_sentiment_file]
}

require(`yargs`)
require(`yargs`) // eslint-disable-line
.demand(1)
.command(
`sentiment-text <text>`,
Expand Down
25 changes: 21 additions & 4 deletions cloud-language/snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
"name": "nodejs-docs-samples-language",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"cloud": {
"requiresKeyFile": true,
"requiresProjectId": true
},
"engines": {
"node": ">=4.3.2"
},
"scripts": {
"test": "cd ..; npm run st -- --verbose language/system-test/*.test.js"
"lint": "samples lint \"*.js\" \"system-test/*.js\" \"slackbot/*.js\" \"slackbot/system-test/*.js\"",
"pretest": "npm run lint",
"system-test": "ava -T 20s --verbose system-test/*.test.js",
"test": "npm run system-test"
},
"dependencies": {
"@google-cloud/language": "0.10.3",
"@google-cloud/storage": "1.1.0",
"yargs": "7.1.0"
},
"engines": {
"node": ">=4.3.2"
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.3.1",
"ava": "0.19.1",
"proxyquire": "1.7.11",
"sinon": "2.1.0"
}
}
2 changes: 1 addition & 1 deletion cloud-language/snippets/quickstart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, Google, Inc.
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down
31 changes: 24 additions & 7 deletions cloud-language/snippets/slackbot/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"name": "kubernetes-slack-botkit-example",
"description": "A Slack Botkit bot, running on Kubernetes.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"license": "Apache-2.0",
"author": "Google Inc.",
"description": "A Slack Botkit bot, running on Kubernetes.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"cloud": {
"requiresKeyFile": true,
"requiresProjectId": true
},
"main": "demo_bot.js",
"engines": {
"node": ">=4.3.2"
},
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"system-test": "ava -T 20s --verbose system-test/*.test.js",
"test": "npm run system-test"
},
"dependencies": {
"botkit": "0.0.5",
"@google-cloud/language": "0.10.2",
"sqlite3": "3.1.8"
},
"scripts": {
"test": "cd ../..; npm run st -- --verbose language/slackbot/system-test/*.test.js"
},
"engines": {
"node": ">=4.3.2"
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.3.1",
"ava": "0.19.1",
"proxyquire": "1.7.11",
"sinon": "2.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, Google, Inc.
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -15,11 +15,11 @@

'use strict';

require(`../../../system-test/_setup`);

const fs = require(`fs`);
const path = require(`path`);
const proxyquire = require(`proxyquire`).noCallThru();
const sinon = require(`sinon`);
const test = require(`ava`);

const SLACK_TOKEN_PATH = path.join(__dirname, `../.token`);

Expand Down
8 changes: 5 additions & 3 deletions cloud-language/snippets/slackbot/system-test/demo_bot.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, Google, Inc.
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -15,19 +15,21 @@

'use strict';

require(`../../../system-test/_setup`);

const fs = require(`fs`);
const path = require(`path`);
const proxyquire = require(`proxyquire`).noCallThru();
const sinon = require(`sinon`);
const sqlite3 = require(`sqlite3`).verbose();
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);

const DB_PATH = path.join(__dirname, `../slackDB.db`);
const SLACK_TOKEN_PATH = path.join(__dirname, `../.token`);
const text = `President Obama is speaking at the White House.`;

let db, controllerMock, botkitMock, botMock, program;

test.before(tools.checkCredentials);
test.before.cb((t) => {
fs.unlink(DB_PATH, (err) => {
if (err && err.code !== `ENOENT`) {
Expand Down
Loading

0 comments on commit 1a91f3d

Please sign in to comment.