diff --git a/src/tables/factory.js b/src/tables/factory.js index 6f0024dc..3935936e 100644 --- a/src/tables/factory.js +++ b/src/tables/factory.js @@ -6,7 +6,8 @@ let paginate = true /** * returns a data client */ -module.exports = function factory ({ tables, options = {} }, callback) { +module.exports = function factory ({ services, options = {} }, callback) { + let { tables } = services let { ARC_ENV, AWS_REGION } = process.env let local = ARC_ENV === 'testing' let region = AWS_REGION || 'us-west-2' diff --git a/src/tables/index.js b/src/tables/index.js index b2c51e63..38d90979 100644 --- a/src/tables/index.js +++ b/src/tables/index.js @@ -36,12 +36,8 @@ module.exports = function tables (arc) { waterfall([ function (callback) { arc.services() - .then(serviceMap => { - callback(null, { tables: serviceMap.tables, options }) - }) - .catch(err => { - callback(err) - }) + .then(services => callback(null, { services, options })) + .catch(callback) }, factory, function (created, callback) { diff --git a/test/unit/src/tables/factory-test.js b/test/unit/src/tables/factory-test.js index 037cc50f..c990c8a2 100644 --- a/test/unit/src/tables/factory-test.js +++ b/test/unit/src/tables/factory-test.js @@ -5,7 +5,7 @@ let sandbox = require('@architect/sandbox') let cwd = process.cwd() let mock = join(cwd, 'test', 'mock', 'project') -let tables = { hi: 'there' } +let services = { tables: { hi: 'there' } } test('Set up env', async t => { t.plan(2) @@ -17,7 +17,7 @@ test('Set up env', async t => { test('tables.factory main client', t => { t.plan(4) - factory({ tables }, (err, client) => { + factory({ services }, (err, client) => { if (err) t.fail(err) t.ok(client._client, '_client property assigned') t.notOk(client._db, '_db property not assigned') @@ -28,7 +28,7 @@ test('tables.factory main client', t => { test('tables.factory AWS SDK properties', t => { t.plan(4) - factory({ tables, options: { awsSdkClient: true } }, (err, client) => { + factory({ services, options: { awsSdkClient: true } }, (err, client) => { if (err) t.fail(err) t.ok(client._client, '_client property assigned') t.ok(client._db, '_db property assigned') @@ -39,10 +39,10 @@ test('tables.factory AWS SDK properties', t => { test('tables.factory client static methods', t => { t.plan(2) - let tables = { quart: 'tequila' } - factory({ tables }, async (err, client) => { + let services = { tables: { quart: 'tequila' } } + factory({ services }, async (err, client) => { if (err) t.fail(err) - t.equals(await client.reflect(), tables, 'reflect() returns tables object') + t.equals(await client.reflect(), services.tables, 'reflect() returns tables object') t.equals(client._name('quart'), 'tequila', '_name() returns tables value') }) })