Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri committed May 2, 2017
1 parent 82e335f commit 838ee7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 6 additions & 9 deletions functions/spanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
// Imports the Google Cloud client library
const Spanner = require('@google-cloud/spanner');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Instantiates a client
const spanner = Spanner({
projectId: projectId
});
const spanner = Spanner();

// Your Cloud Spanner instance ID
const instanceId = 'my-instance';
Expand Down Expand Up @@ -53,9 +48,11 @@ exports.get = (req, res) => {
database.run(query)
.then((results) => {
const rows = results[0];
var data = [];
rows.forEach((row) => data.push(row.toJSON()));
res.send(data);
res.send(rows.map((row) => row.toJSON()));
})
.catch((err) => {
res.status(500);
res.send(`Error querying Spanner: ${err}`);
});
};
// [END spanner_functions_quickstart]
5 changes: 2 additions & 3 deletions functions/spanner/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ function getSample () {
};
}

test(`get: Gets albums`, async (t) => {
test(`get: Gets albums`, (t) => {
const sample = getSample();
const mocks = sample.mocks;

const err = await sample.program.get(mocks.req, mocks.res);
t.falsy(err, null);
const err = sample.program.get(mocks.req, mocks.res);
t.true(mocks.spanner.instance.called);
t.true(mocks.instance.database.called);
t.true(mocks.database.run.calledWith(query));
Expand Down

0 comments on commit 838ee7c

Please sign in to comment.