Skip to content

Commit 6fff1f9

Browse files
jmdobryAce Nassri
authored andcommitted
New quickstarts. (#226)
* New quickstarts. * Address comments.
1 parent 4eeaa51 commit 6fff1f9

4 files changed

Lines changed: 63 additions & 43 deletions

File tree

handwritten/datastore/samples/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
},
1616
"devDependencies": {
1717
"mocha": "^3.0.2"
18+
},
19+
"engines": {
20+
"node": ">=4.3.2"
1821
}
1922
}

handwritten/datastore/samples/quickstart.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -34,8 +36,11 @@ const taskKey = datastoreClient.key([kind, id]);
3436

3537
// Retrieves the entity
3638
datastoreClient.get(taskKey, (err, entity) => {
37-
if (!err) {
38-
// The entity was retrieved successfully
39+
if (err) {
40+
console.error(err);
41+
return;
3942
}
43+
44+
console.log(`Entity: ${entity.key.id}`);
4045
});
4146
// [END datastore_quickstart]

handwritten/datastore/samples/system-test/quickstart.test.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

@@ -47,15 +49,19 @@ describe(`datastore:quickstart`, () => {
4749
return key;
4850
},
4951

50-
get: (_key) => {
52+
get: (_key, _callback) => {
5153
assert.equal(_key, key);
54+
assert.equal(typeof _callback, 'function');
5255

5356
datastore.get(_key, (err, entity) => {
57+
_callback(err, entity);
5458
assert.ifError(err);
5559
assert.notEqual(entity, undefined);
5660
assert.notEqual(entity.key, undefined);
5761
assert.equal(entity.key.kind, kind);
5862
assert.deepEqual(entity.data, { message: message });
63+
assert.equal(console.log.calledOnce, true);
64+
assert.deepEqual(console.log.firstCall.args, [`Entity: ${entity.key.id}`]);
5965
done();
6066
});
6167
}
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
1-
// Copyright 2015-2016, Google, Inc.
2-
// Licensed under the Apache License, Version 2.0 (the "License");
3-
// you may not use this file except in compliance with the License.
4-
// You may obtain a copy of the License at
5-
//
6-
// http://www.apache.org/licenses/LICENSE-2.0
7-
//
8-
// Unless required by applicable law or agreed to in writing, software
9-
// distributed under the License is distributed on an "AS IS" BASIS,
10-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
// See the License for the specific language governing permissions and
12-
// limitations under the License.
1+
/**
2+
* Copyright 2016, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
1315

1416
'use strict';
1517

1618
const proxyquire = require(`proxyquire`).noPreserveCache();
1719

1820
describe(`datastore:quickstart`, () => {
1921
let datastoreMock, DatastoreMock;
22+
const error = new Error(`error`);
23+
const mockKey = {};
2024

2125
before(() => {
2226
datastoreMock = {
23-
get: sinon.stub().yields(null, { key: 1234567890 }),
24-
key: sinon.stub.returns(`task/1234`)
27+
get: sinon.stub().yields(error),
28+
key: sinon.stub().returns(mockKey)
2529
};
2630
DatastoreMock = sinon.stub().returns(datastoreMock);
2731
});
2832

29-
it(`should get a task from Datastore`, () => {
33+
it(`should handle error`, () => {
3034
proxyquire(`../quickstart`, {
3135
'@google-cloud/datastore': DatastoreMock
3236
});
3337

3438
assert.equal(DatastoreMock.calledOnce, true);
3539
assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
3640
assert.equal(datastoreMock.get.calledOnce, true);
37-
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]);
41+
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [mockKey]);
42+
assert.equal(console.error.calledOnce, true);
43+
assert.deepEqual(console.error.firstCall.args, [error]);
3844
});
3945
});

0 commit comments

Comments
 (0)