Skip to content

Commit

Permalink
Move helpers to helpers property
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpogi5 committed Aug 24, 2020
1 parent 8fb4774 commit cd27942
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
14 changes: 6 additions & 8 deletions src/helpers/db/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import deleteItem from './ops/deleteItem';
import deleteTable from './ops/deleteTable';

const helpers = {
methods: {
clearByGSI,
clearByScan,
createTable,
deleteBulk,
deleteItem,
deleteTable,
},
clearByGSI,
clearByScan,
createTable,
deleteBulk,
deleteItem,
deleteTable,
};

export default helpers;
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Model from './model';
import Schema from './schema';
import db from './db';
import dbHelper from './helpers/db/helpers';
import applyMethods from './helpers/applyMethods';
import dbHelpers from './helpers/db/helpers';

const DDB = function DDB() {};

Expand All @@ -13,6 +12,6 @@ DDB.prototype.model = (name, schema) => {
return Model.compile(name, schema);
};

applyMethods(DDB, dbHelper);
DDB.prototype.helpers = dbHelpers;

export default new DDB();
20 changes: 10 additions & 10 deletions tests/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('DDB helpers', () => {
});

it('should create table', async () => {
const { createTable } = DDB;
const { createTable } = DDB.helpers;
expect.assertions(0);
try {
await createTable(schema);
Expand All @@ -23,7 +23,7 @@ describe('DDB helpers', () => {
});

it('should clear by GSI', async () => {
const { db, clearByGSI } = DDB;
const { clearByGSI } = DDB.helpers;
const key = {
pk: 'PK',
sk: 'SK',
Expand All @@ -34,7 +34,7 @@ describe('DDB helpers', () => {

expect.assertions(6);
try {
await db('put', { Item: key });
await DDB.db('put', { Item: key });

const params = {
IndexName: 'GSI',
Expand All @@ -43,7 +43,7 @@ describe('DDB helpers', () => {
ExpressionAttributeValues: { ':pk': 'PK_GSI' },
};

let ret = await db('query', params);
let ret = await DDB.db('query', params);
expect(ret).toHaveProperty('Items');
expect(ret.Count).toBe(1);
expect(ret.Items[0].pk2).toBe('PK_GSI');
Expand All @@ -55,7 +55,7 @@ describe('DDB helpers', () => {
indexName: 'GSI',
});

ret = await db('query', params);
ret = await DDB.db('query', params);
expect(ret).toHaveProperty('Items');
expect(ret.Count).toBe(0);
} catch (error) {
Expand All @@ -64,30 +64,30 @@ describe('DDB helpers', () => {
});

it('should clear by Scan', async () => {
const { db, clearByScan } = DDB;
const { clearByScan } = DDB.helpers;
const key = { pk: 'PK_SCAN', sk: 'SK_SCAN' };
const params = { Item: key };

expect.assertions(4);
try {
await db('put', params);
await DDB.db('put', params);

let ret = await db('get', { Key: key });
let ret = await DDB.db('get', { Key: key });
expect(ret).toHaveProperty('Item');
expect(ret.Item.pk).toBe('PK_SCAN');
expect(ret.Item.sk).toBe('SK_SCAN');

await clearByScan('pk', 'PK_SCAN');

ret = await db('get', { Key: key });
ret = await DDB.db('get', { Key: key });
expect(ret).toStrictEqual({});
} catch (error) {
debug(error);
}
});

it('should delete table', async () => {
const { deleteTable } = DDB;
const { deleteTable } = DDB.helpers;
expect.assertions(0);
try {
await deleteTable();
Expand Down

0 comments on commit cd27942

Please sign in to comment.