Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-env node */
const esModules = ['filter-obj'].join('|');

module.exports = {
roots: ['<rootDir>/src'],
preset: 'ts-jest/presets/js-with-ts',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
transformIgnorePatterns: [`node_modules/(?!${esModules})`],
};
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"dependencies": {
"aws-sdk": "^2.678.0",
"axios": "^0.27.0",
"filter-obj": "^3.0.0",
"jest-diff": "^29.0.0",
"uuid": "^9.0.0"
},
Expand Down
24 changes: 23 additions & 1 deletion src/common/dynamoDb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import filterObject from 'filter-obj';
import { AttributeMap } from 'aws-sdk/clients/dynamodb';
import { ICommonProps } from './';

Expand All @@ -8,6 +7,29 @@ export interface IDynamoDbProps extends ICommonProps {

export const expectedProps = ['region', 'table', 'key'];

type predicate = (key: any, value: any, object: any) => boolean | Array<any>

const filterObject = (
object: AttributeMap,
predicate: predicate,
) => {
const result = {};
const isArray = Array.isArray(predicate);

for (const [key, value] of Object.entries(object)) {
if (isArray ? predicate.includes(key) : predicate(key, value, object)) {
Object.defineProperty(result, key, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
}

return result;
};

export const removeKeysFromItemForNonStrictComparison = (
received: AttributeMap,
expected: AttributeMap,
Expand Down