diff --git a/bigquery/system-test/quickstart.test.js b/bigquery/system-test/quickstart.test.js new file mode 100644 index 00000000000..11225a22e9e --- /dev/null +++ b/bigquery/system-test/quickstart.test.js @@ -0,0 +1,50 @@ +// Copyright 2015-2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noPreserveCache(); +var bigquery = proxyquire('@google-cloud/bigquery', {})(); + +var datasetName = 'my_new_dataset'; + +describe('bigquery:quickstart', function () { + var bigqueryMock, BigqueryMock; + + after(function (done) { + bigquery.dataset(datasetName).delete(function () { + // Ignore any error, the dataset might not have been created + done(); + }); + }); + + it('should create a dataset', function (done) { + bigqueryMock = { + createDataset: function (_datasetName) { + assert.equal(_datasetName, datasetName); + + bigquery.createDataset(datasetName, function (err, dataset, apiResponse) { + assert.ifError(err); + assert.notEqual(dataset, undefined); + assert.notEqual(apiResponse, undefined); + done(); + }); + } + }; + BigqueryMock = sinon.stub().returns(bigqueryMock); + + proxyquire('../quickstart', { + '@google-cloud/bigquery': BigqueryMock + }); + }); +}); diff --git a/bigquery/test/quickstart.test.js b/bigquery/test/quickstart.test.js new file mode 100644 index 00000000000..409b1c87c9b --- /dev/null +++ b/bigquery/test/quickstart.test.js @@ -0,0 +1,38 @@ +// Copyright 2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noCallThru(); + +describe('bigquery:quickstart', function () { + var bigqueryMock, BigqueryMock; + + before(function () { + bigqueryMock = { + createDataset: sinon.stub().yields(null, {}, {}) + }; + BigqueryMock = sinon.stub().returns(bigqueryMock); + }); + + it('should create a dataset', function () { + proxyquire('../quickstart', { + '@google-cloud/bigquery': BigqueryMock + }); + + assert.equal(BigqueryMock.calledOnce, true); + assert.deepEqual(BigqueryMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); + assert.equal(bigqueryMock.createDataset.calledOnce, true); + assert.deepEqual(bigqueryMock.createDataset.firstCall.args.slice(0, -1), ['my_new_dataset']); + }); +}); diff --git a/datastore/system-test/quickstart.test.js b/datastore/system-test/quickstart.test.js new file mode 100644 index 00000000000..4a0266f9d1b --- /dev/null +++ b/datastore/system-test/quickstart.test.js @@ -0,0 +1,69 @@ +// Copyright 2015-2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noPreserveCache(); +var datastore = proxyquire('@google-cloud/datastore', {})(); +var kind = 'Task'; +var message = 'Buy milk'; +var key = datastore.key(kind); + +describe('datastore:quickstart', function () { + var datastoreMock, DatastoreMock; + + before(function (done) { + datastore.save({ + key: key, + data: { + message: message + } + }, function () { + // Datastore is eventually consistent + setTimeout(done, 5000); + }); + }); + + after(function (done) { + datastore.delete(key, function () { + // Ignore any error, the entity might not have been created + done(); + }); + }); + + it('should get a task from Datastore', function (done) { + datastoreMock = { + key: function () { + return key; + }, + + get: function (_key) { + assert.equal(_key, key); + + datastore.get(_key, function (err, entity) { + assert.ifError(err); + assert.notEqual(entity, undefined); + assert.notEqual(entity.key, undefined); + assert.equal(entity.key.kind, kind); + assert.deepEqual(entity.data, { message: message }); + done(); + }); + } + }; + DatastoreMock = sinon.stub().returns(datastoreMock); + + proxyquire('../quickstart', { + '@google-cloud/datastore': DatastoreMock + }); + }); +}); diff --git a/datastore/test/quickstart.test.js b/datastore/test/quickstart.test.js new file mode 100644 index 00000000000..a81dff883bd --- /dev/null +++ b/datastore/test/quickstart.test.js @@ -0,0 +1,39 @@ +// Copyright 2015-2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noPreserveCache(); + +describe('datastore:quickstart', function () { + var datastoreMock, DatastoreMock; + + before(function () { + datastoreMock = { + get: sinon.stub().yields(null, {key: 1234}), + key: sinon.stub.returns('task/1234') + }; + DatastoreMock = sinon.stub().returns(datastoreMock); + }); + + it('should get a task from Datastore', function () { + proxyquire('../quickstart', { + '@google-cloud/datastore': DatastoreMock + }); + + assert.equal(DatastoreMock.calledOnce, true); + assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); + assert.equal(datastoreMock.get.calledOnce, true); + assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234])]); + }); +}); diff --git a/logging/test/quickstart.test.js b/logging/test/quickstart.test.js index c9ce31acf18..23214d7e591 100644 --- a/logging/test/quickstart.test.js +++ b/logging/test/quickstart.test.js @@ -39,7 +39,7 @@ describe('logging:quickstart', function () { }); assert.equal(LoggingMock.calledOnce, true); - assert.deepEqual(LoggingMock.firstCall.args, []); + assert.deepEqual(LoggingMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); assert.equal(loggingMock.log.calledOnce, true); assert.deepEqual(loggingMock.log.firstCall.args, [expectedLogName]); assert.equal(logMock.entry.calledOnce, true); diff --git a/pubsub/test/quickstart.test.js b/pubsub/test/quickstart.test.js index cdd3a492735..e809d968fb7 100644 --- a/pubsub/test/quickstart.test.js +++ b/pubsub/test/quickstart.test.js @@ -33,7 +33,7 @@ describe('pubsub:quickstart', function () { }); assert.equal(PubSubMock.calledOnce, true); - assert.deepEqual(PubSubMock.firstCall.args, []); + assert.deepEqual(PubSubMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); assert.equal(pubsubMock.createTopic.calledOnce, true); assert.deepEqual(pubsubMock.createTopic.firstCall.args.slice(0, -1), [expectedTopicName]); }); diff --git a/storage/test/quickstart.test.js b/storage/test/quickstart.test.js index 809e0017aa7..623634c317c 100644 --- a/storage/test/quickstart.test.js +++ b/storage/test/quickstart.test.js @@ -33,7 +33,7 @@ describe('storage:quickstart', function () { }); assert.equal(StorageMock.calledOnce, true); - assert.deepEqual(StorageMock.firstCall.args, []); + assert.deepEqual(StorageMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); assert.equal(storageMock.createBucket.calledOnce, true); assert.deepEqual(storageMock.createBucket.firstCall.args.slice(0, -1), [expectedBucketName]); }); diff --git a/translate/system-test/quickstart.test.js b/translate/system-test/quickstart.test.js new file mode 100644 index 00000000000..3e772411aef --- /dev/null +++ b/translate/system-test/quickstart.test.js @@ -0,0 +1,46 @@ +// Copyright 2015-2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noPreserveCache(); +var translate = proxyquire('@google-cloud/translate', {})({ + key: process.env.TRANSLATE_API_KEY +}); +var string = 'Hello, world!'; +var targetLanguage = 'ru'; + +describe('translate:quickstart', function () { + var translateMock, TranslateMock; + + it('should translate a string', function (done) { + translateMock = { + translate: function (_string, _targetLanguage) { + assert.equal(_string, string); + assert.equal(_targetLanguage, targetLanguage); + + translate.translate(_string, _targetLanguage, function (err, translation, apiResponse) { + assert.ifError(err); + assert.equal(translation, 'Привет мир!'); + assert.notEqual(apiResponse, undefined); + done(); + }); + } + }; + TranslateMock = sinon.stub().returns(translateMock); + + proxyquire('../quickstart', { + '@google-cloud/translate': TranslateMock + }); + }); +}); diff --git a/translate/test/quickstart.test.js b/translate/test/quickstart.test.js new file mode 100644 index 00000000000..35f2dda6aa1 --- /dev/null +++ b/translate/test/quickstart.test.js @@ -0,0 +1,38 @@ +// Copyright 2016, 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 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noCallThru(); + +describe('translate:quickstart', function () { + var translateMock, TranslateMock; + + before(function () { + translateMock = { + translate: sinon.stub().yields(null, 'Привет мир!', {}) + }; + TranslateMock = sinon.stub().returns(translateMock); + }); + + it('should translate a string', function () { + proxyquire('../quickstart', { + '@google-cloud/translate': TranslateMock + }); + + assert.equal(TranslateMock.calledOnce, true); + assert.deepEqual(TranslateMock.firstCall.args, [{ key: 'YOUR_API_KEY' }]); + assert.equal(translateMock.translate.calledOnce, true); + assert.deepEqual(translateMock.translate.firstCall.args.slice(0, -1), ['Hello, world!', 'ru']); + }); +});