Skip to content

Commit

Permalink
Tidy up tables factory a wee bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Oct 16, 2023
1 parent ec545ad commit 6806bcc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/tables/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 2 additions & 6 deletions src/tables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/src/tables/factory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
})
})
Expand Down

0 comments on commit 6806bcc

Please sign in to comment.